Outlook for Mac Raw Query based Smart Folder

August 3, 2019

My recommendation for Mac power-user email client is MailMate. No question. No contest.

However sometimes work security policies force you into Microsoft-Exchange-land and your only choice is to use Outlook for Mac

You won't ever be able to make Outlook work as well as MailMate, but you can do a few things to help you get closer. MailMate Smart Mailboxes can be somewhat mimicked using Outlook Smart Folder feature along with the Raw Query option.

Outlook mail search is based on the Mac Spotlight search and index system. So make sure you have Spotlight enabled for mail in System Preferences → Spotlight → Mail & Messages:

Then ⌘⌥F to enter Advanced Search mode, then click the Item Contains drop-down and select Raw Query

Now you can enter your raw query in the text box. The raw query is Spotlight query syntax and fields.

To find out what fields Spotlight makes available, run mdls on an Outlook mail message file. In my case Outlook stores mail messages under ~/Library/Group Containers/UBF8T346G9.Office/Outlook/Outlook 15 Profiles/Main Profile/Data/Messages/*/*

$ mdls 8459FCED-2F8B-6A2E-B12E-1BC7C3DFFE33.olk15Message
com_microsoft_outlook_accountID                = 3
com_microsoft_outlook_completed                = 0
com_microsoft_outlook_flagged                  = 0
com_microsoft_outlook_folderID                 = 166
com_microsoft_outlook_forwarded                = 0
com_microsoft_outlook_has_attachments          = 0
com_microsoft_outlook_has_mentioned_me         = 0
com_microsoft_outlook_has_reminder             = 0
com_microsoft_outlook_has_text_content         = 1
com_microsoft_outlook_hasDueDate               = 0
com_microsoft_outlook_hasStartDate             = 0
com_microsoft_outlook_junkLikelihood           = -100
com_microsoft_outlook_messageReceived          = 2019-08-04 19:18:22 +0000
com_microsoft_outlook_messageSent              = 2019-08-04 19:18:19 +0000
com_microsoft_outlook_primaryCategory          = 0
com_microsoft_outlook_priority                 = 0
kMDItemDisplayName                             = "AWS CodeBuild www-site Complete"

Use those fields to form your raw query. For example I have a Smart Folder named Todo where I want to include anything in the Later folder folder or that is flagged and that isn't completed yet and isn't in the Spam or Trash folder:

  (com_microsoft_outlook_folderID == 123
|| com_microsoft_outlook_folderID == 154
|| com_microsoft_outlook_flagged == 1)
&& com_microsoft_outlook_completed == 0
&& com_microsoft_outlook_folderID != 166
&& com_microsoft_outlook_folderID != 162

You may also find the below Apple Script helpful. Select a folder in the Outlook UI and run the script using Script Editor, it will log the folder id of the currently selected folder.

tell application "Microsoft Outlook"
	get selected folder
end tell