Technical Q&A QA1722
Safari's "Mail [Contents/Link] of This page" to Mail Client events...
Q: What do I have to do to make my mail client handle Safari's "Mail Contents of This page" and "Mail Link to This page" events?
A: What do I have to do to make my mail client handle Safari's "Mail Contents of This page" and "Mail Link to This page" events?
1. Add two boolean keys to your <Info.plist>: MailLinkSupported and MailPageSupported
2. Install two AppleEvent handlers:
'mail'/'mlpg' (for mail contents of this page)
'mail'/'mllk' (for mail link to this page)
Listing 1 Installing AppleEvent handlers:
- (void) applicationDidFinishLaunching: (NSNotification *) inNotification {
NSAppleEventManager *eventManager = [NSAppleEventManager sharedAppleEventManager];
[eventManager setEventHandler:self
andSelector:@selector(handleMailPageEvent:withReplyEvent:)
forEventClass:'mail'
andEventID:'mlpg'];
[eventManager setEventHandler:self
andSelector:@selector(handleMailLinkEvent:withReplyEvent:)
forEventClass:'mail'
andEventID:'mllk'];
} // applicationDidFinishLaunching |
3. Implement the AppleEvent handlers:
Listing 2 Implementing the AppleEvent handlers:
- (void) handleMailPageEvent:(NSAppleEventDescriptor *) inEvent
withReplyEvent:(NSAppleEventDescriptor *) inReplyEvent {
// Get the subject and address
NSString *subject = [[inEvent paramDescriptorForKeyword:'urln'] stringValue];
NSString *address = [[inEvent paramDescriptorForKeyword:'url '] stringValue];
NSLog(@"subject: \"%@\", address: \"%@\"", subject, address);
NSData *data = [[inEvent paramDescriptorForKeyword:keyDirectObject] data];
if (data) {
// handle data here⦠(Safari WebArchive)
} else {
// Report error.
NSLog(@"paramDescriptorForKeyword:keyDirectObject.data is NULL.");
}
} // handleMailPageEvent
- (void) handleMailLinkEvent:(NSAppleEventDescriptor *) inEvent
withReplyEvent:(NSAppleEventDescriptor *) inReplyEvent {
// Get the subject and address
NSString *subject = [[inEvent paramDescriptorForKeyword:'urln'] stringValue];
NSString *urlString = [[inEvent paramDescriptorForKeyword:keyDirectObject] stringValue];
NSLog(@"subject: \"%@\", url: <%@>", subject, urlString);
} // handleMailLinkEvent |
Document Revision History
| Date | Notes |
|---|---|
| 2010-12-23 | New document that documents what a mail client needs to handle Safari's "Mail Contents of This page" and "Mail Link to This page" events. |
Copyright © 2010 Apple Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2010-12-23