I'm trying to write a simple email app to handle various AppleEvents and send those messages using another protocol. As far as I know this is accomplished by 3rd party mail apps on OSX with MailSharingSupported, MailLinkSupported, MailPageSupported, and adding a "mailto" URL scheme type. There is a 5th in Mail.app, MailURLShareSupported, but there doesn't seem to be any documentation.
The "mailto" scheme is straightforward, and seems to be the most common method; the MailLink and MailPage events are covered by Technical Q&A QA1722. However, I can't seem to get MailSharing to work at all because of sandboxing. Even if I move the codesigned app to /Applications and launch it there, I still get "errAEPrivilegeError/-10004" for event "mail/shim" in Console. No entitlements I tried to add (com.apple.security.temporary-exception.apple-events, com.apple.security.scripting-targets, etc) seemed to work, probably because these grant permissions to my app, not the Mail service trying to contact it.
--edit
I forgot to mention MailSharingSupported is discussed in What's New in OS X: Mountain Lion
Assuming an Info.plist with
<key>MailSharingSupported</key>
<true/>
<key>MailLinkSupported</key>
<true/>
<key>MailPageSupported</key>
<true/>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>Email Address URL</string>
<key>CFBundleURLSchemes</key>
<array>
<string>mailto</string>
</array>
</dict>
</array>
And this sample code
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application
NSAppleEventManager *em = NSAppleEventManager.sharedAppleEventManager;
[em setEventHandler:self andSelector:@selector(mailto:withReplyEvent:) forEventClass:kInternetEventClass andEventID:kAEGetURL];
[em setEventHandler:self andSelector:@selector(share:withReplyEvent:) forEventClass:eurlMail andEventID:'shim'];
[em setEventHandler:self andSelector:@selector(link:withReplyEvent:) forEventClass:eurlMail andEventID:'mllk'];
[em setEventHandler:self andSelector:@selector(page:withReplyEvent:) forEventClass:eurlMail andEventID:'mlpg'];
}
-(void)share:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)reply {
NSAppleEventDescriptor *d = [event descriptorForKeyword:keyDirectObject], *s = [event descriptorForKeyword:'shud'];
//FIXME: never called
}
-(void)mailto:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)reply {
NSAppleEventDescriptor *d = [event descriptorForKeyword:keyDirectObject], *q = [event descriptorForKeyword:'qtnp'];
NSURLComponents *c = [NSURLComponents componentsWithString:d.stringValue];
if (q) {
NSDictionary *p = [NSPropertyListSerialization propertyListWithData:q.data options:0 format:NULL error:NULL];
}
}
-(void)link:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)reply {
NSAppleEventDescriptor *d = [event descriptorForKeyword:keyDirectObject], *n = [event descriptorForKeyword:'urln'];
NSURL *u = [NSURL URLWithString:d.stringValue];
}
-(void)page:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)reply {
NSAppleEventDescriptor *d = [event descriptorForKeyword:keyDirectObject], *n = [event descriptorForKeyword:'urln'], *u = [event descriptorForKeyword:cURL];
NSURL *l = [NSURL URLWithString:u.stringValue];
WebArchive *a = [[WebArchive alloc] initWithData:d.data];
}
What should I be doing?