* IChatUtils additions.
authorJens Alfke <jens@mooseyard.com>
Wed Jul 16 10:50:34 2008 -0700 (2008-07-16)
changeset 17a1044ae95953
parent 16 ce9c83f7ec14
child 18 d6ab9f52b4d7
* IChatUtils additions.
* Added MailUtils.
* Improved MYAnimatingSplitView.
* Added "lenient" URL parser to URLUtils.
IChatUtils.h
IChatUtils.m
MYAnimatingSplitView.m
MailBridge.h
MailUtils.h
MailUtils.m
URLUtils.h
URLUtils.m
     1.1 --- a/IChatUtils.h	Sun Jul 13 10:45:42 2008 -0700
     1.2 +++ b/IChatUtils.h	Wed Jul 16 10:50:34 2008 -0700
     1.3 @@ -20,6 +20,8 @@
     1.4  
     1.5  + (NSDictionary*) iChatInfoForOnlinePerson: (ABPerson*)abPerson;
     1.6  + (BOOL) isPersonOnline: (ABPerson*)abPerson;
     1.7 +
     1.8  + (BOOL) sendMessage: (NSString*)msg toPerson: (ABPerson*)abPerson;
     1.9 ++ (BOOL) sendMessage: (NSString*)msg toBuddyWithScreenName: (NSString*)screenName;
    1.10  
    1.11  @end
     2.1 --- a/IChatUtils.m	Sun Jul 13 10:45:42 2008 -0700
     2.2 +++ b/IChatUtils.m	Wed Jul 16 10:50:34 2008 -0700
     2.3 @@ -90,18 +90,22 @@
     2.4      return [self iChatInfoForOnlinePerson: abPerson] != nil;
     2.5  }
     2.6  
     2.7 -+ (iChatBuddy*) buddyWithInfo: (NSDictionary*)info
     2.8 ++ (iChatBuddy*) buddyWithScreenName: (NSString*)screenName
     2.9  {
    2.10 -    NSString *ident = [info objectForKey: IMPersonScreenNameKey];
    2.11 -    NSPredicate *pred = [NSPredicate predicateWithFormat: @"handle==%@", ident];
    2.12 +    NSPredicate *pred = [NSPredicate predicateWithFormat: @"handle==%@", screenName];
    2.13      @try{
    2.14          return [[[[sIChatApp buddies] filteredArrayUsingPredicate: pred] objectAtIndex: 0] get];
    2.15      } @catch( NSException *x ) {
    2.16 -        Log(@"buddyWithInfo got exception: %@",x);
    2.17 +        Log(@"buddyWithScreenName got exception: %@",x);
    2.18      }
    2.19      return nil;
    2.20  }
    2.21  
    2.22 ++ (iChatBuddy*) buddyWithInfo: (NSDictionary*)info
    2.23 +{
    2.24 +    return [self buddyWithScreenName: [info objectForKey: IMPersonScreenNameKey]];
    2.25 +}
    2.26 +
    2.27  + (BOOL) sendMessage: (NSString*)msg toPerson: (ABPerson*)abPerson
    2.28  {
    2.29      NSDictionary *info = [self iChatInfoForOnlinePerson: abPerson];
    2.30 @@ -116,6 +120,21 @@
    2.31  }
    2.32  
    2.33  
    2.34 ++ (BOOL) sendMessage: (NSString*)msg toBuddyWithScreenName: (NSString*)screenName
    2.35 +{
    2.36 +    iChatBuddy *buddy = [self buddyWithScreenName: screenName];
    2.37 +    if( buddy ) {
    2.38 +        @try{
    2.39 +            [sIChatApp send: msg to: buddy];
    2.40 +            return YES;
    2.41 +        } @catch( NSException *x ) {
    2.42 +            Log(@"sendMessage:toBuddyWithScreenName: got exception: %@",x);
    2.43 +        }
    2.44 +    } 
    2.45 +    return NO;
    2.46 +}
    2.47 +
    2.48 +
    2.49  @end
    2.50  
    2.51  
     3.1 --- a/MYAnimatingSplitView.m	Sun Jul 13 10:45:42 2008 -0700
     3.2 +++ b/MYAnimatingSplitView.m	Wed Jul 16 10:50:34 2008 -0700
     3.3 @@ -79,7 +79,7 @@
     3.4      [self getDividerPositionMin: &minPos max: &maxPos];
     3.5      float denom = maxPos-minPos;
     3.6      if( denom<=0 )
     3.7 -        return 0.0;
     3.8 +        return 0.0f;
     3.9      else
    3.10          return (pos-minPos)/denom;
    3.11  }
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/MailBridge.h	Wed Jul 16 10:50:34 2008 -0700
     4.3 @@ -0,0 +1,658 @@
     4.4 +/*
     4.5 + * Mail.h
     4.6 + */
     4.7 +
     4.8 +#import <AppKit/AppKit.h>
     4.9 +#import <ScriptingBridge/ScriptingBridge.h>
    4.10 +
    4.11 +
    4.12 +@class MailItem, MailApplication, MailColor, MailDocument, MailWindow, MailText, MailAttachment, MailParagraph, MailWord, MailCharacter, MailAttributeRun, MailOutgoingMessage, MailLdapServer, MailApplication, MailMessageViewer, MailSignature, MailMessage, MailAccount, MailImapAccount, MailMacAccount, MailPopAccount, MailSmtpServer, MailMailbox, MailRule, MailRuleCondition, MailRecipient, MailBccRecipient, MailCcRecipient, MailToRecipient, MailContainer, MailHeader, MailMailAttachment;
    4.13 +
    4.14 +typedef enum {
    4.15 +	MailSavoYes = 'yes ' /* Save the file. */,
    4.16 +	MailSavoNo = 'no  ' /* Do not save the file. */,
    4.17 +	MailSavoAsk = 'ask ' /* Ask the user whether or not to save the file. */
    4.18 +} MailSavo;
    4.19 +
    4.20 +typedef enum {
    4.21 +	MailEdmfPlainText = 'dmpt' /* Plain Text */,
    4.22 +	MailEdmfRichText = 'dmrt' /* Rich Text */
    4.23 +} MailEdmf;
    4.24 +
    4.25 +typedef enum {
    4.26 +	MailHedeAll = 'hdal' /* All */,
    4.27 +	MailHedeCustom = 'hdcu' /* Custom */,
    4.28 +	MailHedeDefault = 'hdde' /* Default */,
    4.29 +	MailHedeNoHeaders = 'hdnn' /* No headers */
    4.30 +} MailHede;
    4.31 +
    4.32 +typedef enum {
    4.33 +	MailLdasBase = 'lsba' /* LDAP scope of 'Base' */,
    4.34 +	MailLdasOneLevel = 'lsol' /* LDAP scope of 'One Level' */,
    4.35 +	MailLdasSubtree = 'lsst' /* LDAP scope of 'Subtree' */
    4.36 +} MailLdas;
    4.37 +
    4.38 +typedef enum {
    4.39 +	MailQqclBlue = 'ccbl' /* Blue */,
    4.40 +	MailQqclGreen = 'ccgr' /* Green */,
    4.41 +	MailQqclOrange = 'ccor' /* Orange */,
    4.42 +	MailQqclOther = 'ccot' /* Other */,
    4.43 +	MailQqclPurple = 'ccpu' /* Purple */,
    4.44 +	MailQqclRed = 'ccre' /* Red */,
    4.45 +	MailQqclYellow = 'ccye' /* Yellow */
    4.46 +} MailQqcl;
    4.47 +
    4.48 +typedef enum {
    4.49 +	MailMvclAttachmentsColumn = 'ecat' /* Column containing the number of attachments a message contains */,
    4.50 +	MailMvclBuddyAvailabilityColumn = 'ecba' /* Column indicating whether the sender of a message is online or not */,
    4.51 +	MailMvclMessageColor = 'eccl' /* Used to indicate sorting should be done by color */,
    4.52 +	MailMvclDateReceivedColumn = 'ecdr' /* Column containing the date a message was received */,
    4.53 +	MailMvclDateSentColumn = 'ecds' /* Column containing the date a message was sent */,
    4.54 +	MailMvclFlagsColumn = 'ecfl' /* Column containing the flags of a message */,
    4.55 +	MailMvclFromColumn = 'ecfr' /* Column containing the sender's name */,
    4.56 +	MailMvclMailboxColumn = 'ecmb' /* Column containing the name of the mailbox or account a message is in */,
    4.57 +	MailMvclMessageStatusColumn = 'ecms' /* Column indicating a messages status (read, unread, replied to, forwarded, etc) */,
    4.58 +	MailMvclNumberColumn = 'ecnm' /* Column containing the number of a message in a mailbox */,
    4.59 +	MailMvclSizeColumn = 'ecsz' /* Column containing the size of a message */,
    4.60 +	MailMvclSubjectColumn = 'ecsu' /* Column containing the subject of a message */,
    4.61 +	MailMvclToColumn = 'ecto' /* Column containing the recipients of a message */
    4.62 +} MailMvcl;
    4.63 +
    4.64 +typedef enum {
    4.65 +	MailExutPassword = 'axct' /* Clear text password */,
    4.66 +	MailExutApop = 'aapo' /* APOP */,
    4.67 +	MailExutKerberos5 = 'axk5' /* Kerberos 5 */,
    4.68 +	MailExutNtlm = 'axnt' /* NTLM */,
    4.69 +	MailExutMd5 = 'axmd' /* MD5 */,
    4.70 +	MailExutNone = 'ccno' /* None */
    4.71 +} MailExut;
    4.72 +
    4.73 +typedef enum {
    4.74 +	MailCclrBlue = 'ccbl' /* Blue */,
    4.75 +	MailCclrGray = 'ccgy' /* Gray */,
    4.76 +	MailCclrGreen = 'ccgr' /* Green */,
    4.77 +	MailCclrNone = 'ccno' /* None */,
    4.78 +	MailCclrOrange = 'ccor' /* Orange */,
    4.79 +	MailCclrOther = 'ccot' /* Other */,
    4.80 +	MailCclrPurple = 'ccpu' /* Purple */,
    4.81 +	MailCclrRed = 'ccre' /* Red */,
    4.82 +	MailCclrYellow = 'ccye' /* Yellow */
    4.83 +} MailCclr;
    4.84 +
    4.85 +typedef enum {
    4.86 +	MailE9xpAllMessagesAndTheirAttachments = 'x9al' /* All messages and their attachments */,
    4.87 +	MailE9xpAllMessagesButOmitAttachments = 'x9bo' /* All messages but omit attachments */,
    4.88 +	MailE9xpDoNotKeepCopiesOfAnyMessages = 'x9no' /* Do not keep copies of any messages */,
    4.89 +	MailE9xpOnlyMessagesIHaveRead = 'x9wr' /* Only messages I have read */
    4.90 +} MailE9xp;
    4.91 +
    4.92 +typedef enum {
    4.93 +	MailEnrqBeginsWithValue = 'rqbw' /* Begins with value */,
    4.94 +	MailEnrqDoesContainValue = 'rqco' /* Does contain value */,
    4.95 +	MailEnrqDoesNotContainValue = 'rqdn' /* Does not contain value */,
    4.96 +	MailEnrqEndsWithValue = 'rqew' /* Ends with value */,
    4.97 +	MailEnrqEqualToValue = 'rqie' /* Equal to value */,
    4.98 +	MailEnrqLessThanValue = 'rqlt' /* Less than value */,
    4.99 +	MailEnrqGreaterThanValue = 'rqgt' /* Greater than value */,
   4.100 +	MailEnrqNone = 'rqno' /* Indicates no qualifier is applicable */
   4.101 +} MailEnrq;
   4.102 +
   4.103 +typedef enum {
   4.104 +	MailErutAccount = 'tacc' /* Account */,
   4.105 +	MailErutAnyRecipient = 'tanr' /* Any recipient */,
   4.106 +	MailErutCcHeader = 'tccc' /* Cc header */,
   4.107 +	MailErutMatchesEveryMessage = 'tevm' /* Every message */,
   4.108 +	MailErutFromHeader = 'tfro' /* From header */,
   4.109 +	MailErutHeaderKey = 'thdk' /* An arbitrary header key */,
   4.110 +	MailErutMessageContent = 'tmec' /* Message content */,
   4.111 +	MailErutMessageIsJunkMail = 'tmij' /* Message is junk mail */,
   4.112 +	MailErutSenderIsInMyAddressBook = 'tsii' /* Sender is in my address book */,
   4.113 +	MailErutSenderIsMemberOfGroup = 'tsim' /* Sender is member of group */,
   4.114 +	MailErutSenderIsNotInMyAddressBook = 'tsin' /* Sender is not in my address book */,
   4.115 +	MailErutSenderIsNotMemberOfGroup = 'tsig' /* Sender is not member of group */,
   4.116 +	MailErutSubjectHeader = 'tsub' /* Subject header */,
   4.117 +	MailErutToHeader = 'ttoo' /* To header */,
   4.118 +	MailErutToOrCcHeader = 'ttoc' /* To or Cc header */
   4.119 +} MailErut;
   4.120 +
   4.121 +typedef enum {
   4.122 +	MailEtocImap = 'etim' /* IMAP */,
   4.123 +	MailEtocPop = 'etpo' /* POP */,
   4.124 +	MailEtocSmtp = 'etsm' /* SMTP */,
   4.125 +	MailEtocMac = 'etit' /* .Mac */
   4.126 +} MailEtoc;
   4.127 +
   4.128 +
   4.129 +
   4.130 +/*
   4.131 + * Standard Suite
   4.132 + */
   4.133 +
   4.134 +// Abstract object provides a base class for scripting classes.  It is never used directly.
   4.135 +@interface MailItem : SBObject
   4.136 +
   4.137 +@property (copy) NSDictionary *properties;  // All of the object's properties.
   4.138 +
   4.139 +- (void) open;  // Open an object.
   4.140 +- (void) print;  // Print an object.
   4.141 +- (void) closeSaving:(MailSavo)saving savingIn:(NSURL *)savingIn;  // Close an object.
   4.142 +- (void) delete;  // Delete an object.
   4.143 +- (void) duplicateTo:(SBObject *)to;  // Copy object(s) and put the copies at a new location.
   4.144 +- (BOOL) exists;  // Verify if an object exists.
   4.145 +- (void) moveTo:(SBObject *)to;  // Move object(s) to a new location.
   4.146 +- (void) saveIn:(NSString *)in_ as:(NSString *)as;  // Save an object.
   4.147 +
   4.148 +@end
   4.149 +
   4.150 +// An application's top level scripting object.
   4.151 +@interface MailApplication : SBApplication
   4.152 ++ (MailApplication *) application;
   4.153 +
   4.154 +- (SBElementArray *) documents;
   4.155 +- (SBElementArray *) windows;
   4.156 +
   4.157 +@property (copy, readonly) NSString *name;  // The name of the application.
   4.158 +@property (readonly) BOOL frontmost;  // Is this the frontmost (active) application?
   4.159 +@property (copy, readonly) NSString *version;  // The version of the application.
   4.160 +
   4.161 +- (void) quitSaving:(MailSavo)saving;  // Quit an application.
   4.162 +- (void) checkForNewMailFor:(MailAccount *)for_;  // Triggers a check for email.
   4.163 +- (NSString *) extractNameFrom:(NSString *)x;  // Command to get the full name out of a fully specified email address. E.g. Calling this with "John Doe <jdoe@example.com>" as the direct object would return "John Doe"
   4.164 +- (NSString *) extractAddressFrom:(NSString *)x;  // Command to get just the email address of a fully specified email address. E.g. Calling this with "John Doe <jdoe@example.com>" as the direct object would return "jdoe@example.com"
   4.165 +- (void) GetURL:(NSString *)x;  // Opens a mailto URL.
   4.166 +- (void) importMailMailboxAt:(NSString *)at;  // Imports a mailbox in Mail's mbox format.
   4.167 +- (void) mailto:(NSString *)x;  // Opens a mailto URL.
   4.168 +- (void) performMailActionWithMessages:(NSArray *)x inMailboxes:(MailMailbox *)inMailboxes forRule:(MailRule *)forRule;  // Script handler invoked by rules and menus that execute AppleScripts.  The direct parameter of this handler is a list of messages being acted upon.
   4.169 +- (void) synchronizeWith:(MailAccount *)with;  // Command to trigger synchronizing of an IMAP account with the server.
   4.170 +
   4.171 +@end
   4.172 +
   4.173 +// A color.
   4.174 +@interface MailColor : SBObject
   4.175 +
   4.176 +- (void) open;  // Open an object.
   4.177 +- (void) print;  // Print an object.
   4.178 +- (void) closeSaving:(MailSavo)saving savingIn:(NSURL *)savingIn;  // Close an object.
   4.179 +- (void) delete;  // Delete an object.
   4.180 +- (void) duplicateTo:(SBObject *)to;  // Copy object(s) and put the copies at a new location.
   4.181 +- (BOOL) exists;  // Verify if an object exists.
   4.182 +- (void) moveTo:(SBObject *)to;  // Move object(s) to a new location.
   4.183 +- (void) saveIn:(NSString *)in_ as:(NSString *)as;  // Save an object.
   4.184 +
   4.185 +@end
   4.186 +
   4.187 +// A document.
   4.188 +@interface MailDocument : SBObject
   4.189 +
   4.190 +@property (copy) NSString *path;  // The document's path.
   4.191 +@property (readonly) BOOL modified;  // Has the document been modified since the last save?
   4.192 +@property (copy) NSString *name;  // The document's name.
   4.193 +
   4.194 +- (void) open;  // Open an object.
   4.195 +- (void) print;  // Print an object.
   4.196 +- (void) closeSaving:(MailSavo)saving savingIn:(NSURL *)savingIn;  // Close an object.
   4.197 +- (void) delete;  // Delete an object.
   4.198 +- (void) duplicateTo:(SBObject *)to;  // Copy object(s) and put the copies at a new location.
   4.199 +- (BOOL) exists;  // Verify if an object exists.
   4.200 +- (void) moveTo:(SBObject *)to;  // Move object(s) to a new location.
   4.201 +- (void) saveIn:(NSString *)in_ as:(NSString *)as;  // Save an object.
   4.202 +
   4.203 +@end
   4.204 +
   4.205 +// A window.
   4.206 +@interface MailWindow : SBObject
   4.207 +
   4.208 +@property (copy) NSString *name;  // The full title of the window.
   4.209 +- (NSInteger) id;  // The unique identifier of the window.
   4.210 +@property NSRect bounds;  // The bounding rectangle of the window.
   4.211 +@property (readonly) BOOL closeable;  // Whether the window has a close box.
   4.212 +@property (readonly) BOOL titled;  // Whether the window has a title bar.
   4.213 +@property NSInteger index;  // The index of the window in the back-to-front window ordering.
   4.214 +@property (readonly) BOOL floating;  // Whether the window floats.
   4.215 +@property (readonly) BOOL miniaturizable;  // Whether the window can be miniaturized.
   4.216 +@property BOOL miniaturized;  // Whether the window is currently miniaturized.
   4.217 +@property (readonly) BOOL modal;  // Whether the window is the application's current modal window.
   4.218 +@property (readonly) BOOL resizable;  // Whether the window can be resized.
   4.219 +@property BOOL visible;  // Whether the window is currently visible.
   4.220 +@property (readonly) BOOL zoomable;  // Whether the window can be zoomed.
   4.221 +@property BOOL zoomed;  // Whether the window is currently zoomed.
   4.222 +
   4.223 +- (void) open;  // Open an object.
   4.224 +- (void) print;  // Print an object.
   4.225 +- (void) closeSaving:(MailSavo)saving savingIn:(NSURL *)savingIn;  // Close an object.
   4.226 +- (void) delete;  // Delete an object.
   4.227 +- (void) duplicateTo:(SBObject *)to;  // Copy object(s) and put the copies at a new location.
   4.228 +- (BOOL) exists;  // Verify if an object exists.
   4.229 +- (void) moveTo:(SBObject *)to;  // Move object(s) to a new location.
   4.230 +- (void) saveIn:(NSString *)in_ as:(NSString *)as;  // Save an object.
   4.231 +
   4.232 +@end
   4.233 +
   4.234 +
   4.235 +
   4.236 +/*
   4.237 + * Text Suite
   4.238 + */
   4.239 +
   4.240 +// Rich (styled) text
   4.241 +@interface MailText : SBObject
   4.242 +
   4.243 +- (SBElementArray *) paragraphs;
   4.244 +- (SBElementArray *) words;
   4.245 +- (SBElementArray *) characters;
   4.246 +- (SBElementArray *) attributeRuns;
   4.247 +- (SBElementArray *) attachments;
   4.248 +
   4.249 +@property (copy) NSColor *color;  // The color of the first character.
   4.250 +@property (copy) NSString *font;  // The name of the font of the first character.
   4.251 +@property (copy) NSNumber *size;  // The size in points of the first character.
   4.252 +
   4.253 +- (void) open;  // Open an object.
   4.254 +- (void) print;  // Print an object.
   4.255 +- (void) closeSaving:(MailSavo)saving savingIn:(NSURL *)savingIn;  // Close an object.
   4.256 +- (void) delete;  // Delete an object.
   4.257 +- (void) duplicateTo:(SBObject *)to;  // Copy object(s) and put the copies at a new location.
   4.258 +- (BOOL) exists;  // Verify if an object exists.
   4.259 +- (void) moveTo:(SBObject *)to;  // Move object(s) to a new location.
   4.260 +- (void) saveIn:(NSString *)in_ as:(NSString *)as;  // Save an object.
   4.261 +- (NSString *) extractNameFrom;  // Command to get the full name out of a fully specified email address. E.g. Calling this with "John Doe <jdoe@example.com>" as the direct object would return "John Doe"
   4.262 +- (NSString *) extractAddressFrom;  // Command to get just the email address of a fully specified email address. E.g. Calling this with "John Doe <jdoe@example.com>" as the direct object would return "jdoe@example.com"
   4.263 +- (void) GetURL;  // Opens a mailto URL.
   4.264 +- (void) mailto;  // Opens a mailto URL.
   4.265 +
   4.266 +@end
   4.267 +
   4.268 +// Represents an inline text attachment.  This class is used mainly for make commands.
   4.269 +@interface MailAttachment : MailText
   4.270 +
   4.271 +@property (copy) NSString *fileName;  // The path to the file for the attachment
   4.272 +
   4.273 +
   4.274 +@end
   4.275 +
   4.276 +// This subdivides the text into paragraphs.
   4.277 +@interface MailParagraph : MailText
   4.278 +
   4.279 +
   4.280 +@end
   4.281 +
   4.282 +// This subdivides the text into words.
   4.283 +@interface MailWord : MailText
   4.284 +
   4.285 +
   4.286 +@end
   4.287 +
   4.288 +// This subdivides the text into characters.
   4.289 +@interface MailCharacter : MailText
   4.290 +
   4.291 +
   4.292 +@end
   4.293 +
   4.294 +// This subdivides the text into chunks that all have the same attributes.
   4.295 +@interface MailAttributeRun : MailText
   4.296 +
   4.297 +
   4.298 +@end
   4.299 +
   4.300 +
   4.301 +
   4.302 +/*
   4.303 + * Mail
   4.304 + */
   4.305 +
   4.306 +// A new email message
   4.307 +@interface MailOutgoingMessage : MailItem
   4.308 +
   4.309 +- (SBElementArray *) bccRecipients;
   4.310 +- (SBElementArray *) ccRecipients;
   4.311 +- (SBElementArray *) recipients;
   4.312 +- (SBElementArray *) toRecipients;
   4.313 +
   4.314 +@property (copy) NSString *sender;  // The sender of the message
   4.315 +@property (copy) NSString *subject;  // The subject of the message
   4.316 +@property (copy) MailText *content;  // The contents of the message
   4.317 +@property BOOL visible;  // Controls whether the message window is shown on the screen.  The default is false
   4.318 +@property (copy) MailSignature *messageSignature;  // The signature of the message
   4.319 +- (NSInteger) id;  // The unique identifier of the message
   4.320 +
   4.321 +- (BOOL) send;  // Sends a message.
   4.322 +
   4.323 +@end
   4.324 +
   4.325 +// LDAP servers for use in type completion in Mail
   4.326 +@interface MailLdapServer : MailItem
   4.327 +
   4.328 +@property BOOL enabled;  // Indicates whether this LDAP server will be used for type completion in Mail
   4.329 +@property (copy) NSString *name;  // Name of LDAP server configuration to be displayed in Composing preferences
   4.330 +@property NSInteger port;  // Port number for the LDAP server (default is 389)
   4.331 +@property MailLdas scope;  // Scope setting for the LDAP server
   4.332 +@property (copy) NSString *searchBase;  // Search base for this LDAP server (not required by all LDAP servers)
   4.333 +@property (copy) NSString *hostName;  // Internet address (myldapserver.company.com) for LDAP server
   4.334 +
   4.335 +
   4.336 +@end
   4.337 +
   4.338 +// Mail's top level scripting object.
   4.339 +@interface MailApplication (Mail)
   4.340 +
   4.341 +- (SBElementArray *) accounts;
   4.342 +- (SBElementArray *) outgoingMessages;
   4.343 +- (SBElementArray *) smtpServers;
   4.344 +- (SBElementArray *) MacAccounts;
   4.345 +- (SBElementArray *) imapAccounts;
   4.346 +- (SBElementArray *) ldapServers;
   4.347 +- (SBElementArray *) mailboxes;
   4.348 +- (SBElementArray *) messageViewers;
   4.349 +- (SBElementArray *) popAccounts;
   4.350 +- (SBElementArray *) rules;
   4.351 +- (SBElementArray *) signatures;
   4.352 +
   4.353 +@property (copy, readonly) NSString *version;  // The version of the application.
   4.354 +@property BOOL alwaysBccMyself;  // Indicates whether you will be included in the Bcc: field of messages which you are composing
   4.355 +@property BOOL alwaysCcMyself;  // Indicates whether you will be included in the Cc: field of messages which you are composing
   4.356 +@property (copy, readonly) NSArray *selection;  // List of messages that the user has selected
   4.357 +@property (copy, readonly) NSString *applicationVersion;  // The build number for the Mail application bundle
   4.358 +@property NSInteger fetchInterval;  // The interval (in minutes) between automatic fetches of new mail
   4.359 +@property (readonly) NSInteger backgroundActivityCount;  // Number of background activities currently running in Mail, according to the Activity Viewer
   4.360 +@property BOOL chooseSignatureWhenComposing;  // Indicates whether user can choose a signature directly in a new compose window
   4.361 +@property BOOL colorQuotedText;  // Indicates whether quoted text should be colored
   4.362 +@property MailEdmf defaultMessageFormat;  // Default format for messages being composed or message replies
   4.363 +@property BOOL downloadHtmlAttachments;  // Indicates whether images and attachments in HTML messages should be downloaded and displayed
   4.364 +@property (copy, readonly) MailMailbox *draftsMailbox;  // The top level Drafts mailbox
   4.365 +@property BOOL expandGroupAddresses;  // Indicates whether group addresses will be expanded when entered into the address fields of a new compose message
   4.366 +@property (copy) NSString *fixedWidthFont;  // Font for plain text messages, only used if 'use fixed width font' is set to true
   4.367 +@property double fixedWidthFontSize;  // Font size for plain text messages, only used if 'use fixed width font' is set to true
   4.368 +@property (copy, readonly) NSString *frameworkVersion;  // The build number for the Message framework, used by Mail
   4.369 +@property MailHede headerDetail;  // The level of detail shown for headers on incoming messages
   4.370 +@property (copy, readonly) MailMailbox *inbox;  // The top level In mailbox
   4.371 +@property BOOL includeAllOriginalMessageText;  // Indicates whether all of the original message will be quoted or only the text you have selected (if any)
   4.372 +@property BOOL quoteOriginalMessage;  // Indicates whether the text of the original message will be included in replies
   4.373 +@property BOOL checkSpellingWhileTyping;  // Indicates whether spelling will be checked automatically in messages being composed
   4.374 +@property (copy, readonly) MailMailbox *junkMailbox;  // The top level Junk mailbox
   4.375 +@property MailQqcl levelOneQuotingColor;  // Color for quoted text with one level of indentation
   4.376 +@property MailQqcl levelTwoQuotingColor;  // Color for quoted text with two levels of indentation
   4.377 +@property MailQqcl levelThreeQuotingColor;  // Color for quoted text with three levels of indentation
   4.378 +@property (copy) NSString *messageFont;  // Font for messages (proportional font)
   4.379 +@property double messageFontSize;  // Font size for messages (proportional font)
   4.380 +@property (copy) NSString *messageListFont;  // Font for message list
   4.381 +@property double messageListFontSize;  // Font size for message list
   4.382 +@property (copy) NSString *newMailSound;  // Name of new mail sound or 'None' if no sound is selected
   4.383 +@property (copy, readonly) MailMailbox *outbox;  // The top level Out mailbox
   4.384 +@property BOOL shouldPlayOtherMailSounds;  // Indicates whether sounds will be played for various things such as when a messages is sent or if no mail is found when manually checking for new mail or if there is a fetch error
   4.385 +@property BOOL sameReplyFormat;  // Indicates whether replies will be in the same text format as the message to which you are replying
   4.386 +@property (copy) NSString *selectedSignature;  // Name of current selected signature (or 'randomly', 'sequentially', or 'none')
   4.387 +@property (copy, readonly) MailMailbox *sentMailbox;  // The top level Sent mailbox
   4.388 +@property BOOL fetchesAutomatically;  // Indicates whether mail will automatically be fetched at a specific interval
   4.389 +@property BOOL highlightSelectedThread;  // Indicates whether threads should be highlighted in the Mail viewer window
   4.390 +@property BOOL showOnlineBuddyStatus;  // Indicates whether Mail will show online buddy status
   4.391 +@property (copy, readonly) MailMailbox *trashMailbox;  // The top level Trash mailbox
   4.392 +@property BOOL useAddressCompletion;  // Indicates whether network directories (LDAP) and Address Book will be used for address completion
   4.393 +@property BOOL useFixedWidthFont;  // Should fixed-width font be used for plain text messages?
   4.394 +@property (copy, readonly) NSString *primaryEmail;  // The user's primary email address
   4.395 +
   4.396 +@end
   4.397 +
   4.398 +// Represents the object responsible for managing a viewer window
   4.399 +@interface MailMessageViewer : MailItem
   4.400 +
   4.401 +- (SBElementArray *) messages;
   4.402 +
   4.403 +@property (copy, readonly) MailMailbox *draftsMailbox;  // The top level Drafts mailbox
   4.404 +@property (copy, readonly) MailMailbox *inbox;  // The top level In mailbox
   4.405 +@property (copy, readonly) MailMailbox *junkMailbox;  // The top level Junk mailbox
   4.406 +@property (copy, readonly) MailMailbox *outbox;  // The top level Out mailbox
   4.407 +@property (copy, readonly) MailMailbox *sentMailbox;  // The top level Sent mailbox
   4.408 +@property (copy, readonly) MailMailbox *trashMailbox;  // The top level Trash mailbox
   4.409 +@property MailMvcl sortColumn;  // The column that is currently sorted in the viewer
   4.410 +@property BOOL sortedAscending;  // Whether the viewer is sorted ascending or not
   4.411 +@property BOOL mailboxListVisible;  // Controls whether the list of mailboxes is visible or not
   4.412 +@property BOOL previewPaneIsVisible;  // Controls whether the preview pane of the message viewer window is visible or not
   4.413 +@property MailMvcl visibleColumns;  // List of columns that are visible.  The subject column and the message status column will always be visible
   4.414 +- (NSInteger) id;  // The unique identifier of the message viewer
   4.415 +@property (copy) NSArray *visibleMessages;  // List of messages currently being displayed in the viewer
   4.416 +@property (copy) NSArray *selectedMessages;  // List of messages currently selected
   4.417 +@property (copy) NSArray *selectedMailboxes;  // List of mailboxes currently selected in the list of mailboxes
   4.418 +@property (copy) MailWindow *window;  // The window for the message viewer
   4.419 +
   4.420 +
   4.421 +@end
   4.422 +
   4.423 +// Email signatures
   4.424 +@interface MailSignature : MailItem
   4.425 +
   4.426 +@property (copy) NSString *content;  // Contents of email signature. If there is a version with fonts and/or styles, that will be returned over the plain text version
   4.427 +@property (copy) NSString *name;  // Name of the signature
   4.428 +
   4.429 +
   4.430 +@end
   4.431 +
   4.432 +
   4.433 +
   4.434 +/*
   4.435 + * Message
   4.436 + */
   4.437 +
   4.438 +// An email message
   4.439 +@interface MailMessage : MailItem
   4.440 +
   4.441 +- (SBElementArray *) bccRecipients;
   4.442 +- (SBElementArray *) ccRecipients;
   4.443 +- (SBElementArray *) recipients;
   4.444 +- (SBElementArray *) toRecipients;
   4.445 +- (SBElementArray *) headers;
   4.446 +- (SBElementArray *) mailAttachments;
   4.447 +
   4.448 +- (NSInteger) id;  // The unique identifier of the message.
   4.449 +@property (copy, readonly) NSString *allHeaders;  // All the headers of the message
   4.450 +@property MailCclr backgroundColor;  // The background color of the message
   4.451 +@property (copy) MailMailbox *mailbox;  // The mailbox in which this message is filed
   4.452 +@property (copy) MailText *content;  // Contents of an email message
   4.453 +@property (copy, readonly) NSDate *dateReceived;  // The date a message was received
   4.454 +@property (copy, readonly) NSDate *dateSent;  // The date a message was sent
   4.455 +@property BOOL deletedStatus;  // Indicates whether the message is deleted or not
   4.456 +@property BOOL flaggedStatus;  // Indicates whether the message is flagged or not
   4.457 +@property BOOL junkMailStatus;  // Indicates whether the message has been marked junk or evaluated to be junk by the junk mail filter.
   4.458 +@property BOOL readStatus;  // Indicates whether the message is read or not
   4.459 +@property (copy, readonly) NSString *messageId;  // The unique message ID string
   4.460 +@property (copy, readonly) NSString *source;  // Raw source of the message
   4.461 +@property (copy) NSString *replyTo;  // The address that replies should be sent to
   4.462 +@property NSInteger messageSize;  // The size (in bytes) of a message
   4.463 +@property (copy) NSString *sender;  // The sender of the message
   4.464 +@property (copy) NSString *subject;  // The subject of the message
   4.465 +@property BOOL wasForwarded;  // Indicates whether the message was forwarded or not
   4.466 +@property BOOL wasRedirected;  // Indicates whether the message was redirected or not
   4.467 +@property BOOL wasRepliedTo;  // Indicates whether the message was replied to or not
   4.468 +
   4.469 +- (void) bounce;  // Bounces a message back to the sender.
   4.470 +- (void) delete;  // Delete a message.
   4.471 +- (void) duplicateTo:(MailMailbox *)to;  // Copy message(s) and put the copies in the specified mailbox.
   4.472 +- (MailOutgoingMessage *) forwardOpeningWindow:(BOOL)openingWindow;  // Creates a forwarded message.
   4.473 +- (void) moveTo:(MailMailbox *)to;  // Move message(s) to a new mailbox.
   4.474 +- (MailOutgoingMessage *) redirectOpeningWindow:(BOOL)openingWindow;  // Creates a redirected message.
   4.475 +- (MailOutgoingMessage *) replyOpeningWindow:(BOOL)openingWindow replyToAll:(BOOL)replyToAll;  // Creates a reply message.
   4.476 +
   4.477 +@end
   4.478 +
   4.479 +// A Mail account for receiving messages (IMAP/POP/.Mac). To create a new receiving account, use the 'pop account', 'imap account', and 'Mac account' objects
   4.480 +@interface MailAccount : MailItem
   4.481 +
   4.482 +- (SBElementArray *) mailboxes;
   4.483 +
   4.484 +@property (copy) MailSmtpServer *deliveryAccount;  // The delivery account used when sending mail from this account
   4.485 +@property (copy) NSString *name;  // The name of an account
   4.486 +@property (copy) NSString *password;  // Password for this account. Can be set, but not read via scripting
   4.487 +@property MailExut authentication;  // Preferred authentication scheme for account
   4.488 +@property (readonly) MailEtoc accountType;  // The type of an account
   4.489 +@property (copy) NSArray *emailAddresses;  // The list of email addresses configured for an account
   4.490 +@property (copy) NSString *fullName;  // The users full name configured for an account
   4.491 +@property NSInteger emptyJunkMessagesFrequency;  // Number of days before junk messages are deleted (0 = delete on quit, -1 = never delete)
   4.492 +@property NSInteger emptySentMessagesFrequency;  // Number of days before archived sent messages are deleted (0 = delete on quit, -1 = never delete)
   4.493 +@property NSInteger emptyTrashFrequency;  // Number of days before messages in the trash are permanently deleted (0 = delete on quit, -1 = never delete)
   4.494 +@property BOOL emptyJunkMessagesOnQuit;  // Indicates whether the messages in the junk messages mailboxes will be deleted on quit
   4.495 +@property BOOL emptySentMessagesOnQuit;  // Indicates whether the messages in the sent messages mailboxes will be deleted on quit
   4.496 +@property BOOL emptyTrashOnQuit;  // Indicates whether the messages in deleted messages mailboxes will be permanently deleted on quit
   4.497 +@property BOOL enabled;  // Indicates whether the account is enabled or not
   4.498 +@property (copy) NSString *userName;  // The user name used to connect to an account
   4.499 +@property (copy, readonly) NSURL *accountDirectory;  // The directory where the account stores things on disk
   4.500 +@property NSInteger port;  // The port used to connect to an account
   4.501 +@property (copy) NSString *serverName;  // The host name used to connect to an account
   4.502 +@property BOOL includeWhenGettingNewMail;  // Indicates whether the account will be included when getting new mail
   4.503 +@property BOOL moveDeletedMessagesToTrash;  // Indicates whether messages that are deleted will be moved to the trash mailbox
   4.504 +@property BOOL usesSsl;  // Indicates whether SSL is enabled for this receiving account
   4.505 +
   4.506 +
   4.507 +@end
   4.508 +
   4.509 +// An IMAP email account
   4.510 +@interface MailImapAccount : MailAccount
   4.511 +
   4.512 +@property BOOL compactMailboxesWhenClosing;  // Indicates whether an IMAP mailbox is automatically compacted when you quit Mail or switch to another mailbox
   4.513 +@property MailE9xp messageCaching;  // Message caching setting for this account
   4.514 +@property BOOL storeDraftsOnServer;  // Indicates whether drafts will be stored on the IMAP server
   4.515 +@property BOOL storeJunkMailOnServer;  // Indicates whether junk mail will be stored on the IMAP server
   4.516 +@property BOOL storeSentMessagesOnServer;  // Indicates whether sent messages will be stored on the IMAP server
   4.517 +@property BOOL storeDeletedMessagesOnServer;  // Indicates whether deleted messages will be stored on the IMAP server
   4.518 +
   4.519 +
   4.520 +@end
   4.521 +
   4.522 +// A .Mac email account
   4.523 +@interface MailMacAccount : MailImapAccount
   4.524 +
   4.525 +
   4.526 +@end
   4.527 +
   4.528 +// A POP email account
   4.529 +@interface MailPopAccount : MailAccount
   4.530 +
   4.531 +@property NSInteger bigMessageWarningSize;  // If message size (in bytes) is over this amount, Mail will prompt you asking whether you want to download the message (-1 = do not prompt)
   4.532 +@property NSInteger delayedMessageDeletionInterval;  // Number of days before messages that have been downloaded will be deleted from the server (0 = delete immediately after downloading)
   4.533 +@property BOOL deleteMailOnServer;  // Indicates whether POP account deletes messages on the server after downloading
   4.534 +@property BOOL deleteMessagesWhenMovedFromInbox;  // Indicates whether messages will be deleted from the server when moved from your POP inbox
   4.535 +
   4.536 +
   4.537 +@end
   4.538 +
   4.539 +// An SMTP account (for sending email)
   4.540 +@interface MailSmtpServer : MailItem
   4.541 +
   4.542 +@property (copy, readonly) NSString *name;  // The name of an account
   4.543 +@property (copy) NSString *password;  // Password for this account. Can be set, but not read via scripting
   4.544 +@property (readonly) MailEtoc accountType;  // The type of an account
   4.545 +@property MailExut authentication;  // Preferred authentication scheme for account
   4.546 +@property BOOL enabled;  // Indicates whether the account is enabled or not
   4.547 +@property (copy) NSString *userName;  // The user name used to connect to an account
   4.548 +@property NSInteger port;  // The port used to connect to an account
   4.549 +@property (copy) NSString *serverName;  // The host name used to connect to an account
   4.550 +@property BOOL usesSsl;  // Indicates whether SSL is enabled for this receiving account
   4.551 +
   4.552 +
   4.553 +@end
   4.554 +
   4.555 +// A mailbox that holds messages
   4.556 +@interface MailMailbox : MailItem
   4.557 +
   4.558 +- (SBElementArray *) mailboxes;
   4.559 +- (SBElementArray *) messages;
   4.560 +
   4.561 +@property (copy) NSString *name;  // The name of a mailbox
   4.562 +@property (readonly) NSInteger unreadCount;  // The number of unread messages in the mailbox
   4.563 +@property (copy, readonly) MailAccount *account;
   4.564 +@property (copy, readonly) MailMailbox *container;
   4.565 +
   4.566 +
   4.567 +@end
   4.568 +
   4.569 +// Class for message rules
   4.570 +@interface MailRule : MailItem
   4.571 +
   4.572 +- (SBElementArray *) ruleConditions;
   4.573 +
   4.574 +@property MailCclr colorMessage;  // If rule matches, apply this color
   4.575 +@property BOOL deleteMessage;  // If rule matches, delete message
   4.576 +@property (copy) NSString *forwardText;  // If rule matches, prepend this text to the forwarded message. Set to empty string to include no prepended text
   4.577 +@property (copy) NSString *forwardMessage;  // If rule matches, forward message to this address, or multiple addresses, separated by commas. Set to empty string to disable this action
   4.578 +@property BOOL markFlagged;  // If rule matches, mark message as flagged
   4.579 +@property BOOL markRead;  // If rule matches, mark message as read
   4.580 +@property (copy) NSString *playSound;  // If rule matches, play this sound (specify name of sound or path to sound)
   4.581 +@property (copy) NSArray *redirectMessage;  // If rule matches, redirect message to this address or multiple addresses, separate by commas. Set to empty string to disable this action
   4.582 +@property (copy) NSString *replyText;  // If rule matches, reply to message and prepend with this text. Set to empty string to disable this action
   4.583 +@property (copy) NSURL *runScript;  // If rule matches, run this AppleScript.  Set to POSIX path of compiled AppleScript file.  Set to empty string to disable this action
   4.584 +@property BOOL allConditionsMustBeMet;  // Indicates whether all conditions must be met for rule to execute
   4.585 +@property (copy) MailMailbox *copyMessage;  // If rule matches, copy to this mailbox
   4.586 +@property (copy) MailMailbox *moveMessage;  // If rule matches, move to this mailbox
   4.587 +@property BOOL highlightTextUsingColor;  // Indicates whether the color will be used to highlight the text or background of a message in the message list
   4.588 +@property BOOL enabled;  // Indicates whether the rule is enabled
   4.589 +@property (copy) NSString *name;  // Name of rule
   4.590 +@property BOOL shouldCopyMessage;  // Indicates whether the rule has a copy action
   4.591 +@property BOOL shouldMoveMessage;  // Indicates whether the rule has a transfer action
   4.592 +@property BOOL stopEvaluatingRules;  // If rule matches, stop rule evaluation for this message
   4.593 +
   4.594 +
   4.595 +@end
   4.596 +
   4.597 +// Class for conditions that can be attached to a single rule
   4.598 +@interface MailRuleCondition : MailItem
   4.599 +
   4.600 +@property (copy) NSString *expression;  // Rule expression field
   4.601 +@property (copy) NSString *header;  // Rule header key
   4.602 +@property MailEnrq qualifier;  // Rule qualifier
   4.603 +@property MailErut ruleType;  // Rule type
   4.604 +
   4.605 +
   4.606 +@end
   4.607 +
   4.608 +// An email recipient
   4.609 +@interface MailRecipient : MailItem
   4.610 +
   4.611 +@property (copy) NSString *address;  // The recipients email address
   4.612 +@property (copy) NSString *name;  // The name used for display
   4.613 +
   4.614 +
   4.615 +@end
   4.616 +
   4.617 +// An email recipient in the Bcc: field
   4.618 +@interface MailBccRecipient : MailRecipient
   4.619 +
   4.620 +
   4.621 +@end
   4.622 +
   4.623 +// An email recipient in the Cc: field
   4.624 +@interface MailCcRecipient : MailRecipient
   4.625 +
   4.626 +
   4.627 +@end
   4.628 +
   4.629 +// An email recipient in the To: field
   4.630 +@interface MailToRecipient : MailRecipient
   4.631 +
   4.632 +
   4.633 +@end
   4.634 +
   4.635 +// A mailbox that contains other mailboxes.
   4.636 +@interface MailContainer : MailMailbox
   4.637 +
   4.638 +
   4.639 +@end
   4.640 +
   4.641 +// A header value for a message.  E.g. To, Subject, From.
   4.642 +@interface MailHeader : MailItem
   4.643 +
   4.644 +@property (copy) NSString *content;  // Contents of the header
   4.645 +@property (copy) NSString *name;  // Name of the header value
   4.646 +
   4.647 +
   4.648 +@end
   4.649 +
   4.650 +// A file attached to a received message.
   4.651 +@interface MailMailAttachment : MailItem
   4.652 +
   4.653 +@property (copy, readonly) NSString *name;  // Name of the attachment
   4.654 +@property (copy, readonly) NSString *MIMEType;  // MIME type of the attachment E.g. text/plain.
   4.655 +@property (readonly) NSInteger fileSize;  // Approximate size in bytes.
   4.656 +@property (readonly) BOOL downloaded;  // Indicates whether the attachment has been downloaded.
   4.657 +- (NSString *) id;  // The unique identifier of the attachment.
   4.658 +
   4.659 +
   4.660 +@end
   4.661 +
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/MailUtils.h	Wed Jul 16 10:50:34 2008 -0700
     5.3 @@ -0,0 +1,31 @@
     5.4 +//
     5.5 +//  MailUtils.h
     5.6 +//  YourMove
     5.7 +//
     5.8 +//  Created by Jens Alfke on 7/13/08.
     5.9 +//  Copyright 2008 Jens Alfke. All rights reserved.
    5.10 +//
    5.11 +
    5.12 +#import <Cocoa/Cocoa.h>
    5.13 +@class MailOutgoingMessage;
    5.14 +
    5.15 +
    5.16 +@interface OutgoingEmail : NSObject 
    5.17 +{
    5.18 +    NSString *_subject, *_body, *_sender;
    5.19 +    NSMutableArray *_toRecipients, *_attachments;
    5.20 +    MailOutgoingMessage *_message;
    5.21 +}
    5.22 +
    5.23 ++ (BOOL) isMailRunning;
    5.24 +
    5.25 +- (id) init;
    5.26 +- (id) initWithSubject: (NSString*)subject body: (NSString*)body;
    5.27 +
    5.28 +@property (copy) NSString *subject, *body, *sender;
    5.29 +@property (retain) NSMutableArray *toRecipients, *attachments;
    5.30 +
    5.31 +- (void) show;
    5.32 +- (void) send;
    5.33 +
    5.34 +@end
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/MailUtils.m	Wed Jul 16 10:50:34 2008 -0700
     6.3 @@ -0,0 +1,136 @@
     6.4 +//
     6.5 +//  MailUtils.m
     6.6 +//  YourMove
     6.7 +//
     6.8 +//  Created by Jens Alfke on 7/13/08.
     6.9 +//  Copyright 2008 Jens Alfke. All rights reserved.
    6.10 +//  Adapted from Apple's "SBSendEmail" sample app.
    6.11 +//
    6.12 +
    6.13 +#import "MailUtils.h"
    6.14 +#import "MailBridge.h"
    6.15 +#import "CollectionUtils.h"
    6.16 +
    6.17 +
    6.18 +@implementation OutgoingEmail
    6.19 +
    6.20 +
    6.21 +- (id) init
    6.22 +{
    6.23 +    self = [super init];
    6.24 +    if (self != nil) {
    6.25 +        _toRecipients = [[NSMutableArray alloc] init];
    6.26 +        _attachments  = [[NSMutableArray alloc] init];
    6.27 +    }
    6.28 +    return self;
    6.29 +}
    6.30 +
    6.31 +- (id) initWithSubject: (NSString*)subject body: (NSString*)body
    6.32 +{
    6.33 +    self = [self init];
    6.34 +    if (self != nil) {
    6.35 +        self.subject = subject;
    6.36 +        self.body = body;
    6.37 +    }
    6.38 +    return self;
    6.39 +}
    6.40 +
    6.41 +- (void) dealloc
    6.42 +{
    6.43 +    [_message release];
    6.44 +    [_subject release];
    6.45 +    [_body release];
    6.46 +    [_sender release];
    6.47 +    [_toRecipients release];
    6.48 +    [_attachments release];
    6.49 +    [super dealloc];
    6.50 +}
    6.51 +
    6.52 +
    6.53 +@synthesize subject=_subject, sender=_sender, body=_body,
    6.54 +            toRecipients=_toRecipients, attachments=_attachments;
    6.55 +
    6.56 +
    6.57 ++ (MailApplication*) mailApp
    6.58 +{
    6.59 +    /* create a Scripting Bridge object for talking to the Mail application */
    6.60 +    MailApplication *mail = [SBApplication applicationWithBundleIdentifier:@"com.apple.Mail"];
    6.61 +    mail.timeout = 5*60; // in ticks
    6.62 +    return mail;
    6.63 +}
    6.64 +
    6.65 ++ (BOOL) isMailRunning
    6.66 +{
    6.67 +    return [self mailApp].isRunning;
    6.68 +}
    6.69 +
    6.70 +- (MailOutgoingMessage*) _message
    6.71 +{
    6.72 +    if( ! _message ) {
    6.73 +        MailApplication *mail = [[self class] mailApp];
    6.74 +        
    6.75 +        /* create a new outgoing message object */
    6.76 +        MailOutgoingMessage *emailMessage =
    6.77 +            [[[mail classForScriptingClass:@"outgoing message"] alloc] initWithProperties:
    6.78 +                                                                 $dict({@"subject", self.subject},
    6.79 +                                                                       {@"content", self.body})];
    6.80 +        
    6.81 +        /* set the sender, show the message */
    6.82 +        if( _sender )
    6.83 +            emailMessage.sender = _sender;
    6.84 +        
    6.85 +        /* Have to add this to a container now, else the scripting bridge complains */
    6.86 +        [[mail outgoingMessages] addObject: emailMessage];
    6.87 +
    6.88 +        /* create a new recipient and add it to the recipients list */
    6.89 +        for( NSString *recipient in _toRecipients ) {
    6.90 +            MailToRecipient *theRecipient =
    6.91 +                [[[mail classForScriptingClass:@"to recipient"] alloc] initWithProperties:
    6.92 +                                                                 $dict({@"address", recipient})];
    6.93 +            [emailMessage.toRecipients addObject: theRecipient];
    6.94 +        }
    6.95 +        
    6.96 +        /* add an attachment, if one was specified */
    6.97 +        for( NSString *attachmentPath in self.attachments ) {
    6.98 +            /* create an attachment object */
    6.99 +            MailAttachment *theAttachment = 
   6.100 +                [[[mail classForScriptingClass:@"attachment"] alloc] initWithProperties:
   6.101 +                                                                 $dict({@"fileName", attachmentPath})];
   6.102 +            
   6.103 +            /* add it to the list of attachments */
   6.104 +            [[emailMessage.content attachments] addObject: theAttachment];
   6.105 +        }
   6.106 +        
   6.107 +        /* add the object to the mail app  */
   6.108 +        _message = [emailMessage retain];
   6.109 +    }
   6.110 +    return _message;
   6.111 +}
   6.112 +
   6.113 +
   6.114 +- (void) show
   6.115 +{
   6.116 +	self._message.visible = YES;
   6.117 +    [[[self class] mailApp] activate];
   6.118 +}
   6.119 +
   6.120 +
   6.121 +- (void) send
   6.122 +{
   6.123 +	[self._message send];
   6.124 +}
   6.125 +
   6.126 +
   6.127 +@end
   6.128 +
   6.129 +
   6.130 +
   6.131 +
   6.132 +TestCase(MailUtils) {
   6.133 +    OutgoingEmail *m = [[OutgoingEmail alloc] initWithSubject: @"This is a test"
   6.134 +                                                         body: @"Hi there! This is a test email from an automated test case. http://mooseyard.com/"];
   6.135 +    [m.toRecipients addObject: @"jens@mooseyard.com"];
   6.136 +    [m show];
   6.137 +    //[m send];
   6.138 +    [m release];
   6.139 +}
     7.1 --- a/URLUtils.h	Sun Jul 13 10:45:42 2008 -0700
     7.2 +++ b/URLUtils.h	Wed Jul 16 10:50:34 2008 -0700
     7.3 @@ -9,6 +9,19 @@
     7.4  #import <Foundation/Foundation.h>
     7.5  
     7.6  
     7.7 +@interface NSURL (MYUtilities)
     7.8 +
     7.9 +/** Smart/lenient version of +URLWithString:, for use with user-entered URLs.
    7.10 +    - Strips out any whitespace or newlines
    7.11 +    - Removes surrounding "<...>"
    7.12 +    - Adds a default scheme like http: if necessary, if one is provided
    7.13 +    - Checks against a list of allowed schemes, if one is provided */
    7.14 ++ (NSURL*) my_URLWithLenientString: (NSString*)string 
    7.15 +                     defaultScheme: (NSString*)defaultScheme
    7.16 +                    allowedSchemes: (NSArray*)allowedSchemes;
    7.17 +@end
    7.18 +
    7.19 +
    7.20  @interface NSHTTPURLResponse (MYUtilities)
    7.21  
    7.22  - (NSError*) HTTPError;
     8.1 --- a/URLUtils.m	Sun Jul 13 10:45:42 2008 -0700
     8.2 +++ b/URLUtils.m	Wed Jul 16 10:50:34 2008 -0700
     8.3 @@ -9,6 +9,64 @@
     8.4  #import "URLUtils.h"
     8.5  
     8.6  
     8.7 +@implementation NSURL (MYUtilities)
     8.8 +
     8.9 ++ (NSString*) my_stringByTrimmingURLString: (NSString*)string
    8.10 +{
    8.11 +    NSMutableString *trimmed = [[string mutableCopy] autorelease];
    8.12 +    NSRange r;
    8.13 +    // Remove all whitespace and newlines:
    8.14 +    while(YES){
    8.15 +        r = [trimmed rangeOfCharacterFromSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];
    8.16 +        if( r.length==0 )
    8.17 +            break;
    8.18 +        [trimmed replaceCharactersInRange: r withString: @""];
    8.19 +    }
    8.20 +    
    8.21 +    // Delete surrounding "<...>":
    8.22 +    r = NSMakeRange(0,trimmed.length);
    8.23 +    if( [trimmed hasPrefix: @"<"] ) {
    8.24 +        r.location++;
    8.25 +        r.length--;
    8.26 +    }
    8.27 +    if( [trimmed hasSuffix: @">"] )
    8.28 +        r.length--;
    8.29 +    return [trimmed substringWithRange: r];
    8.30 +}
    8.31 +
    8.32 ++ (NSURL*) my_URLWithLenientString: (NSString*)string 
    8.33 +                     defaultScheme: (NSString*)defaultScheme
    8.34 +                    allowedSchemes: (NSArray*)allowedSchemes
    8.35 +{
    8.36 +    // Trim it:
    8.37 +    string = [self my_stringByTrimmingURLString: string];
    8.38 +    if( string.length==0 )
    8.39 +        return nil;
    8.40 +    NSURL *url = [NSURL URLWithString: string];
    8.41 +    if( ! url )
    8.42 +        return nil;
    8.43 +    // Apply default scheme (if any):
    8.44 +    NSString *scheme = url.scheme.lowercaseString;
    8.45 +    if( scheme == nil ) {
    8.46 +        if(  ! defaultScheme )
    8.47 +            return nil;
    8.48 +        string = $sprintf(@"%@://%@", defaultScheme,string);
    8.49 +        url = [NSURL URLWithString: string];
    8.50 +        scheme = [url scheme];
    8.51 +        if( scheme == nil )
    8.52 +            return nil;
    8.53 +    }
    8.54 +    // Check that scheme is allowed:
    8.55 +    if( allowedSchemes && ![allowedSchemes containsObject: scheme] )
    8.56 +        return nil;
    8.57 +    return url;
    8.58 +}
    8.59 +
    8.60 +@end
    8.61 +
    8.62 +
    8.63 +
    8.64 +
    8.65  @implementation NSHTTPURLResponse (MYUtilities)
    8.66  
    8.67