Mac OS X Hacks: 100 Industrial-Strength Tips & Tricks
Hack 80 Using IMAP with Apple's Mail Application
Set up and use an IMAP-enabled mail account through Mac OS X's Mail application. Most modern email clients, including Mac OS X applications such as Apple's own Mail, Qualcomm's Eudora, or Microsoft's Entourage, default to using the same mail transfer protocol: the venerable Post Office Protocol, more commonly known as POP. POP defines a simple set of instructions that lets users connect to a mail server account, download new mail, and then disconnect. Nearly every ISP's mail server supports POP, so it's a safe choice for mail-fetching client applications to support as well. More recently, an alternative protocol known as the Internet Message Access Protocol (IMAP) has been steadily gaining popularity and support from Internet providers. IMAP contains a more sophisticated command set that allows users to store and organize mail on the server, instead of simply downloading and deleting it. IMAP gives the most benefit to people who connect to a mail server using more than one computer, since an IMAP-enabled mail account will look the same on all these machines, from overall mailbox structure down to the status of individual messages, and any changes made to a mailbox on one machine become visible to the rest. This hack will guide you through setting up and using an IMAP-enabled mail account through Mac OS X's Mail application, covering IMAP-specific concepts and terminology as they come up. 80.1 Checking for IMAP Service
Of course, before you can start having fun with IMAP, your mail server must support it! You can find out simply by asking your ISP or network administrator, or you could poke your mail server machine directly to find out, by launching the Terminal [Hack #48] application and trying this: % telnet mail.server.net 143 Replace mail.server.net with the hostname of your mail server. If you've installed a local IMAP server (you've just arrived from [Hack #81]), use localhost. The 143 is the standard port number (think television channel) on which the IMAP server listens. If you have an IMAP service at your disposal, you'll receive a response a little something like this: Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. * OK [CAPABILITY IMAP4REV1 LOGIN-REFERRALS AUTH=LOGIN] localhost IMAP4rev1 2001.315 at Mon, 29 Jul 2002 15:31:46 -0700 (PDT) If so, you're good to go. If you instead receive a blunt "Connection refused" or something altogether different, check in with your service operator. To end the IMAP session you just started, type foo LOGOUT and press Return. 80.2 Creating an IMAP Mail Account
Launch Mail (Applications Figure 7-5. Creating a new IMAP account 80.3 Specifying Account Options
Visit the Advanced tab to see Mail's IMAP-specific options, shown in Figure 7-6. (The controls that appear under this tab depend upon the type of account you've selected under the Account Information tab.) Mail will fill the "Connect to server using port:" text field with 143, the usual TCP port of a mail server's IMAP service. Change this value only if you know that your host runs its IMAP service on a different port. Activate the Use SSL checkbox if your host supports secure IMAP (a.k.a. IMAPS) and you wish to take advantage of it. Figure 7-6. Setting IMAP options Check the "Compact mailboxes when closing" checkbox if you want Mail to purge your mailboxes of deleted messages when you quit the application; if left unchecked, deleted emails will remain within mailboxes, invisible to Mail but still accessible by other means. 80.3.1 Account directory
The Account Directory text field lets you specify the location of this account's cache folder on your local filesystem. Unless you have good reason to do otherwise, leave this field blank; Mail will use its default location of ~/Library/Mail/IMAP/account-name, which should work just fine. You'll notice that once you've started to use the account, this field becomes grayed out and uneditable, so choose wisely and type carefully. 80.3.2 IMAP path prefix
The Account Path Prefix text field specifies the path that Mail will prepend to all mailbox names when it's trying to locate them on the mail server. If you keep all your mailboxes in a directory called mail within your home directory, then you should put ~/mail here. On the other hand, if you never log into your mail server machine directly, or are otherwise not sure what to put here, then you're probably safe putting nothing here at all and letting the server figure it out for you. 80.3.3 Message caching
To help keep things efficient, Mail keeps local caches of your IMAP accounts' content, even though the real messages reside on the server. By default, an account's cache lives in ~/Library/Mail/IMAP, unless you specified a different location when you created the account. Every account gets its own folder there, named IMAP/account name. Through the Message Caching pull-down menu, you can specify how much of your incoming email Mail should cache and when it should cache it:
80.4 Mac.com Accounts
As testimony to the magical properties of IMAP, the Mac.com (http://www.mac.com) accounts that Apple provides to its customers as part of its .Mac package use IMAP as its protocol. This lets you consistently access and organize your Mac.com mail from any machine with an IMAP client Macintosh or otherwise. Setting up a Mac.com-flavored IMAP account is easy; just select Mac.com Account from Mail's Account Type pull-down menu, instead of IMAP Account. It's really just a shortcut that cues Mail to fill in the account configuration text fields to point to Apple's mail servers. 80.5 Organizing Mailboxes
In the mailbox list underneath an IMAP account's header, you'll find a list containing an inbox, any mailboxes you create, and any mailboxes Mail creates in order to support some of its own special features. 80.5.1 Inbox
An IMAP server abstracts all a user's new and otherwise unsorted mail into a single mailbox called Inbox, so you'll always have at least this mailbox available to you. 80.5.2 Creating and editing IMAP mailboxes
Mail's commands for creating and organizing mailboxes and folders, found under the Mailbox menu, remain consistent across all its account types, IMAP included. When you create, rename, and delete mailboxes through the commands in this menu or move mailboxes around by dragging their icons in the mailbox list drawer, Mail echoes these actions on your IMAP account's structure. Thus, all the changes you make in one session with Mail will carry across to any future connections you make to this IMAP account with any mail client. 80.5.3 Special mailboxes
While Mail takes full advantage of IMAP's ability to let you create and organize mailboxes any way you like, the application also has the ability to map its own functionality onto some special server-side mailboxes, if you let it. In all of the following cases, Mail will create these mailboxes on the server as necessary:
80.6 Organizing Messages
An email message sitting in an IMAP mailbox can have some number of message flags set on it, recording the actions performed on this message, such as the user's reading, replying to, or deleting it. When you reply to a message on your office PC, for example, and then later connect to your mailbox at home, that message will remember the fact you already replied to it, and be able to report this to you. Mail works with most flags in a fairly straightforward fashion, but it gets a little squirrelly when it comes to IMAP's Deleted flag.
80.7 Message Flags
Mail displays IMAP flags through symbols in the Flag and Status columns of a mailbox's message list (see Figure 7-7). Figure 7-7. Message flags 80.7.1 Recent
A message gets a Recent flag if the current IMAP connection is the first to have seen it. Mail places a blue dot in this message's Status column, marking it as a new, unread message. Mail unsets this flag once the user reads a message. 80.7.2 Seen
A message with a Seen flag has been read. Mail reacts to the absence of this flag; a message lacking a Seen flag (which all Recent messages do, by definition) gets a blue dot. Mail does not distinguish between unread mail that arrived since the current session started (and has a Recent flag) and unread mail carried over from a previous IMAP session (and therefore has no message flags). Selecting Message 80.7.3 Answered
Replying to an IMAP message prompts Mail to set its Answered flag. Mail displays such messages with a little U-turn arrow in its status column, unless the message lacks a Seen flag. 80.7.4 Flagged
The Flagged flag can mean whatever you want. Generally, it's meant to signal that a message requires urgent attention. In Mail, you can toggle this flag for the selected messages through Message 80.7.5 Draft
Mail sets a message's Draft flag if it's an unfinished, unsent message you're storing in an IMAP mailbox (see "Drafts" item in the previous Special Mailboxes section). 80.7.6 Deleted
Mail gives messages Delete flags when you delete them (pressing the Delete key on your keyboard, selecting Message 80.8 Deleting Messages
IMAP uses a two-step process for deleting messages. Any message can set a Deleted flag on itself, which marks it as susceptible to actual deletion but doesn't actually get rid of it or even move it out of its original mailbox. A separate IMAP command purges a mailbox of all the deleted messages it contains. Different mail clients have different ways of representing deleted (but not yet erased) messages to the user. Mail chooses to simply not show deleted mail at all, unless it's inside the designated Trash mailbox. Mail's IMAP response to deleting mail changes depending upon how you've set the "Move deleted mail to a folder named" checkbox. If you've checked it, then deleting a piece of mail will cause Mail to move it to your chosen Trash mailbox, rather than setting its Delete flag. If, instead, you've left that checkbox unchecked, Mail will set the message's Deleted flags but otherwise leave them be. Since Mail refuses to display deleted mail in mailboxes other than the Trash mailbox, this action will also make the message vanish from sight, even though it continues to exist on the server (and perhaps remain visible to other mail clients). That same checkbox also dictates Mail's behavior with actually erasing Deleted messages. If checked, Mail gives you a Mailbox If you leave this box unchecked, then Mail instead offers the Mailbox Note that both these commands share the Jason McIntosh |