mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-04-28 00:09:29 +00:00
fix(eas): use bare email address (fixes #5612) - initial fix from @tfux
This commit is contained in:
@@ -31,10 +31,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#define __NGMIMEMESSAGEACTIVESYNC_H__
|
||||
|
||||
#import <NGMail/NGMimeMessage.h>
|
||||
#import "SOGoMailBaseObject.h"
|
||||
|
||||
@class NSArray;
|
||||
@class SOGoMailObject;
|
||||
|
||||
@interface NGMimeMessage (ActiveSync)
|
||||
@interface NGMimeMessage (ActiveSync) : SOGoMailBaseObject
|
||||
|
||||
- (NSArray *) allRecipients;
|
||||
|
||||
|
||||
@@ -29,48 +29,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#import "NGMimeMessage+ActiveSync.h"
|
||||
|
||||
#import <Foundation/NSArray.h>
|
||||
|
||||
#import <NGMail/NGMailAddress.h>
|
||||
#import <NGMail/NGMailAddressParser.h>
|
||||
|
||||
#import <SOGo/NSString+Utilities.h>
|
||||
|
||||
@implementation NGMimeMessage (ActiveSync)
|
||||
|
||||
- (void) _addRecipients: (NSEnumerator *) enumerator
|
||||
toArray: (NSMutableArray *) recipients
|
||||
{
|
||||
NGMailAddressParser *parser;
|
||||
NSEnumerator *addressList;
|
||||
NGMailAddress *address;
|
||||
NSString *s;
|
||||
|
||||
while ((s = [enumerator nextObject]))
|
||||
{
|
||||
parser = [NGMailAddressParser mailAddressParserWithString: s];
|
||||
addressList = [[parser parseAddressList] objectEnumerator];
|
||||
|
||||
while ((address = [addressList nextObject]))
|
||||
[recipients addObject: [address address]];
|
||||
}
|
||||
}
|
||||
|
||||
- (NSArray *) allRecipients
|
||||
{
|
||||
NSMutableArray *recipients;
|
||||
|
||||
recipients = [NSMutableArray array];
|
||||
|
||||
[self _addRecipients: [[self headersForKey: @"to"] objectEnumerator]
|
||||
toArray: recipients];
|
||||
|
||||
[self _addRecipients: [[self headersForKey: @"cc"] objectEnumerator]
|
||||
toArray: recipients];
|
||||
|
||||
[self _addRecipients: [[self headersForKey: @"bcc"] objectEnumerator]
|
||||
toArray: recipients];
|
||||
|
||||
return recipients;
|
||||
}
|
||||
@end
|
||||
|
||||
@@ -3619,7 +3619,7 @@ void handle_eas_terminate(int signum)
|
||||
}
|
||||
|
||||
error = [self _sendMail: data
|
||||
recipients: [message allRecipients]
|
||||
recipients: [message allBareRecipients]
|
||||
saveInSentItems: ([(id)[theDocumentElement getElementsByTagName: @"SaveInSentItems"] count] ? YES : NO)];
|
||||
|
||||
if (error)
|
||||
@@ -4180,7 +4180,7 @@ void handle_eas_terminate(int signum)
|
||||
data = [generator generateMimeFromPart: messageToSend];
|
||||
|
||||
error = [self _sendMail: data
|
||||
recipients: [messageFromSmartForward allRecipients]
|
||||
recipients: [messageFromSmartForward allBareRecipients]
|
||||
saveInSentItems: ([(id)[theDocumentElement getElementsByTagName: @"SaveInSentItems"] count] ? YES : NO)];
|
||||
|
||||
if (error)
|
||||
|
||||
@@ -54,7 +54,6 @@
|
||||
NSString *path;
|
||||
int IMAP4ID;
|
||||
int sourceIMAP4ID;
|
||||
NSMutableDictionary *headers;
|
||||
NSString *inReplyTo;
|
||||
NSString *text;
|
||||
NSString *sourceURL;
|
||||
@@ -77,8 +76,6 @@
|
||||
toAll: (BOOL) toAll;
|
||||
- (void) fetchMailForForwarding: (SOGoMailObject *) sourceMail;
|
||||
|
||||
- (void) setHeaders: (NSDictionary *) newHeaders;
|
||||
- (NSDictionary *) headers;
|
||||
- (void) setText: (NSString *) newText;
|
||||
- (NSString *) text;
|
||||
- (void) setIsHTML: (BOOL) aBool;
|
||||
@@ -119,10 +116,6 @@
|
||||
|
||||
- (NSData *) mimeMessageForRecipient: (NSString *) theRecipient;
|
||||
|
||||
/* operations */
|
||||
- (NSArray *) allRecipients;
|
||||
- (NSArray *) allBareRecipients;
|
||||
|
||||
- (NSException *) delete;
|
||||
- (NSException *) sendMail;
|
||||
- (NSException *) sendMailAndCopyToSent: (BOOL) copyToSent; /* default: YES */
|
||||
|
||||
@@ -87,9 +87,6 @@
|
||||
|
||||
static NSString *contentTypeValue = @"text/plain; charset=utf-8";
|
||||
static NSString *htmlContentTypeValue = @"text/html; charset=utf-8";
|
||||
static NSString *headerKeys[] = {@"subject", @"to", @"cc", @"bcc",
|
||||
@"from", @"replyTo", @"message-id",
|
||||
nil};
|
||||
|
||||
#warning -[NGImap4Connection postData:flags:toFolderURL:] should be enhanced \
|
||||
to return at least the new uid
|
||||
@@ -131,7 +128,6 @@ static NSString *userAgent = nil;
|
||||
{
|
||||
sourceIMAP4ID = -1;
|
||||
IMAP4ID = -1;
|
||||
headers = [[NSMutableDictionary alloc] init];
|
||||
certificates = [[NSMutableDictionary alloc] init];
|
||||
text = @"";
|
||||
path = nil;
|
||||
@@ -148,7 +144,6 @@ static NSString *userAgent = nil;
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[headers release];
|
||||
[certificates release];
|
||||
[text release];
|
||||
[path release];
|
||||
@@ -198,120 +193,6 @@ static NSString *userAgent = nil;
|
||||
|
||||
/* contents */
|
||||
|
||||
- (void) setHeaders: (NSDictionary *) newHeaders
|
||||
{
|
||||
id headerValue;
|
||||
unsigned int count;
|
||||
NSString *messageID, *priority, *pureSender, *replyTo, *receipt;
|
||||
|
||||
for (count = 0; count < 8; count++)
|
||||
{
|
||||
headerValue = [newHeaders objectForKey: headerKeys[count]];
|
||||
if (headerValue)
|
||||
[headers setObject: headerValue
|
||||
forKey: headerKeys[count]];
|
||||
else if ([headers objectForKey: headerKeys[count]])
|
||||
[headers removeObjectForKey: headerKeys[count]];
|
||||
}
|
||||
|
||||
messageID = [headers objectForKey: @"message-id"];
|
||||
if (!messageID)
|
||||
{
|
||||
messageID = [NSString generateMessageID];
|
||||
[headers setObject: messageID forKey: @"message-id"];
|
||||
}
|
||||
|
||||
priority = [newHeaders objectForKey: @"X-Priority"];
|
||||
if (priority)
|
||||
{
|
||||
// newHeaders come from MIME message; convert X-Priority to Web representation
|
||||
[headers setObject: priority forKey: @"X-Priority"];
|
||||
[headers removeObjectForKey: @"priority"];
|
||||
if ([priority isEqualToString: @"1 (Highest)"])
|
||||
{
|
||||
[headers setObject: @"HIGHEST" forKey: @"priority"];
|
||||
}
|
||||
else if ([priority isEqualToString: @"2 (High)"])
|
||||
{
|
||||
[headers setObject: @"HIGH" forKey: @"priority"];
|
||||
}
|
||||
else if ([priority isEqualToString: @"4 (Low)"])
|
||||
{
|
||||
[headers setObject: @"LOW" forKey: @"priority"];
|
||||
}
|
||||
else if ([priority isEqualToString: @"5 (Lowest)"])
|
||||
{
|
||||
[headers setObject: @"LOWEST" forKey: @"priority"];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// newHeaders come from Web form; convert priority to MIME header representation
|
||||
priority = [newHeaders objectForKey: @"priority"];
|
||||
if ([priority intValue] == 1)
|
||||
{
|
||||
[headers setObject: @"1 (Highest)" forKey: @"X-Priority"];
|
||||
}
|
||||
else if ([priority intValue] == 2)
|
||||
{
|
||||
[headers setObject: @"2 (High)" forKey: @"X-Priority"];
|
||||
}
|
||||
else if ([priority intValue] == 4)
|
||||
{
|
||||
[headers setObject: @"4 (Low)" forKey: @"X-Priority"];
|
||||
}
|
||||
else if ([priority intValue] == 5)
|
||||
{
|
||||
[headers setObject: @"5 (Lowest)" forKey: @"X-Priority"];
|
||||
}
|
||||
else
|
||||
{
|
||||
[headers removeObjectForKey: @"X-Priority"];
|
||||
}
|
||||
if (priority)
|
||||
{
|
||||
[headers setObject: priority forKey: @"priority"];
|
||||
}
|
||||
}
|
||||
|
||||
replyTo = [headers objectForKey: @"replyTo"];
|
||||
if ([replyTo length] > 0)
|
||||
{
|
||||
[headers setObject: replyTo forKey: @"reply-to"];
|
||||
}
|
||||
[headers removeObjectForKey: @"replyTo"];
|
||||
|
||||
receipt = [newHeaders objectForKey: @"Disposition-Notification-To"];
|
||||
if ([receipt length] > 0)
|
||||
{
|
||||
[headers setObject: @"true" forKey: @"receipt"];
|
||||
[headers setObject: receipt forKey: @"Disposition-Notification-To"];
|
||||
}
|
||||
else
|
||||
{
|
||||
receipt = [newHeaders objectForKey: @"receipt"];
|
||||
if ([receipt boolValue])
|
||||
{
|
||||
[headers setObject: receipt forKey: @"receipt"];
|
||||
pureSender = [[newHeaders objectForKey: @"from"] pureEMailAddress];
|
||||
if (pureSender)
|
||||
{
|
||||
[headers setObject: pureSender forKey: @"Disposition-Notification-To"];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
[headers removeObjectForKey: @"receipt"];
|
||||
[headers removeObjectForKey: @"Disposition-Notification-To"];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (NSDictionary *) headers
|
||||
{
|
||||
return headers;
|
||||
}
|
||||
|
||||
- (void) setText: (NSString *) newText
|
||||
{
|
||||
ASSIGN (text, newText);
|
||||
@@ -1948,46 +1829,6 @@ static NSString *userAgent = nil;
|
||||
return d;
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
- (NSArray *) allRecipients
|
||||
{
|
||||
NSMutableArray *allRecipients;
|
||||
NSArray *recipients;
|
||||
NSString *fieldNames[] = {@"to", @"cc", @"bcc"};
|
||||
unsigned int count;
|
||||
|
||||
allRecipients = [NSMutableArray arrayWithCapacity: 16];
|
||||
|
||||
for (count = 0; count < 3; count++)
|
||||
{
|
||||
recipients = [headers objectForKey: fieldNames[count]];
|
||||
if ([recipients count] > 0)
|
||||
[allRecipients addObjectsFromArray: recipients];
|
||||
}
|
||||
|
||||
return allRecipients;
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
- (NSArray *) allBareRecipients
|
||||
{
|
||||
NSMutableArray *bareRecipients;
|
||||
NSEnumerator *allRecipients;
|
||||
NSString *recipient;
|
||||
|
||||
bareRecipients = [NSMutableArray array];
|
||||
|
||||
allRecipients = [[self allRecipients] objectEnumerator];
|
||||
while ((recipient = [allRecipients nextObject]))
|
||||
[bareRecipients addObject: [recipient pureEMailAddress]];
|
||||
|
||||
return bareRecipients;
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
SOGoMailObject
|
||||
*/
|
||||
|
||||
@class NSString, NSArray, NSURL;
|
||||
@class NSString, NSArray, NSURL, NSMutableDictionary;
|
||||
@class NGImap4ConnectionManager, NGImap4Connection;
|
||||
@class SOGoMailAccount, SOGoMailAccounts;
|
||||
|
||||
@@ -48,6 +48,7 @@
|
||||
NSURL *imap4URL;
|
||||
NGImap4Connection *imap4;
|
||||
BOOL imap4ExceptionsEnabled;
|
||||
NSMutableDictionary *headers;
|
||||
}
|
||||
|
||||
- (BOOL) isFolderish;
|
||||
@@ -84,6 +85,14 @@
|
||||
|
||||
- (int) IMAP4IDFromAppendResult: (NSDictionary *) result;
|
||||
|
||||
/* contents */
|
||||
- (void) setHeaders: (NSDictionary *) newHeaders;
|
||||
- (NSDictionary *) headers;
|
||||
|
||||
/* operations */
|
||||
- (NSArray *) allRecipients;
|
||||
- (NSArray *) allBareRecipients;
|
||||
|
||||
@end
|
||||
|
||||
#endif /* __Mailer_SOGoMailBaseObject_H__ */
|
||||
|
||||
@@ -38,6 +38,9 @@
|
||||
#import "SOGoMailAccount.h"
|
||||
#import "SOGoMailManager.h"
|
||||
|
||||
static NSString *headerKeys[] = {@"subject", @"to", @"cc", @"bcc",
|
||||
@"from", @"replyTo", @"message-id",
|
||||
nil};
|
||||
|
||||
@implementation SOGoMailBaseObject
|
||||
|
||||
@@ -49,6 +52,7 @@
|
||||
// With this to YES, imap4Connection will raise exception if a working
|
||||
// connection cannot be provided
|
||||
imap4ExceptionsEnabled = [ud boolForKey:@"SoIMAP4ExceptionsEnabled"];
|
||||
headers = [[NSMutableDictionary alloc] init];
|
||||
}
|
||||
|
||||
return self;
|
||||
@@ -72,6 +76,7 @@
|
||||
{
|
||||
[imap4URL release];
|
||||
[imap4 release];
|
||||
[headers release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@@ -370,4 +375,160 @@
|
||||
return [newIdString intValue];
|
||||
}
|
||||
|
||||
/* contents */
|
||||
|
||||
- (void) setHeaders: (NSDictionary *) newHeaders
|
||||
{
|
||||
id headerValue;
|
||||
unsigned int count;
|
||||
NSString *messageID, *priority, *pureSender, *replyTo, *receipt;
|
||||
|
||||
for (count = 0; count < 8; count++)
|
||||
{
|
||||
headerValue = [newHeaders objectForKey: headerKeys[count]];
|
||||
if (headerValue)
|
||||
[headers setObject: headerValue
|
||||
forKey: headerKeys[count]];
|
||||
else if ([headers objectForKey: headerKeys[count]])
|
||||
[headers removeObjectForKey: headerKeys[count]];
|
||||
}
|
||||
|
||||
messageID = [headers objectForKey: @"message-id"];
|
||||
if (!messageID)
|
||||
{
|
||||
messageID = [NSString generateMessageID];
|
||||
[headers setObject: messageID forKey: @"message-id"];
|
||||
}
|
||||
|
||||
priority = [newHeaders objectForKey: @"X-Priority"];
|
||||
if (priority)
|
||||
{
|
||||
// newHeaders come from MIME message; convert X-Priority to Web representation
|
||||
[headers setObject: priority forKey: @"X-Priority"];
|
||||
[headers removeObjectForKey: @"priority"];
|
||||
if ([priority isEqualToString: @"1 (Highest)"])
|
||||
{
|
||||
[headers setObject: @"HIGHEST" forKey: @"priority"];
|
||||
}
|
||||
else if ([priority isEqualToString: @"2 (High)"])
|
||||
{
|
||||
[headers setObject: @"HIGH" forKey: @"priority"];
|
||||
}
|
||||
else if ([priority isEqualToString: @"4 (Low)"])
|
||||
{
|
||||
[headers setObject: @"LOW" forKey: @"priority"];
|
||||
}
|
||||
else if ([priority isEqualToString: @"5 (Lowest)"])
|
||||
{
|
||||
[headers setObject: @"LOWEST" forKey: @"priority"];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// newHeaders come from Web form; convert priority to MIME header representation
|
||||
priority = [newHeaders objectForKey: @"priority"];
|
||||
if ([priority intValue] == 1)
|
||||
{
|
||||
[headers setObject: @"1 (Highest)" forKey: @"X-Priority"];
|
||||
}
|
||||
else if ([priority intValue] == 2)
|
||||
{
|
||||
[headers setObject: @"2 (High)" forKey: @"X-Priority"];
|
||||
}
|
||||
else if ([priority intValue] == 4)
|
||||
{
|
||||
[headers setObject: @"4 (Low)" forKey: @"X-Priority"];
|
||||
}
|
||||
else if ([priority intValue] == 5)
|
||||
{
|
||||
[headers setObject: @"5 (Lowest)" forKey: @"X-Priority"];
|
||||
}
|
||||
else
|
||||
{
|
||||
[headers removeObjectForKey: @"X-Priority"];
|
||||
}
|
||||
if (priority)
|
||||
{
|
||||
[headers setObject: priority forKey: @"priority"];
|
||||
}
|
||||
}
|
||||
|
||||
replyTo = [headers objectForKey: @"replyTo"];
|
||||
if ([replyTo length] > 0)
|
||||
{
|
||||
[headers setObject: replyTo forKey: @"reply-to"];
|
||||
}
|
||||
[headers removeObjectForKey: @"replyTo"];
|
||||
|
||||
receipt = [newHeaders objectForKey: @"Disposition-Notification-To"];
|
||||
if ([receipt length] > 0)
|
||||
{
|
||||
[headers setObject: @"true" forKey: @"receipt"];
|
||||
[headers setObject: receipt forKey: @"Disposition-Notification-To"];
|
||||
}
|
||||
else
|
||||
{
|
||||
receipt = [newHeaders objectForKey: @"receipt"];
|
||||
if ([receipt boolValue])
|
||||
{
|
||||
[headers setObject: receipt forKey: @"receipt"];
|
||||
pureSender = [[newHeaders objectForKey: @"from"] pureEMailAddress];
|
||||
if (pureSender)
|
||||
{
|
||||
[headers setObject: pureSender forKey: @"Disposition-Notification-To"];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
[headers removeObjectForKey: @"receipt"];
|
||||
[headers removeObjectForKey: @"Disposition-Notification-To"];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (NSDictionary *) headers
|
||||
{
|
||||
return headers;
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
- (NSArray *) allRecipients
|
||||
{
|
||||
NSMutableArray *allRecipients;
|
||||
NSArray *recipients;
|
||||
NSString *fieldNames[] = {@"to", @"cc", @"bcc"};
|
||||
unsigned int count;
|
||||
|
||||
allRecipients = [NSMutableArray arrayWithCapacity: 16];
|
||||
|
||||
for (count = 0; count < (sizeof(fieldNames) / sizeof(NSString)); count++)
|
||||
{
|
||||
recipients = [headers objectForKey: fieldNames[count]];
|
||||
if ([recipients count] > 0)
|
||||
[allRecipients addObjectsFromArray: recipients];
|
||||
}
|
||||
|
||||
return allRecipients;
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
- (NSArray *) allBareRecipients
|
||||
{
|
||||
NSMutableArray *bareRecipients;
|
||||
NSEnumerator *allRecipients;
|
||||
NSString *recipient;
|
||||
|
||||
bareRecipients = [NSMutableArray array];
|
||||
|
||||
allRecipients = [[self allRecipients] objectEnumerator];
|
||||
while ((recipient = [allRecipients nextObject]))
|
||||
[bareRecipients addObject: [recipient pureEMailAddress]];
|
||||
|
||||
return bareRecipients;
|
||||
}
|
||||
|
||||
@end /* SOGoMailBaseObject */
|
||||
|
||||
@@ -57,7 +57,6 @@ extern NSArray *SOGoMailCoreInfoKeys;
|
||||
{
|
||||
id coreInfos;
|
||||
id headerPart;
|
||||
NSDictionary *headers;
|
||||
}
|
||||
|
||||
/* message */
|
||||
|
||||
@@ -98,7 +98,6 @@ static BOOL debugSoParts = NO;
|
||||
{
|
||||
if ((self = [super init]))
|
||||
{
|
||||
headers = nil;
|
||||
headerPart = nil;
|
||||
coreInfos = nil;
|
||||
}
|
||||
@@ -108,7 +107,6 @@ static BOOL debugSoParts = NO;
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[headers release];
|
||||
[headerPart release];
|
||||
[coreInfos release];
|
||||
[super dealloc];
|
||||
|
||||
Reference in New Issue
Block a user