Monotone-Parent: e339a3442f42acdf4909a6baec00b5327ae53cb3

Monotone-Revision: ee950e307e6571a0c19bb8438551295e0126c17e

Monotone-Author: wsourdeau@inverse.ca
Monotone-Date: 2010-08-26T15:30:51
Monotone-Branch: ca.inverse.sogo
This commit is contained in:
Wolfgang Sourdeau 2010-08-26 15:30:51 +00:00
parent a4488f234f
commit 14d3f1ae86
2 changed files with 66 additions and 50 deletions

View file

@ -1,5 +1,10 @@
2010-08-26 Wolfgang Sourdeau <wsourdeau@inverse.ca> 2010-08-26 Wolfgang Sourdeau <wsourdeau@inverse.ca>
* 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" * UI/MailerUI/UIxMailEditor.m (_emailFromIdentity:): the "from"
field is handled in SOGoDraftObject, therefore we don't need to field is handled in SOGoDraftObject, therefore we don't need to
modify it here, especially since this will alterate the display. modify it here, especially since this will alterate the display.

View file

@ -1202,58 +1202,69 @@ static NSString *userAgent = nil;
return NO; return NO;
} }
- (NSArray *) _quoteSpecials: (NSArray *) _array - (NSString *) _quoteSpecials: (NSString *) address
{ {
NSMutableArray *a; NSString *result, *part, *s2;
NSString *s1, *s2; int i, len;
int i, j, len;
a = [NSMutableArray array];
// We want to correctly send mails to recipients such as : // We want to correctly send mails to recipients such as :
// foo.bar // foo.bar
// foo (bar) <foo@zot.com> // foo (bar) <foo@zot.com>
// bar, foo <foo@zot.com> // bar, foo <foo@zot.com>
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 if (i > 0)
|| [s1 indexOf: '<'] >= 0 || [s1 indexOf: '>'] >= 0 {
|| [s1 indexOf: '@'] >= 0 || [s1 indexOf: ','] >= 0 part = [address substringToIndex: i - 1];
|| [s1 indexOf: ';'] >= 0 || [s1 indexOf: ':'] >= 0 s2 = [[part stringByReplacingString: @"\\" withString: @"\\\\"]
|| [s1 indexOf: '\\'] >= 0 || [s1 indexOf: '"'] >= 0 stringByReplacingString: @"\"" withString: @"\\\""];
|| [s1 indexOf: '.'] >= 0 result = [NSString stringWithFormat: @"\"%@\" %@", s2, [address substringFromIndex: i]];
|| [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];
}
else 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 - (NGMutableHashMap *) mimeHeaderMapWithHeaders: (NSDictionary *) _headers
@ -1269,11 +1280,11 @@ static NSString *userAgent = nil;
/* add recipients */ /* add recipients */
if ((emails = [headers objectForKey: @"to"]) != nil) 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) 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) if ((emails = [headers objectForKey: @"bcc"]) != nil)
[map setObjects: [self _quoteSpecials: emails] forKey: @"bcc"]; [map setObjects: [self _quoteSpecialsInArray: emails] forKey: @"bcc"];
/* add senders */ /* add senders */
@ -1282,20 +1293,20 @@ static NSString *userAgent = nil;
if (![self isEmptyValue:from]) { if (![self isEmptyValue:from]) {
if ([from isKindOfClass:[NSArray class]]) if ([from isKindOfClass:[NSArray class]])
[map setObjects: from forKey: @"from"]; [map setObjects: [self _quoteSpecialsInArray: from] forKey: @"from"];
else else
[map setObject: from forKey: @"from"]; [map setObject: [self _quoteSpecials: from] forKey: @"from"];
} }
if (![self isEmptyValue: replyTo]) { if (![self isEmptyValue: replyTo]) {
if ([from isKindOfClass:[NSArray class]]) if ([from isKindOfClass:[NSArray class]])
[map setObjects:from forKey: @"reply-to"]; [map setObjects: [self _quoteSpecialsInArray: from] forKey: @"reply-to"];
else else
[map setObject:from forKey: @"reply-to"]; [map setObject: [self _quoteSpecials: from] forKey: @"reply-to"];
} }
else if (![self isEmptyValue:from]) else if (![self isEmptyValue:from])
[map setObjects:[map objectsForKey: @"from"] forKey: @"reply-to"]; [map setObjects: [map objectsForKey: @"from"] forKey: @"reply-to"];
if (inReplyTo) if (inReplyTo)
[map setObject: inReplyTo forKey: @"in-reply-to"]; [map setObject: inReplyTo forKey: @"in-reply-to"];