[Editor’s Note: This article is an excerpt from Take Control of Apple Mail, available for download from TidBITS Publishing for $15. The 175-page ebook, which covers Mail for both Mavericks and iOS 7, goes well beyond searching Mail to provide essential setup, customization, usage, and troubleshooting advice, whether you use Gmail, iCloud, Exchange, or IMAP—or multiple accounts.]
OS X’s Spotlight search feature automatically indexes all the messages in Apple Mail for super-fast searching, and you can search for those messages either within Mail or using the system-wide Spotlight menu.
But Mail isn’t limited to simple text searches. With a flexible system of search tokens (which I explain in a moment), Boolean searches, and other options, you can find almost any message you can describe. You can even save a search by converting it into a smart mailbox, as I describe at the end of this article.
Perform a Basic Search
To find an email message, begin by (optionally) selecting one or more mailboxes in the Mail’s sidebar to restrict your search to those mailboxes. Then start typing your query in the Search field in Mail’s toolbar. (To jump right to the Search field, press Command-Option-F.) Mail begins displaying results in the message list immediately—sometimes even before you finish typing.
To hide the results and return to the message list, click the X icon in the Search box.
Use Suggestions and Tokens As you type your search term, the Search field displays a drop-down list of suggestions—not of matching messages, but of text or other elements Mail thinks you might be looking for. If you see what you’re looking for in the list, you can save yourself a bit of typing by simply selecting it, either by clicking it or by using the arrow keys to highlight the item and then pressing Return.
If you ignore the list of suggestions, or select the default choice at the top (“Message contains:”), Mail simply searches entire messages (including headers and metadata) for that literal text.
If Mail notices that whatever you’ve typed is part of a name, email address, date, subject, or other message header, it may display the corresponding full item in the list. Select one of those items (for example, a sender’s name) and Mail encapsulates the item in a little gray bubble. That bubble is a search token—a unit that functions as a special, adjustable search term. Tokens are great because they make searching less error-prone and easier to manipulate.
When I say a token is “adjustable,” I mean you can change the context of where Mail searches for the term. For example, when searching for a person, you can narrow the search to messages from that person, to that person, or where the person’s name is mentioned anywhere in the message—just click the little arrow on the left side of the token and choose the desired context from the pop-up menu that appears. Similarly, when the search token is a subject word, you can restrict the search to just message subjects.
You can’t force Mail to make a search token; you can only take what it offers. But names, email addresses, subject words, and certain date-like expressions (such as “yesterday” and “May 2012”) frequently produce tokens.
You’re also not restricted to using just one token. Once you’ve chosen a search query to select it as a token, you can add more tokens if you like, and you can also include additional non-token text to search for. Just remember that whatever you enter in the Search field, by default Mail searches for messages containing all those terms.
Adjust Search Scope Besides offering search suggestions, Mail makes another change to its interface as you begin typing a search term. The Favorites bar, just beneath the toolbar, changes subtly to provide controls for restricting or expanding the range of the search (for example, just one mailbox or all mailboxes).
The options you can select are as follows:
- All: Click this item, and Mail searches messages in all mailboxes (including Sent and Drafts) for the text you entered.
- Mailbox Name: If you had a single mailbox selected when you started searching, that mailbox’s name appears in the Favorites bar. Click it to restrict the search to that mailbox. You can also select any mailbox or smart mailbox already on the Favorites bar.
- Selected Mailboxes: If you had more than one mailbox selected, click this to search all (and only) those mailboxes.
- Save: Click this button, which sits at the far right of the Favorites bar, to Create a Smart Mailbox (discussed below).
Search for a Phrase
To search for an exact sequence of words, such as dark green shirt, put quotation marks around the phrase:
"dark green shirt". Without the quotation marks, Mail matches messages containing all three of those words, anywhere in the message, so, for example, Mr. Green put on his red shirt after dark would match. With the quotation marks, only a phrase such as Mr. Green put on his dark green shirt would match.
Use Boolean Expressions
A Boolean search is one that uses the logical operators AND, OR, and NOT, along with optional parentheses, to help narrow the results in different ways—for example, messages containing either Jack or Jill, both Jack and Jill, or Jack but not Jill. Mail can perform Boolean searches, but only in message contents, not in headers (such as Subject, From, or Date).
When using Boolean operators, always use uppercase—
NOT—so Mail doesn’t search for the actual words and, or, and not. You can use a minus sign (-) as a shortcut for
AND NOT, so, if you type
Jack -Jill in the Search field, you’ll see a list of all the messages that contain “Jack” but not “Jill.”
Search by Date Range
To search for messages in a range of dates, enter the dates using the format
12/26/11-4/15/12 for “December 26, 2011 through April 15, 2012.” (Don’t expect tokens to appear here, however, as those happen only for common units such as a whole month.) You can, of course, combine dates with other text. For example,
3/1/2012-4/11/2012 backups finds messages dated between 3/1/2012 and 4/11/2012 that contain the word backups.
Search within the Current Message
If you want to find text within a selected message or conversation (as opposed to finding messages themselves), you can choose Edit > Find > Find (or press Command-F) to display an inline search field just above the message contents. As you type in this field, Mail instantly highlights all matching terms in the current message or conversation. You can use the arrow buttons to move from one match to the next; click Done to dismiss the search field.
To perform a find-and-replace action (which is possible only in messages you’re composing, not in incoming messages), check the Replace box next to the inline search field to display additional controls.
Work Smarter with Smart Mailboxes
Smart mailboxes appear in your sidebar alongside ordinary mailboxes, but they aren’t truly mailboxes—they hold no data themselves. A smart mailbox is instead a saved search query that displays messages, stored in other mailboxes, that match the smart mailbox’s particular search criteria. You set up the smart mailbox’s search conditions, and you get a dynamic folder that always displays the messages matching those conditions, regardless of the messages’ actual locations.
Create a Smart Mailbox Mail provides two ways to create smart mailboxes. The easiest way is to save a search, as I describe below. However, you can instead start building a smart mailbox from scratch by choosing Mailbox > New Smart Mailbox, or clicking the plus (+) button at the bottom of Mail’s sidebar and choosing New Smart Mailbox from the resulting pop-up menu.
Follow these steps to set up a smart mailbox:
- Enter search text in the Search field at the upper right of Mail’s main window. Use any of the usual search criteria Mail supports except for Boolean operators; select where Mail should look for matching messages (in one or more particular mailboxes or All—unfortunately, smart mailboxes don’t work with Selected Mailboxes selected in the Favorites bar); and choose which parts of the message to search (a certain header or Entire Message).
- Click the Save button on the right side of the Search/Favorites bar. A dialog appears showing your search criteria in a more-structured form that you can further edit.
- Enter a name for the smart mailbox (or keep the name Mail fills in automatically).
- To add a new condition, click the plus (+) button to the right of an existing condition and then configure the new condition. For example, you might fill in any of the following:
[From] [Contains] some-email-addressor
[Subject] [Begins with] Fwd:or
[Date Received] [Is in the last] 2 [Days]or
[Any Attachment Name] [Ends with] .exe. (To delete a condition, click the minus (–) button next to it.)
- If your smart mailbox has only one condition, proceed to Step 6. Otherwise, you must choose Any or All from the “that match” pop-up menu near the top of the dialog. Any, like a Boolean OR, means that if any one of the conditions matches a message, the message appears in the results. For example, to display any message from your mother or brother or sister in a Family smart mailbox, you should specify the appropriate three conditions (such as
[From] [Contains] person’s address) and choose Any from the pop-up menu. All, like a Boolean AND, works if you want messages to appear only if all your conditions are met. An example is displaying a message only if it is from your stockbroker and is unread and was received today.
- Decide whether you want the smart mailbox to list messages found in your Trash or Sent folders.
- Click OK.
Mail adds a new smart mailbox to your sidebar with the name and criteria you selected. If you click that mailbox icon, it should initially display exactly the same messages as your search. As you receive and delete messages that meet your criteria, the list will automatically update to reflect the latest message matches.
Smart Mailbox Suggestions Here are my favorite suggestions for making smart mailboxes:
- Show all correspondence with a specific person: Choose Any from the pop-up menu at the top. Add two conditions,
[Any Recipient], both of which include the other person’s email address. (To show conversations with more than one person, create a new Contacts group with all the names you want to include, and instead of
[Sender Is a Member of Group] [some-Address-Book-group]. Then add
[Any Recipient]conditions for each person in the group individually.) Make sure you select Include Messages from Sent so Mail also shows any messages you’ve sent to this person. For even better results, when viewing this smart mailbox, choose View > Organize by Conversation to display all your exchanges in a threaded conversation.
- Display recent unread messages: If you use rules to move messages into different mailboxes, you might enjoy seeing all your unread messages—wherever they may reside—in a single place. If you like, limit the smart mailbox to messages received in the last day (or few days).
- Locate attachments in Sent mail: If you often send photos or other large attachments, their copies in your Sent mailbox can take up a lot of space, and you probably have the originals elsewhere on your Mac. Make a smart mailbox with two conditions:
[Message is in Mailbox] [Sent]. From time to time, check this mailbox; to remove attachments from these messages, select the messages and choose Message > Remove Attachments.
- Look for group members: Use the
[Sender is a Member of Group]option to search for messages from people in one of your Contacts groups. And, yes, you can even refer to smart groups you’ve created in the Contacts app, so that as your contacts’ information changes, the contents of the smart mailbox track the automatic changes in a smart group’s membership.
- Get more flexible than All and Any: If you use the
[Message is in Mailbox]condition, the contents of one smart mailbox can depend on another smart mailbox. This is handy when you have so complex a set of conditions that Any and All are too limited. For example, you might have one smart mailbox that lists messages from any (“Any”) of several friends, and another that lists messages that are both in the first smart mailbox and (“All”) marked as high priority.