(fix) check if EAS identity is ok and use it (fixes #3698)
parent
fa91a07cb7
commit
030bdb4bc7
|
@ -2694,6 +2694,38 @@ void handle_eas_terminate(int signum)
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (BOOL) _isEMailValid: (NSString *) email
|
||||||
|
{
|
||||||
|
NSArray *identities;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
identities = [[context activeUser] allIdentities];
|
||||||
|
|
||||||
|
for (i = 0; i < [identities count]; i++)
|
||||||
|
{
|
||||||
|
if ([email isEqualToString: [[identities objectAtIndex: i] objectForKey: @"email"]])
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSString *) _fullNameForEMail: (NSString *) email
|
||||||
|
{
|
||||||
|
NSArray *identities;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
identities = [[context activeUser] allIdentities];
|
||||||
|
|
||||||
|
for (i = 0; i < [identities count]; i++)
|
||||||
|
{
|
||||||
|
if ([email isEqualToString: [[identities objectAtIndex: i] objectForKey: @"email"]])
|
||||||
|
return [[identities objectAtIndex: i] objectForKey: @"fullName"];
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
|
@ -2707,10 +2739,12 @@ void handle_eas_terminate(int signum)
|
||||||
NSData *new_from_header;
|
NSData *new_from_header;
|
||||||
NSDictionary *identity;
|
NSDictionary *identity;
|
||||||
NSString *fullName, *email;
|
NSString *fullName, *email;
|
||||||
|
NSArray *from;
|
||||||
|
|
||||||
const char *bytes;
|
const char *bytes;
|
||||||
int i, e, len;
|
int i, e, len;
|
||||||
BOOL found_header;
|
BOOL found_header;
|
||||||
|
email = nil;
|
||||||
|
|
||||||
// We get the mail's data
|
// We get the mail's data
|
||||||
data = [NSMutableData dataWithData: [[[[(id)[theDocumentElement getElementsByTagName: @"MIME"] lastObject] textValue] stringByDecodingBase64] dataUsingEncoding: NSUTF8StringEncoding]];
|
data = [NSMutableData dataWithData: [[[[(id)[theDocumentElement getElementsByTagName: @"MIME"] lastObject] textValue] stringByDecodingBase64] dataUsingEncoding: NSUTF8StringEncoding]];
|
||||||
|
@ -2720,81 +2754,97 @@ void handle_eas_terminate(int signum)
|
||||||
message = [parser parsePartFromData: data];
|
message = [parser parsePartFromData: data];
|
||||||
RELEASE(parser);
|
RELEASE(parser);
|
||||||
|
|
||||||
identity = [[context activeUser] primaryIdentity];
|
from = [message headersForKey: @"from"];
|
||||||
|
|
||||||
fullName = [identity objectForKey: @"fullName"];
|
if (![from count] || ![self _isEMailValid: [[from objectAtIndex: 0] pureEMailAddress]] ||
|
||||||
email = [identity objectForKey: @"email"];
|
[[[from objectAtIndex: 0] pureEMailAddress] isEqualToString: [from objectAtIndex: 0]] ||
|
||||||
|
[[NSString stringWithFormat: @"<%@>", [[from objectAtIndex: 0] pureEMailAddress]] isEqualToString: [from objectAtIndex: 0]])
|
||||||
if ([fullName length])
|
|
||||||
new_from_header = [[NSString stringWithFormat: @"From: %@ <%@>\r\n", [fullName asQPSubjectString: @"utf-8"], email] dataUsingEncoding:NSUTF8StringEncoding];
|
|
||||||
else
|
|
||||||
new_from_header = [[NSString stringWithFormat: @"From: %@\r\n", email] dataUsingEncoding:NSUTF8StringEncoding];
|
|
||||||
|
|
||||||
bytes = [data bytes];
|
|
||||||
len = [data length];
|
|
||||||
i = 0;
|
|
||||||
found_header = NO;
|
|
||||||
|
|
||||||
// Search for the from-header
|
|
||||||
while (i < len)
|
|
||||||
{
|
{
|
||||||
if (i == 0 &&
|
if ([from count] && [self _isEMailValid: [[from objectAtIndex: 0] pureEMailAddress]])
|
||||||
(*bytes == 'f' || *bytes == 'F') &&
|
|
||||||
(*(bytes+1) == 'r' || *(bytes+1) == 'R') &&
|
|
||||||
(*(bytes+2) == 'o' || *(bytes+2) == 'O') &&
|
|
||||||
(*(bytes+3) == 'm' || *(bytes+3) == 'M') &&
|
|
||||||
(*(bytes+4) == ':'))
|
|
||||||
{
|
{
|
||||||
found_header = YES;
|
// We have a valid email address, lets fill in the fullname.
|
||||||
break;
|
email = [[from objectAtIndex: 0] pureEMailAddress];
|
||||||
|
fullName = [self _fullNameForEMail: email];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Fallback to primary identity.
|
||||||
|
identity = [[context activeUser] primaryIdentity];
|
||||||
|
fullName = [identity objectForKey: @"fullName"];
|
||||||
|
email = [identity objectForKey: @"email"];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (((*bytes == '\r') && (*(bytes+1) == '\n')) &&
|
if ([fullName length])
|
||||||
(*(bytes+2) == 'f' || *(bytes+2) == 'F') &&
|
new_from_header = [[NSString stringWithFormat: @"From: %@ <%@>\r\n", [fullName asQPSubjectString: @"utf-8"], email] dataUsingEncoding: NSUTF8StringEncoding];
|
||||||
(*(bytes+3) == 'r' || *(bytes+3) == 'R') &&
|
else
|
||||||
(*(bytes+4) == 'o' || *(bytes+4) == 'O') &&
|
new_from_header = [[NSString stringWithFormat: @"From: %@\r\n", email] dataUsingEncoding: NSUTF8StringEncoding];
|
||||||
(*(bytes+5) == 'm' || *(bytes+5) == 'M') &&
|
|
||||||
(*(bytes+6) == ':'))
|
bytes = [data bytes];
|
||||||
|
len = [data length];
|
||||||
|
i = 0;
|
||||||
|
found_header = NO;
|
||||||
|
|
||||||
|
// Search for the from-header
|
||||||
|
while (i < len)
|
||||||
{
|
{
|
||||||
found_header = YES;
|
if (i == 0 &&
|
||||||
i = i + 2; // \r\n
|
(*bytes == 'f' || *bytes == 'F') &&
|
||||||
bytes = bytes + 2;
|
(*(bytes+1) == 'r' || *(bytes+1) == 'R') &&
|
||||||
break;
|
(*(bytes+2) == 'o' || *(bytes+2) == 'O') &&
|
||||||
|
(*(bytes+3) == 'm' || *(bytes+3) == 'M') &&
|
||||||
|
(*(bytes+4) == ':'))
|
||||||
|
{
|
||||||
|
found_header = YES;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (((*bytes == '\r') && (*(bytes+1) == '\n')) &&
|
||||||
|
(*(bytes+2) == 'f' || *(bytes+2) == 'F') &&
|
||||||
|
(*(bytes+3) == 'r' || *(bytes+3) == 'R') &&
|
||||||
|
(*(bytes+4) == 'o' || *(bytes+4) == 'O') &&
|
||||||
|
(*(bytes+5) == 'm' || *(bytes+5) == 'M') &&
|
||||||
|
(*(bytes+6) == ':'))
|
||||||
|
{
|
||||||
|
found_header = YES;
|
||||||
|
i = i + 2; // \r\n
|
||||||
|
bytes = bytes + 2;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
bytes++;
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
bytes++;
|
// We search for the first \r\n AFTER the From: header to get the length of the string to replace.
|
||||||
i++;
|
e = i;
|
||||||
}
|
while (e < len)
|
||||||
|
{
|
||||||
|
if ((*bytes == '\r') && (*(bytes+1) == '\n'))
|
||||||
|
{
|
||||||
|
e = e + 2;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// We search for the first \r\n AFTER the From: header to get the length of the string to replace.
|
bytes++;
|
||||||
e = i;
|
e++;
|
||||||
while (e < len)
|
}
|
||||||
{
|
|
||||||
if ((*bytes == '\r') && (*(bytes+1) == '\n'))
|
|
||||||
{
|
|
||||||
e = e + 2;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
bytes++;
|
// Update/Add the From header in the MIMEBody of the SendMail request.
|
||||||
e++;
|
// Any other way to modify the mail body would break s/mime emails.
|
||||||
}
|
if (found_header)
|
||||||
|
{
|
||||||
// Update/Add the From header in the MIMEBody of the SendMail request.
|
// Change the From header
|
||||||
// Any other way to modify the mail body would break s/mime emails.
|
[data replaceBytesInRange: NSMakeRange(i, (NSUInteger)(e-i))
|
||||||
if (found_header)
|
withBytes: [new_from_header bytes]
|
||||||
{
|
length: [new_from_header length]];
|
||||||
// Change the From header
|
}
|
||||||
[data replaceBytesInRange: NSMakeRange(i, (NSUInteger)(e-i))
|
else
|
||||||
withBytes: [new_from_header bytes]
|
{
|
||||||
length: [new_from_header length]];
|
// Add a From header
|
||||||
}
|
[data replaceBytesInRange: NSMakeRange(0, 0)
|
||||||
else
|
withBytes: [new_from_header bytes]
|
||||||
{
|
length: [new_from_header length]];
|
||||||
// Add a From header
|
}
|
||||||
[data replaceBytesInRange: NSMakeRange(0, 0)
|
|
||||||
withBytes: [new_from_header bytes]
|
|
||||||
length: [new_from_header length]];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
error = [self _sendMail: data
|
error = [self _sendMail: data
|
||||||
|
@ -2933,7 +2983,7 @@ void handle_eas_terminate(int signum)
|
||||||
NSMutableArray *attachments, *references;
|
NSMutableArray *attachments, *references;
|
||||||
|
|
||||||
id body, bodyFromSmartForward, htmlPart, textPart;
|
id body, bodyFromSmartForward, htmlPart, textPart;
|
||||||
NSString *fullName, *email, *charset, *s;
|
NSString *fullName, *email, *charset, *s, *from;
|
||||||
NSDictionary *identity;
|
NSDictionary *identity;
|
||||||
|
|
||||||
int a;
|
int a;
|
||||||
|
@ -2959,14 +3009,32 @@ void handle_eas_terminate(int signum)
|
||||||
map = [NGHashMap hashMapWithDictionary: [messageFromSmartForward headers]];
|
map = [NGHashMap hashMapWithDictionary: [messageFromSmartForward headers]];
|
||||||
[map setObject: @"multipart/mixed" forKey: @"content-type"];
|
[map setObject: @"multipart/mixed" forKey: @"content-type"];
|
||||||
|
|
||||||
identity = [[context activeUser] primaryIdentity];
|
from = [map objectForKey: @"from"];
|
||||||
|
|
||||||
fullName = [identity objectForKey: @"fullName"];
|
if (![from length] || ![self _isEMailValid: [from pureEMailAddress]] ||
|
||||||
email = [identity objectForKey: @"email"];
|
[[from pureEMailAddress] isEqualToString: from] ||
|
||||||
if ([fullName length])
|
[[NSString stringWithFormat: @"<%@>", [from pureEMailAddress]] isEqualToString: from])
|
||||||
[map setObject: [NSString stringWithFormat: @"%@ <%@>", fullName, email] forKey: @"from"];
|
{
|
||||||
else
|
if ([from length] && [self _isEMailValid: [from pureEMailAddress]])
|
||||||
[map setObject: email forKey: @"from"];
|
{
|
||||||
|
// We have a valid email address, lets fill in the fullname.
|
||||||
|
email = [from pureEMailAddress];
|
||||||
|
fullName = [self _fullNameForEMail: email];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Fallback to primary identity.
|
||||||
|
identity = [[context activeUser] primaryIdentity];
|
||||||
|
|
||||||
|
fullName = [identity objectForKey: @"fullName"];
|
||||||
|
email = [identity objectForKey: @"email"];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ([fullName length])
|
||||||
|
[map setObject: [NSString stringWithFormat: @"%@ <%@>", fullName, email] forKey: @"from"];
|
||||||
|
else
|
||||||
|
[map setObject: email forKey: @"from"];
|
||||||
|
}
|
||||||
|
|
||||||
if ([mailObject messageId])
|
if ([mailObject messageId])
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue