2 // GrowlMailMeDisplay.m
3 // Growl Display Plugins
5 // Copyright 2004 Mac-arena the Bored Zo. All rights reserved.
7 #import "GrowlMailMeDisplay.h"
8 #import "GrowlMailMePrefs.h"
9 #import "GrowlDefinesInternal.h"
10 #import "GrowlApplicationNotification.h"
12 #import "Mail.h" // this file is automatically generated by a shell script; see the target build rules for details
14 #import <Message/NSMailDelivery.h>
17 #define destAddressKey @"MailMe - Recipient address"
19 /* for when there is no icon */
20 #define plainTextMessageFormat @"%@\r\n"\
21 @"-- This message was automatically generated by MailMe, a Growl plug-in, --\r\n"\
22 @"-- in response to a Growl notification --\r\n"\
23 @"-- http://growl.info/ --\r\n"
25 @implementation GrowlMailMeDisplay
28 [preferencePane release];
32 - (NSPreferencePane *) preferencePane {
34 preferencePane = [[GrowlMailMePrefs alloc] initWithBundle:[NSBundle bundleWithIdentifier:@"com.Growl.MailMe"]];
35 return preferencePane;
38 - (void) displayNotification:(GrowlApplicationNotification *)notification {
39 NSString *destAddress = nil;
40 READ_GROWL_PREF_VALUE(destAddressKey, @"com.Growl.MailMe", NSString *, &destAddress);
41 NSDictionary *noteDict = [notification dictionaryRepresentation];
44 CFMakeCollectable(destAddress);
45 if([destAddress length]) {
46 NSString *title = [noteDict objectForKey:GROWL_NOTIFICATION_TITLE];
47 NSString *desc = [noteDict objectForKey:GROWL_NOTIFICATION_DESCRIPTION];
48 //hopefully something can be worked out to use the imageData.
49 //documentation, Apple, documentation!
50 // NSData *imageData = [noteDict objectForKey:GROWL_NOTIFICATION_ICON];
53 // On 64-bit, the Message framework is not available. Instead, use the Scripting Bridge.
54 MailApplication *Mail = [SBApplication applicationWithBundleIdentifier:@"com.apple.Mail"];
55 MailOutgoingMessage *message = [[[[Mail classForScriptingClass:@"outgoing message"] alloc] initWithProperties:[NSDictionary dictionaryWithObjectsAndKeys:title, @"subject", [NSString stringWithFormat:plainTextMessageFormat, desc], @"content", nil]] autorelease];
56 MailToRecipient *recipient = [[[[Mail classForScriptingClass:@"to recipient"] alloc] initWithProperties:[NSDictionary dictionaryWithObjectsAndKeys:destAddress, @"address", nil]] autorelease];
59 [[Mail outgoingMessages] addObject:message];
60 [message.toRecipients addObject:recipient]; // don't ask me, I'm only following the sample code's example
61 success = [message send];
63 BOOL success = [NSMailDelivery deliverMessage:[NSString stringWithFormat:plainTextMessageFormat, desc]
69 NSLog(@"(MailMe) WARNING: Could not send email message \"%@\" to address %@", title, destAddress);
70 NSLog(@"(MailMe) description of notification:\n%@", desc);
72 NSLog(@"(MailMe) Successfully sent message \"%@\" to address %@", title, destAddress);
74 NSLog(@"(MailMe) WARNING: No destination address set");
77 NSLog(@"(MailMe) WARNING: No destination address set");
79 [destAddress release];
81 id clickContext = [noteDict objectForKey:GROWL_NOTIFICATION_CLICK_CONTEXT];
83 NSDictionary *userInfo = [[NSDictionary alloc] initWithObjectsAndKeys:
84 [noteDict objectForKey:@"ClickHandlerEnabled"], @"ClickHandlerEnabled",
85 clickContext, GROWL_KEY_CLICKED_CONTEXT,
86 [noteDict objectForKey:GROWL_APP_PID], GROWL_APP_PID,
88 [[NSNotificationCenter defaultCenter] postNotificationName:GROWL_NOTIFICATION_TIMED_OUT
89 object:[notification applicationName]
95 - (BOOL) requiresPositioning {