aaron.harnly.net

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:

  1. 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.

  2. The Template

    Download this template here:

    Mail Plugin 1.0

    and install into ~/Library/Application Support/Apple/Developer Tools/Project Templates/Bundle

  3. 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.

Digg this     Create a del.icio.us Bookmark     Add to Newsvine

14 Responses to “Mail Plugin Template 1.0”

  1. Jeroen Says:

    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.

  2. Todd Says:

    Same problem here. How do I actually get that template to register?

  3. Josh Says:

    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?

  4. Me Says:

    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

  5. Me Says:

    Nevermind … the mail plugin template had the following example in it:
    [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)MyPlugInSwizzleMethodSEL)origsel withMethodSEL)altsel;
    + (void)MyPlugInReplaceMethodSEL)origsel withMethodSEL)altsel fromClassClass)targetClass;

    As you can see, there is no such thing as
    MyPlugInSwizzleMethod:withMethod:fromClass:
    Rather, only the following exist
    MyPlugInSwizzleMethod:withMethod: and MyPlugInReplaceMethod:withMethod:fromClass

  6. Raphael Pautasso Says:

    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 ?

  7. Marc Says:

    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.

  8. Jeff Hendrickson Says:

    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

  9. Trevor Says:

    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

  10. Luke Says:

    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?

  11. aaronharnly Says:

    Yes, I have an updated template, which I’ll throw up here as soon as I get a chance.

  12. DavidW Says:

    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.

  13. DavidW Says:

    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?

  14. Luke Says:

    So Dave, when can we expect your updated template? Thanks for your excellent work!

Leave a Reply

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word