Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

10.4: Build complex booleans in Mail with Smart Folders Apps
Tiger only hintI've seen a couple hints about how to perform complex boolean operation by hacking plist files. For example, this one. Here's a non-hacker way to deal with this, and yes, I know there are other ways to do this, too. I'm just using this as an example.

I have some mailing lists that I want to view using Smart Folders. All my mailing lists pool in a folder aptly named 'mailing lists.'

The criteria I want to define is:
((( && (folder=mailing lists)) 
(( && (folder=mailing lists)))
Which means if the to address is one of those addresses, and it's in the mailing list folder, it's a match. Instead of making one Smart Folder to handle this, you make three. Two smart folders called Cocoa and Cocoa2 (I call these builders) and one Smart Folder, CocoaMailingList, that gathers the contents of the first two smart folders:
Cocoa: (( and (folder=mailing lists))
Cocoa2: (( and (folder=mailing lists))
CocoaMailingList. If a message is in Cocoa -or- Cocoa2.
  • Currently 1.50 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (2 votes cast)

10.4: Build complex booleans in Mail with Smart Folders | 10 comments | Create New Account
Click here to return to the '10.4: Build complex booleans in Mail with Smart Folders' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.4: Build complex booleans in Mail with Smart Folders
Authored by: derPlau on Jul 12, '05 01:26:24PM

One note about this hint: I tried this idea right after Tiger was released, and it didn't seem to work, so I gave up on it.

The problem was that the criteria in the third Smart Folder (the one that combines the other two with an Or -- the equivalent of CocoaMailingList in the original entry) always changed themselves to the equivalent of Cocoa || Cocoa. In other words, even though I originally set the criteria to:

Is in mailbox "Cocoa" Or Is in mailbox "Cocoa2"

Mail always seemed to switch them to:

Is in mailbox "Cocoa" Or Is in mailbox "Cocoa"

which obviously just gave me the same messages as in the original Cocoa mailbox, and none of the ones in Cocoa2.

I assumed this was just a bug and hoped it would be fixed with 10.4.1. When it wasn't, I looked a bit closer, and discovered what the bug is.

My problem originated with the fact that I'd made my second mailbox (Cocoa2) by duplicating the first (Cocoa) -- i.e., by option-dragging Cocoa within the mailbox panel. (I did this because I have several junk and mailing-list folders that I didn't want to include in either Cocoa or Cocoa2, so rather than re-enter all of those for both mailboxes I just copied the whole Smart Mailbox).

As it turns out, when you duplicate a Smart Mailbox, Mail duplicates it perfectly -- including the supposedly-unique MailboxID entry in the plist file. So, even though I changed my Cocoa2 mailbox to a new set of criteria, it had the same MailboxID as the original Cocoa mailbox. Apparently, when you make a Smart Mailbox (like CocoaMailingList) that has "In Mailbox X" as one of its criteria, that criterion is saved in the plist file as "Mailbox Is Equal to MailboxID". Since the MailboxIDs of both the mailboxes CocoaMailingList was looking into were identical, it only looked in the first mailbox it found with that ID.

The bottom line here is, if you're combining Smart Mailboxes in the way suggested by the original hint, don't make any of the mailboxes by duplicating already-existing mailboxes. In fact, you should probably avoid duplicating Smart Mailboxes altogether to avoid unpredictable effects of having duplicate MailboxID's.

[ Reply to This | # ]
Why don't they build it into Mail, etc.
Authored by: googoo on Jul 12, '05 05:07:09PM

I do not know about you, but I am tired of having to use this kind work-around to make complex smart mailboxes/playlists/etc. Why doesn't Apple just build this ability into their "smart" interfaces? It really would not be hard to do!


[ Reply to This | # ]
Why don't they build it into Mail, etc.
Authored by: derrickbass on Jul 12, '05 08:27:31PM

Actually, it would be quite hard. Have you ever tried to envision a user interface for creating and editing arbitrary boolean expressions? Try it; really think about how you would do both simple things and complex things. Then think about your non-techincally savvy Uncle George doing things he might need to do.

I've developed software, and have thought about this really hard, and decided that the way described in this hint is close to the best way to do it. (The one thing I would add is a way to create an expression without creating a real mailbox; you may not care to actually see the mailboxes "Cocoa" and "Cocoa2".)

I've seen many attempts to create such an interface and none was very easy to use. Complex boolean expressions are just hard to show graphically, and even harder to edit.

That's not to say it can't be done. If anyone can do, it's Apple. But I doubt it's very high on their priority list, since there are easy workarounds (like this hint) for geeky people (like us) who actually want complex booleans.

[ Reply to This | # ]
Why don't they build it into Mail, etc.
Authored by: googoo on Jul 12, '05 09:47:07PM

A simple advanced option could enable functionality that some would find too difficult. As for an intuitive interface, there could be "logic groups" identified by indenting them, coloring them, or connecting them in a bracket. I know it is more difficult that either "all and" or "all or," but I think that we can handle it.


[ Reply to This | # ]
Why don't they build it into Mail, etc.
Authored by: smanzo on Jul 13, '05 04:56:41PM

See Advanced Options toggle widget

(On clicking)

Four buttons are available

Each criterion gets it's own line
Command+Click to select, pressing appropriate operand button while selected applies that criterion to all selected items AND groups them together into a single line with ( ) marks around it

Further edits nest as necessary.

It'll be messy once you get a few levels deep, but it's hidden under the Advanced Options button. You can click that same button to go back to the Simple interface (with a warning that this will undo advanced changes I would expect, as they wouldn't be viewable in the Simple interface)

[ Reply to This | # ]
Why don't they build it into Mail, etc.
Authored by: mediaman on Jul 14, '05 12:56:29PM

Is this a suggestion? Or is it really an option? If it is an option, please elaborate on the "Advanced Options Widget" and how to access it.


[ Reply to This | # ]
Why don't they build it into Mail, etc.
Authored by: horhey23 on Sep 15, '05 04:10:32AM

Where is this Advanced Options toggle in MAil? Or are you referring to Spotlight?

[ Reply to This | # ]
Actually it can be easy
Authored by: adsmart on Jul 18, '05 03:53:00PM

Having tried, and failed, many times to design simple UIs for simple people to do highly complex things... it can be nearly impossible to do.

But lets for a minute keep in mind our users. Who is likely to need this feature? In general, we're talking about folks that are smarter than your average bear; people for whom entering a Raw Query (where have I seen that before?) is undaunting. Granted, for my grandmother it may as well say, "Here there be dragons," but so what? Odds are, having loads of useless smart folders won't be all that painful for them.

But lets consider how we could build a UI for the average Joe to build very complex queries. As it turns out, Apple has all the UI elements we need, all we have to do is extend the paradigm and we're laughing. Here's what you do:

  • Allow individual Smart Mailboxes to be hidden (so I don't have to see all those boxes that are just waypoints to get me to some more useful state)
  • Allow Smart Mailboxes to contain child Smart Mailboxes, which by default filters its parents content. This is a simplification step. Often I build up complex queryies by filtering the results of the previous step.
  • Allow Smart Mailboxes to be visible but not their contents, this way you can have a smart mailbox that acts more like a folder, but without showing you unnecessary information

If you really just want to have one mailbox (not very good for ongoing maintainance, but there you go), then put in command to take a mailbox and simply integrate all the references to smart mailboxes so you only have one complex query.

There you go, a simple UI to allow users to create advanced complex queries. Granted it, its a little rough around the edges but you get the idea.

[ Reply to This | # ]
10.4: Build complex booleans in Mail with Smart Folders
Authored by: paulhagstrom on Nov 18, '07 09:59:33PM

I rediscovered this basic idea recently (and would have posted a hint here about it, if this hint hadn't already been posted), and was trying it out, but I also ran into a problem as well, when you try to include a criterion that requires the use of Spotlight.

My testing was on 10.5, and I haven't actually tried it on 10.5.1, but the basic content of the main hint should work in both (not just in 10.4). The problem I had with Spotlight was this, though:

The technique above is fine for conditions based on headers and flagged/unread status. However, if you include something like "Entire message contains 'omnigroup'" (or, in my case, "MailTags keyword is 'expire'"), then Mail seems to generate an incoherent query for Spotlight. My diagnosis of what is happening was that when you have a Smart Mailbox that has as one of its criteria "is in Another-Smart-Mailbox", opening that superordinate Smart Mailbox results in the generation of a single Spotlight query that collapses together the conditions of the subordinate smart mailbox and the superordinate smart mailbox -- but they are collapsed incorrectly (without any sort of grouping, and disregarding the any/or setting of the subordinate criteria), so you wind up with a query that is more like "msg contains 'omnigroup' or folder=mailing_lists or to=Y or folder=mailing_lists", clearly not what we're after.

I hope that gets fixed, it would be great if it worked with Spotlight too. Although, another thing I have noticed is that smart mailbox criteria that need to use Spotlight are really much slower to run than those that can just work off the headers and flag/unread status -- meaning I usually try to stay away from Spotlight-requiring smart mailboxes anyway.

[ Reply to This | # ]
10.4: Build complex booleans in Mail with Smart Folders
Authored by: paulhagstrom on Nov 18, '07 10:16:42PM

Following up on that last comment (where I said I hadn't tested it under 10.5.1), I just now did -- and it still doesn't work, in the same way I described above.

I had two MailTags keywords, X7 and X30, and two subordinate smart mailboxes, one looking for the X7 keyword and received not within the last 7 days, the other looking for the X30 keyword and received not within the last 30 days. The main smart mailbox looked for messages in one subordinate smart mailbox or in the other subordinate smart mailbox. I should have gotten about 20 messages (since one subordinate mailbox showed 5, the other 20), but instead got 36000 -- anything not within the last 7 or 30 days or bearing either X7 or X30, from what I can tell. It or'ed everything together.

[ Reply to This | # ]