Archive forpyobjc

Demystifying Mail.app Plugins for Leopard

In the course of writing my email un-attachment plugin for Mail.app (and subsequently updating it for Leopard), I found that Apple has a capable, but entirely undocumented, plugin API. I’m providing this update to my previous tutorial in the hopes that it may be useful to anyone else considering implementing a plugin for Apple Mail.

__(’Read the rest of this entry »’)

Comments (22)

Demystifying Mail.app Plugins – A Tutorial

In the course of writing my email un-attachment plugin for Mail.app, I found that Apple has a capable, but entirely undocumented, plugin API. I’m providing this tutorial in the hopes that it may be useful to anyone else considering implementing a plugin for Apple Mail.

Update 2008-02-16: See my updated version of this tutorial for Leopard.

Update 2006-04-11: Apparently yesterday’s update truncated the entry. I’ve managed to restore it thanks to the Google Gods and Their Glorious Cache.

Update 2006-04-10: Added some cautionary text about using a private API, as suggested by Jens Alfke. It’s all common sense, but definitely deserves a mention. Especially considering how uncommon common sense is! :-)

__(’Read the rest of this entry »’)

Comments (14)

Cool Objective-C tricks

I have this really annoying habit of composing emails that refer to an attachment, only to realize after sending the message that I forgot to include the attachment. So I wrote an attachment scanner plugin for Apple’s Mail.app. The plugin itself is nothing special. It just checks if there’s an attachment, and if there isn’t, makes sure you aren’t using certain words in the message body (basically, attach, attachment, and the like).

What is particularly cool, however, is how the plugin works! It’s written in python (using PyObjC) as a .mailbundle, so when Mail starts up, it will load the plugin. The plugin then creates a subclass of the WebMessageEditor class that Mail uses for, well, the message editor window. It then redefines the send: message to perform its checks, and if they all pass, call its parent’s send: method. On its own, that’s nothing special. What’s cool is how I get Mail to use my WebMessageEditor instead of the one it was compiled to use.

Enter the Objective-C runtime. Objective-C supports a notion of class posing, whereby a subclass can pretend to be (or, to pose as) its parent class. Thus, whenever the code instantiates the parent class, it actually instantiates the subclass. Now, when Mail creates a new WebMessageEditor window, it actually creates my WebMessageEditor window, which adds in my attachment checking hooks. How cool is that?!

Comments (1)