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

Figure 1  MailLinkSupported and MailPageSupported keys in <Info.plist>.
<IMAGE>

2. Install two AppleEvent handlers:

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


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