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:

$ ls -la Maildir-iphone
total 1264
drwx------   2 schmonz  users    1024 Jan 31 00:37 .
drwxr-xr-x  27 schmonz  users   15872 Jan 30 21:59 ..
lrwxr-xr-x   1 schmonz  users      18 Jan 30 22:14 .Drafts -> ../Maildir/.Drafts
lrwxr-xr-x   1 schmonz  users      16 Jan 30 22:13 .Sent -> ../Maildir/.Sent
lrwxr-xr-x   1 schmonz  users      17 Jan 30 22:13 .Trash -> ../Maildir/.Trash
lrwxr-xr-x   1 schmonz  users      14 Jan 30 22:06 cur -> ../Maildir/cur
lrwxr-xr-x   1 schmonz  users      14 Jan 30 22:06 new -> ../Maildir/new
lrwxr-xr-x   1 schmonz  users      14 Jan 30 22:06 tmp -> ../Maildir/tmp

And I changed the line in /etc/dovecot/schmonz.com/passwd to this:


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.