I'm going to create a mail plugin for the OS X Mail.app application for some additional features.
I have no idea where to start as there is no official documentation for plugins.
Can anyone please help me, how can I start the project. Is there any initial link or tutorial, please suggest?
Manage Mail extensionsIn the Mail app on your Mac, choose Mail > Preferences, then click Extensions. In the list of Mail extensions available on your Mac, do any of the following: Turn an extension on or off: Select or deselect the extension's checkbox.
To change these preferences in the Mail app on your Mac, choose Mail > Preferences, then click Extensions. Extensions available on your Mac. To turn an extension on or off, select or deselect the extension's checkbox. Information about the selected extension.
The EMLX file format is implemented and developed by Apple. The Apple Mail application uses the EMLX file format for exporting the emails. There are other applications as well that can open the EMLX files and convert these to other file formats.
You can attach an AppleScript script to a Mail rule. For example, you could have an incoming message trigger a script that copies information from the message and pastes it into a database that works with Script Editor. In the Mail app on your Mac, choose Mail > Preferences, then click Rules.
As noted, writing Apple Mail plugins is not straightforward, since it only has a private plugin API, which is entirely undocumented and can change with any new version of Mail.app. The best code example is GPGMail, which is open source & still active (already working on Yosemite support). Here is what I successfully did to get started (will put it up on github once finished):
mailbundle
(under Packaging in the project Build settings)~/Library/Mail/Bundles
(as Build Phase add a Copy Files action with that as absolute path destination and the *.mailbundle from your build/ folder as item to copy)/Applications/Mail.app
as executable in my run scheme, so that Run in XCode will build it, copy the bundle and start mail; note that at this point you'll get an error from Mail that your plugin cannot be started and was disabledSupportedPluginCompatibilityUUIDs
in the Info.plist, I stole it from GPGMail, these change with new Mail/OSX versions MVMailBundle
, which you have to inherit from and which has a registerBundle
method to hook you in MyMailBundle
, inheriting from NSObject
initialize
method#import <Cocoa/Cocoa.h> @interface MyMailBundle : NSObject + (void)initialize; @end
initialize
implementation: previously, you could use the simple way and directly inherit as done in Letterbox, however, since 64-bit runtimes of Objective-C you have to use the dynamic way as done by GPGMail: NSClassFromString
to dynamically get the MVMailBundle
classclass_setSuperclass
from <objc/runtime.h>
to have your own class inherit from itregisterBundle
on it casted as MVMailBundle
(requires include of MVMailBundle.h
)#import <objc/runtime.h> #import "MVMailBundle.h" #import "MyMailBundle.h" @implementation MyMailBundle + (void)initialize { NSLog(@"Loading MyMail plugin..."); // since 64-bit objective-c runtimes, you apparently can't load // symbols directly (i.e. through class inheritance) and have to // resort to NSClassFromString Class mvMailBundleClass = NSClassFromString(@"MVMailBundle"); // If this class is not available that means Mail.app // doesn't allow plugins anymore or has changed the API if (!mvMailBundleClass) return; // dynamically change super class hierarchy #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdeprecated" class_setSuperclass([self class], mvMailBundleClass); #pragma GCC diagnostic pop // register our plugin bundle in mail [[((MyMailBundle *)self) class] registerBundle]; NSLog(@"Done registering MyMail plugin."); } @end
NSLog
logging calls to verify the right thing is happening, they'll be visible in XCode's console when running/debugging Mail.app from within XCode or alternatively in the system logs of Console.appFor reference, here are some of the resources that helped me:
There is no official supported way to build such a tool - you need to start trying to hook in to Mail.app without any official support.
If you want to persist on this sort of thing, then you'll need to understand how Mail.app internals work, which is a bunch of using the debugger and class dump to inspect libraries in other apps:
https://github.com/nygard/class-dump
You'll probably also want a way to inject code into other applications, for example:
https://github.com/rentzsch/mach_inject
And every time Apple update Mail.app you'll potentially need to redo everything :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With