"The ID extension to the Internet Message Access Protocol - Version 4rev1 (IMAP4rev1) protocol allows the server and client to exchange identification information on their implementation in order to make bug reports and usage statistics more complete."
The dovecot mailserver implemented this extension and extended it further to receive the remote client's ip address and port. These credentials can be passed to the authorization system (e.g. PAM), that can make decisions based on the credentials and log the real addresses, when a webmail client is used.
The attached patch implements this extension for SquirrelMail.