Important note it seems it is a known issue that on both OSX (10.4 and 10.5) and iPhone mail clients don't seem to handle non-standard ports for SSL or TLS very well which means using the default port of 993. Some notes on this I found:

I have several dozen IMAP mail folders (stored on the server as Maildir++, which Dovecot supports). When I’m on the go with my iPhone, I only want to see a few of them. IMAP provides a way for clients to “subscribe” to specific folders, so I figured that was the basic idea. As with all things IMAP, subscription information is stored on the server; by default, Dovecot keeps it in a file in the top-level Maildir. To avoid interfering with my more full-featured IMAP clients, I needed a way to get at my top-level Maildir with the usual permissions, but with a separate subscriptions file. Dovecot’s passwd-file authentication scheme made this easy. After the default passdb passwd stanza in /etc/dovecot.conf, I appended this:

passdb passwd-file {

args = /etc/dovecot/%d/passwd

}

Likewise for userdb. Then I created /etc/dovecot/schmonz.com/passwd with the following format:

The iPhone has no UI for manipulating subscriptions, so I logged into my webmail app as iphone@schmonz.com and set up everything the way I wanted. Unfortunately, it turns out there’s a reason the iPhone has no subscription UI: it doesn’t care about subscriptions at all. It just always shows you every folder it can possibly show you.

Needing to take a different tack, I kept the idea of a separate IMAP login for iPhone purposes and tweaked the details. Alongside the real Maildir++, I created a separate Maildir++ specifically for the iPhone, with strategic symlinks to my real inbox, Drafts, Sent, and Trash folders:

I reopened Mail on the iPhone. After a moment, it showed only Inbox, Drafts, Sent, and Trash, and they had the same contents as Mail.app on my Mac. I marked something as read in one IMAP client, and the other noticed the change shortly thereafter. Once convinced I was working safely with my real mail, I symlinked in the handful of other folders I wanted to see on the iPhone.

It would be nice if iPhone Mail grokked IMAP subscriptions. If and when it does, I can roll back to my first attempt and undo this hack. In the meantime, it works."