I just got this working on Linux for IMAP by using stunnel. You should be able to get this to work for POP3 too. Basically you want to generate two stunnels, one for IMAP and one for SMTP. I've done this via /etc/inetd.conf like so:
imap stream tcp nowait nobody /usr/bin/stunnel stunnel -c -r imap.gmail.com:993
465 stream tcp nowait nobody /usr/bin/stunnel stunnel -c -r smtp.gmail.com:465
From the command line, the former translates to e.g.
stunnel -c -d imap -r imap.gmail.com:993
You can test if it's working by telnet'ing to localhost 143 and trying to login:
telnet localhost 143
Trying 127.0.0.1...
Connected to edinburgh.
Escape character is '^]'.
- OK Gimap ready for requests from 76.103.91.108 33if686099yxr.3
a01 login yourname yourpassword
a01 OK yourname authenticated (success)
^]
telnet> quit
If all's well then change your account settings to point to localhost port 143 for IMAP and localhost port 465 for SMTP. If your localhost is already using those ports, then just switcheroo and use e.g. 998 for IMAP and 999 for SMTP - whatever works for you. Just be sure to point at port 993 on imap.gmail.com and 465 on smtp.gmail.com.
I was so happy to get this working... enjoy 😉