The term "firewall" comes to mind..
Otherwise, set the binding IP-address from your IMAP-server to localhost or 127.0.0.1.
For Courier-IMAP that is, change/put:
in your /etc/courier/imapd (and/or imapd-ssl).
Make sure your squirrelmail is connecting to 127.0.0.1, not to your external IP.
Why on earth you would want to limit users in this way, I wouldn't know.