From 14d3f1ae86b347b72ad4643c70fa2b02c84a64de Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Thu, 26 Aug 2010 15:30:51 +0000 Subject: [PATCH] Monotone-Parent: e339a3442f42acdf4909a6baec00b5327ae53cb3 Monotone-Revision: ee950e307e6571a0c19bb8438551295e0126c17e Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2010-08-26T15:30:51 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 5 ++ SoObjects/Mailer/SOGoDraftObject.m | 111 ++++++++++++++++------------- 2 files changed, 66 insertions(+), 50 deletions(-) diff --git a/ChangeLog b/ChangeLog index a98d0f91e..af0e05b8b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2010-08-26 Wolfgang Sourdeau + * SoObjects/Mailer/SOGoDraftObject.m (_quoteSpecials:): now work + on single strings. + (_quoteSpecialsInArray:): new method that offers the same + functionality as _quoteSpecials: did before the change above. + * UI/MailerUI/UIxMailEditor.m (_emailFromIdentity:): the "from" field is handled in SOGoDraftObject, therefore we don't need to modify it here, especially since this will alterate the display. diff --git a/SoObjects/Mailer/SOGoDraftObject.m b/SoObjects/Mailer/SOGoDraftObject.m index 6333cd51d..45773d087 100644 --- a/SoObjects/Mailer/SOGoDraftObject.m +++ b/SoObjects/Mailer/SOGoDraftObject.m @@ -1202,58 +1202,69 @@ static NSString *userAgent = nil; return NO; } -- (NSArray *) _quoteSpecials: (NSArray *) _array +- (NSString *) _quoteSpecials: (NSString *) address { - NSMutableArray *a; - NSString *s1, *s2; - int i, j, len; - - a = [NSMutableArray array]; + NSString *result, *part, *s2; + int i, len; // We want to correctly send mails to recipients such as : // foo.bar // foo (bar) // bar, foo - for (i = 0; i < [_array count]; i++) + if ([address indexOf: '('] >= 0 || [address indexOf: ')'] >= 0 + || [address indexOf: '<'] >= 0 || [address indexOf: '>'] >= 0 + || [address indexOf: '@'] >= 0 || [address indexOf: ','] >= 0 + || [address indexOf: ';'] >= 0 || [address indexOf: ':'] >= 0 + || [address indexOf: '\\'] >= 0 || [address indexOf: '"'] >= 0 + || [address indexOf: '.'] >= 0 + || [address indexOf: '['] >= 0 || [address indexOf: ']'] >= 0) { - s1 = [_array objectAtIndex: i]; + // We search for the first instance of < from the end + // and we quote what was before if we need to + len = [address length]; + i = -1; + while (len--) + if ([address characterAtIndex: len] == '<') + { + i = len; + break; + } - if ([s1 indexOf: '('] >= 0 || [s1 indexOf: ')'] >= 0 - || [s1 indexOf: '<'] >= 0 || [s1 indexOf: '>'] >= 0 - || [s1 indexOf: '@'] >= 0 || [s1 indexOf: ','] >= 0 - || [s1 indexOf: ';'] >= 0 || [s1 indexOf: ':'] >= 0 - || [s1 indexOf: '\\'] >= 0 || [s1 indexOf: '"'] >= 0 - || [s1 indexOf: '.'] >= 0 - || [s1 indexOf: '['] >= 0 || [s1 indexOf: ']'] >= 0) - { - // We search for the first instance of < from the end - // and we quote what was before if we need to - len = [s1 length]; - j = -1; - while (len--) - if ([s1 characterAtIndex: len] == '<') - { - j = len; - break; - } - - if (j > 0) - { - s2 = [s1 substringToIndex: j-1]; - s2 = [NSString stringWithFormat: @"\"%@\" %@", s2, [s1 substringFromIndex: j]]; - } - else - { - s2 = [NSString stringWithFormat: @"\"%@\"", s1]; - } - - [a addObject: s2]; - } + if (i > 0) + { + part = [address substringToIndex: i - 1]; + s2 = [[part stringByReplacingString: @"\\" withString: @"\\\\"] + stringByReplacingString: @"\"" withString: @"\\\""]; + result = [NSString stringWithFormat: @"\"%@\" %@", s2, [address substringFromIndex: i]]; + } else - [a addObject: s1]; + { + s2 = [[address stringByReplacingString: @"\\" withString: @"\\\\"] + stringByReplacingString: @"\"" withString: @"\\\""]; + result = [NSString stringWithFormat: @"\"%@\"", s2]; + } + } + else + result = address; + + return result; +} + +- (NSArray *) _quoteSpecialsInArray: (NSArray *) addresses +{ + NSMutableArray *result; + NSString *address; + int count, max; + + max = [addresses count]; + result = [NSMutableArray arrayWithCapacity: max]; + for (count = 0; count < max; count++) + { + address = [self _quoteSpecials: [addresses objectAtIndex: count]]; + [result addObject: address]; } - return a; + return result; } - (NGMutableHashMap *) mimeHeaderMapWithHeaders: (NSDictionary *) _headers @@ -1269,11 +1280,11 @@ static NSString *userAgent = nil; /* add recipients */ if ((emails = [headers objectForKey: @"to"]) != nil) - [map setObjects: [self _quoteSpecials: emails] forKey: @"to"]; + [map setObjects: [self _quoteSpecialsInArray: emails] forKey: @"to"]; if ((emails = [headers objectForKey: @"cc"]) != nil) - [map setObjects: [self _quoteSpecials: emails] forKey: @"cc"]; + [map setObjects: [self _quoteSpecialsInArray: emails] forKey: @"cc"]; if ((emails = [headers objectForKey: @"bcc"]) != nil) - [map setObjects: [self _quoteSpecials: emails] forKey: @"bcc"]; + [map setObjects: [self _quoteSpecialsInArray: emails] forKey: @"bcc"]; /* add senders */ @@ -1282,20 +1293,20 @@ static NSString *userAgent = nil; if (![self isEmptyValue:from]) { if ([from isKindOfClass:[NSArray class]]) - [map setObjects: from forKey: @"from"]; + [map setObjects: [self _quoteSpecialsInArray: from] forKey: @"from"]; else - [map setObject: from forKey: @"from"]; + [map setObject: [self _quoteSpecials: from] forKey: @"from"]; } if (![self isEmptyValue: replyTo]) { if ([from isKindOfClass:[NSArray class]]) - [map setObjects:from forKey: @"reply-to"]; + [map setObjects: [self _quoteSpecialsInArray: from] forKey: @"reply-to"]; else - [map setObject:from forKey: @"reply-to"]; + [map setObject: [self _quoteSpecials: from] forKey: @"reply-to"]; } else if (![self isEmptyValue:from]) - [map setObjects:[map objectsForKey: @"from"] forKey: @"reply-to"]; - + [map setObjects: [map objectsForKey: @"from"] forKey: @"reply-to"]; + if (inReplyTo) [map setObject: inReplyTo forKey: @"in-reply-to"];