10.6 compatibility: Fix some new compiler warnings, and work around apparent regressions in NSTask and -stringByStandardizingPath.
5 // Created by Jens Alfke on 7/13/08.
6 // Copyright 2008 Jens Alfke. All rights reserved.
7 // Adapted from Apple's "SBSendEmail" sample app.
11 #import "MailBridge.h"
12 #import "CollectionUtils.h"
15 @implementation OutgoingEmail
22 _toRecipients = [[NSMutableArray alloc] init];
23 _attachments = [[NSMutableArray alloc] init];
28 - (id) initWithSubject: (NSString*)subject body: (NSString*)body
32 self.subject = subject;
44 [_toRecipients release];
45 [_attachments release];
50 @synthesize subject=_subject, sender=_sender, body=_body,
51 toRecipients=_toRecipients, attachments=_attachments;
54 + (MailApplication*) mailApp
56 /* create a Scripting Bridge object for talking to the Mail application */
57 MailApplication *mail = [SBApplication applicationWithBundleIdentifier:@"com.apple.Mail"];
58 mail.timeout = 5*60; // in ticks
62 + (BOOL) isMailRunning
64 return [self mailApp].isRunning;
67 - (MailOutgoingMessage*) _message
70 MailApplication *mail = [[self class] mailApp];
72 /* create a new outgoing message object */
73 MailOutgoingMessage *emailMessage =
74 [[[mail classForScriptingClass:@"outgoing message"] alloc] initWithProperties:
75 $dict({@"subject", self.subject},
76 {@"content", self.body})];
78 /* set the sender, show the message */
80 emailMessage.sender = _sender;
82 /* Have to add this to a container now, else the scripting bridge complains */
83 [[mail outgoingMessages] addObject: emailMessage];
85 /* create a new recipient and add it to the recipients list */
86 for( NSString *recipient in _toRecipients ) {
87 MailToRecipient *theRecipient =
88 [[[mail classForScriptingClass:@"to recipient"] alloc] initWithProperties:
89 $dict({@"address", recipient})];
90 [emailMessage.toRecipients addObject: theRecipient];
93 /* add an attachment, if one was specified */
94 for( NSString *attachmentPath in self.attachments ) {
95 /* create an attachment object */
96 MailAttachment *theAttachment =
97 [[[mail classForScriptingClass:@"attachment"] alloc] initWithProperties:
98 $dict({@"fileName", attachmentPath})];
100 /* add it to the list of attachments */
101 [[emailMessage.content attachments] addObject: theAttachment];
104 /* add the object to the mail app */
105 _message = [emailMessage retain];
113 self._message.visible = YES;
114 [[[self class] mailApp] activate];
120 [self._message send];
129 TestCase(MailUtils) {
130 OutgoingEmail *m = [[OutgoingEmail alloc] initWithSubject: @"This is a test"
131 body: @"Hi there! This is a test email from an automated test case. http://mooseyard.com/"];
132 [m.toRecipients addObject: @"jens@mooseyard.com"];