Old stunnel
(stunnel3 from Doorbot Gaming: Secure Email Using Cyrus IMAP, Sendmail, and SASLv2):
/usr/sbin/stunnel3 -c -d localhost:143 -r localhost:993
New stunnel
Create a conf file with the following contents:
client = yes [imap] accept = localhost:143 connect = localhost:993
Run
/usr/sbin/stunnel <filename>