All-Rules Mail Bundle: The shortcut to your Mail.app rules

Have you ever wanted to automate some message sorting tasks in Apple’s Mail application after you have read a message? I, for example, use one archive folder per account and move all messages into that folder after I’ve read them. The application’s rule system is perfectly suited for that task, unfortunately there is no way to activate certain rules by pressing a keyboard shortcut. That’s where this bundle comes into play.

The All-Rules Mail Bundle acts as a plugin for Apple’s Mail application and serves just one specific purpose. It provides an additional menu item located under “Message -> Apply All Rules” which applies all active rules to the currently selected messages while ignoring any present “Stop evaluating rules” action.

Where to get the bundle

The source of the bundle is available at GitHub as a standard Xcode project. Feel free to adapt it to your needs if necessary. I will also provide a precompiled binary for those of you who just want to use it out of the box.

Note that I’ve developed and tested the thing on my only Mac machine, which clearly is an inadequate test coverage. As always I would be happy about any response. So far the bundle is known to run in the following environment, which is the most recent one at the time of writing.

  • Mac OS X Snow Leopard 10.6.6
  • Mail Application 4.4
  • Message Framework 4.4

How it is implemented

First of all, let me emphasis that this is the first time I actually did some Objective-C coding. But I really liked the feel of it. I was really surprised about the power of the Objective-C runtime. You can do lots of nasty stuff at runtime like changing class hierarchies, adding methods to classes, changing method implementations and so on.

I used one technique known as method swizzling in the bundle, which lets you switch the existing implementation of a method with your own replacement at runtime. This enabled me to override the original shouldStopEvaluatingRules implementation of the MessageRule class inside the Message framework.

Unfortunately most of the APIs of the Mail application and the Message framework are private, so I expect my bundle to break sometime in the future. But the API can be easily reverse engineered with the class-dump utility which generates header files out of Objective-C binaries.

To prevent bundles from silently breaking, each bundle includes a list of the exact versions of Message frameworks and Mail applications it is compatible with. I found an article that explains how to fix unsupported plugins after upgrading Mail.app without recompiling them. So if you have different versions running on your machine that are compatible as well, let me know about them.

And last but not least I want to mention one article which helped me a lot in figuring out all those tiny details and really did it’s job in demystifying Mail.app plugins on Leopard for me.

Related bundles

The same (and more) could be done with Indev’s Mail Act-On bundle, unfortunately that bundle is sold under a commercial license. With my bundle I cloned the essential feature which was indispensable for my personal use.

The other day, while I was at

The other day, while I was at work, my sister stole my iPad and tested
to see if it can survive a forty foot drop, just so she can be a youtube
sensation. My apple ipad is now broken and she has 83 views.
I know this is entirely off topic but I had to share it with someone!

Whenever it is in any way

Whenever it is in any way possible, every boy and girl should choose as his life work some occupation which he should like to do anyhow, even if he did not need the money. http://www.toolbox.com.ph/

Boldness in itself is genius.

Boldness in itself is genius.

Now it has become really

Now it has become really clear for me - I think I can follow your steps and make the same thing!

Hi Michael, Bit off topic but

Hi Michael,
Bit off topic but thanks for the firefox addon. The new version works great. All other ones break now because there they don't have a results per page value which yours does.

Cheers
Tim
http://www.biostim.com.au

That’s where this bundle

That’s where this bundle comes into play.unfortunately there is no way to activate certain rules by pressing a keyboard shortcut.

there is no way to activate

there is no way to activate certain rules by pressing a keyboard shortcut. That’s where this bundle comes into play. rule system is perfectly suited for that task, unfortunately