Mail Plugin Template 1.0
Initial release of the template.
Changes
- Initial release!
Writing Mail.app Plugins
To get started writing plugins for Mail.app, I suggest the following steps:
Fscript
Download the marvelous FScript, including FScriptAnywhere.
Familiarize yourself with FScript (it’s like Smalltalk + ObjC + Python, or something), and use FScriptAnywhere to start browsing around the object hierarchy of Mail.app. Figure out what controllers or views you want to target.
The Template
Download this template here:
Mail Plugin 1.0
and install into ~/Library/Application Support/Apple/Developer Tools/Project Templates/Bundle
Code!
Create a new project using the template.
Right away, the project should compile and create a double-clickable installer. Once installed, your plugin will log “Loaded FooPlugin bundle” to the system console (viewable with Console.app). Wahoo!
The main action takes place in the FooPluginBundle.m file, which is in the FooPlugin Classes > Controllers group. The basic idea is that you’ll pick a few Mail.app classes or method to override, with some combination of class posing, categories, and method swizzling or replacement. If you’re not familiar with these techniques, well, it’s about time you get so!
The complete classdumps of Mail.app and the Message.framework are included as text files. I’ve created cleaned-up header files few of the most common classes that you might want to link against or customize; but if you want more, you’ll have to dig through the text files and create your own .h files. Let me know if you think that should be different – my reasoning was that there’s no reason to clutter up the project with dozens of headers for Mail.app classes you aren’t customizing; but I could be persuaded otherwise.
I’ve included some convenient categories on NSObject to make swizzling and replacement straightforward. From there on, it’s up to you!
Feel free to add your comments below. I’m not going to write your plugin for you, but I’d appreciate feedback on how the template can be made more useful.





August 21st, 2006 at 2:23 pm
Maybe it’s me, but after unzipping the MailPlugin_1.0.zip into the mentioned directory, I can’t find the project template when I try to create a new project. I tried to put it in the main /Library directory, but that had the same effect.
September 1st, 2006 at 11:11 am
Same problem here. How do I actually get that template to register?
September 10th, 2006 at 5:26 pm
Yup! I couldn’t get it working either. I even dropped it in the primary Xcode directory:
Library/Application Support/Apple/Developer Tools/Project Templates/Bundle/
with no luck.
I noticed the project file is a .xcodeproj whereas the other seem only to be .xcode and .pbproj.
Maybe a compatibility issue?
December 11th, 2006 at 8:23 pm
When I try to ues your swizzle function, I get a selector not recognized error. Is there something wrong in the way I am using it? I am trying to swizzle the drawingAttributes method from the AddressAttachment class.
[code]
@class AddressAttachment;
….
[AddressAttachment MyPlugInSwizzleMethod:@selector(drawingAttributes) withMethod:@selector(myDrawingAttributes) fromClass:[AddressAttachment class]];
[/code]
The resulting console error:
+[AddressAttachment MyPlugInSwizzleMethod:withMethod:fromClass:]: selector not recognized
December 11th, 2006 at 8:46 pm
Nevermind … the mail plugin template had the following example in it:
SEL)origsel withMethod
SEL)altsel;
SEL)origsel withMethod
SEL)altsel fromClass
Class)targetClass;
[Foo MyPlugInSwizzleMethod:@selector(bar) withMethod:@selector(bar) fromClass:[Some class]];
However, the above selector does not exist. The above is a hybrid of the two that are actually provided:
+ (void)MyPlugInSwizzleMethod
+ (void)MyPlugInReplaceMethod
As you can see, there is no such thing as
MyPlugInSwizzleMethod:withMethod:fromClass:
Rather, only the following exist
MyPlugInSwizzleMethod:withMethod: and MyPlugInReplaceMethod:withMethod:fromClass
May 14th, 2007 at 9:30 am
Hi, This page is great and difficult to find with Google. I have test the tutorial:
Just clicking on the “Build” icon but the installer was not built. (But if i just right click a the installer target and select the “Build” then it was built).
I launched the installer and i get an error : “Impossible to transform “class ctnr” of alias “toto:test:build:release:install test.app” in type string” translated from french. (But manual installation worked)
Very interesting project, good code and really useful !
I will try to replace this tutorial (http://www.bazza.com/~eaganj/weblog/2006/03/29/demystifying-mail-app-plugins) in this new context.
Is http://www.codethecode.com/Projects/class-dump/ is enough or we reealy need FScript ?
July 23rd, 2007 at 11:26 am
Very nice template. Using it, I could get my plugin loaded by Mail.app.
How do you use the swizzle methods, to redefine the behavior of the send method?
I have this [code] [myPluginBundle myPluginSwizzle:@selector(send:) withMethod:@selector(anOtherMethod:)]; [/code]
It throws me a: selector not recognized error.
October 22nd, 2007 at 8:40 pm
Great template! Thanks.
Does anyone know how I would deploy this if I wanted to be able to call an Apple Script before Mail closed?
TIA
March 5th, 2008 at 12:42 am
Hi Aaron, any chance of this being updated for Leopard? I just gave it a crack and have a few problems out of the box. http://tinyurl.com/2gwthn Thanks,
Trevor
March 10th, 2008 at 4:06 pm
Hi Aaron, I would also like to know if you intend to release an updated template that is compatible with Xcode 3.0 and Leopard?
March 10th, 2008 at 4:10 pm
Yes, I have an updated template, which I’ll throw up here as soon as I get a chance.
March 12th, 2008 at 12:05 am
I’m looking for a 10.5 version as well, after seeing the python example for Mail plugins, this was exactly what I was looking for. Thanks for sharing.
March 12th, 2008 at 12:16 am
I used class-dump to generate new header files, and changed defaults write com.apple.mail BundleCompatibilityVersion 2
to
defaults write com.apple.mail BundleCompatibilityVersion 3
and the plugin appears to load, I don\’t really know anything about the interaction with Mail.app so my question I guess is, do you know if there are other issues to worry about for the template or should it (just the base template code) be fine with only these modifications?
April 9th, 2008 at 11:50 am
So Dave, when can we expect your updated template? Thanks for your excellent work!
January 8th, 2009 at 1:47 pm
I just found this site and am interesteed in the updated template
April 7th, 2009 at 7:00 pm
Great post. Any chance of the updated template?
May 25th, 2009 at 10:15 am
Hi Aaron, Any chance of the updated template for Xcode 3 & Leopard? Thanks!
June 17th, 2009 at 11:06 am
Hello,
Do you know how make a plugin compatible 10.6 ? All the plugins for OS 10.5 are disabled by Snow Leopard Mail.app. I don’t find how to fix.
July 29th, 2009 at 3:45 pm
In NSObject ComposerSwizzle.m , I had to replace line 11
#import
with
#import
to make it compile.
I also had to re-create Info.plist by right-clicking Resources Add > New File > Other > Property List and copy/pasting the original content in plain-text mode there. For some obscure reason XCode 3.1.3 would deem it ill-formed.
HTH,
–c-alpha