From 54eedb3363ec39ead94d3d597652f735abdb1782 Mon Sep 17 00:00:00 2001 From: Ludovic Marcotte Date: Thu, 9 Feb 2017 08:56:02 -0500 Subject: [PATCH] (fix) moved bcc handling code to the generic mail sending method --- SoObjects/Mailer/SOGoDraftObject.m | 146 +--------------------------- SoObjects/SOGo/SOGoMailer.m | 147 ++++++++++++++++++++++++++++- 2 files changed, 146 insertions(+), 147 deletions(-) diff --git a/SoObjects/Mailer/SOGoDraftObject.m b/SoObjects/Mailer/SOGoDraftObject.m index da0bf29dc..70119ff47 100644 --- a/SoObjects/Mailer/SOGoDraftObject.m +++ b/SoObjects/Mailer/SOGoDraftObject.m @@ -88,111 +88,6 @@ static NSString *headerKeys[] = {@"subject", @"to", @"cc", @"bcc", @end -// -// Useful extension that comes from Pantomime which is also -// released under the LGPL. We should eventually merge -// this with the same category found in SOPE's NGSmtpClient.m -// or simply drop sope-mime in favor of Pantomime -// -@interface NSMutableData (DataCleanupExtension) - -- (unichar) characterAtIndex: (int) theIndex; -- (NSRange) rangeOfCString: (const char *) theCString; -- (NSRange) rangeOfCString: (const char *) theCString - options: (unsigned int) theOptions - range: (NSRange) theRange; -@end - -@implementation NSMutableData (DataCleanupExtension) - -- (unichar) characterAtIndex: (int) theIndex -{ - const char *bytes; - int i, len; - - len = [self length]; - - if (len == 0 || theIndex >= len) - { - [[NSException exceptionWithName: NSRangeException - reason: @"Index out of range." - userInfo: nil] raise]; - - return (unichar)0; - } - - bytes = [self bytes]; - - for (i = 0; i < theIndex; i++) - { - bytes++; - } - - return (unichar)*bytes; -} - -- (NSRange) rangeOfCString: (const char *) theCString -{ - return [self rangeOfCString: theCString - options: 0 - range: NSMakeRange(0,[self length])]; -} - --(NSRange) rangeOfCString: (const char *) theCString - options: (unsigned int) theOptions - range: (NSRange) theRange -{ - const char *b, *bytes; - int i, len, slen; - - if (!theCString) - { - return NSMakeRange(NSNotFound,0); - } - - bytes = [self bytes]; - len = [self length]; - slen = strlen(theCString); - - b = bytes; - - if (len > theRange.location + theRange.length) - { - len = theRange.location + theRange.length; - } - - if (theOptions == NSCaseInsensitiveSearch) - { - i = theRange.location; - b += i; - - for (; i <= len-slen; i++, b++) - { - if (!strncasecmp(theCString,b,slen)) - { - return NSMakeRange(i,slen); - } - } - } - else - { - i = theRange.location; - b += i; - - for (; i <= len-slen; i++, b++) - { - if (!memcmp(theCString,b,slen)) - { - return NSMakeRange(i,slen); - } - } - } - - return NSMakeRange(NSNotFound,0); -} - -@end - // // // @@ -1857,59 +1752,20 @@ static NSString *userAgent = nil; // - (NSException *) sendMailAndCopyToSent: (BOOL) copyToSent { - NSMutableData *cleaned_message; SOGoMailFolder *sentFolder; SOGoDomainDefaults *dd; NSURL *sourceIMAP4URL; NSException *error; NSData *message; - NSRange r1; - - unsigned int limit; // We strip the BCC fields prior sending any mails NGMimeMessageGenerator *generator; generator = [[[NGMimeMessageGenerator alloc] init] autorelease]; message = [generator generateMimeFromPart: [self mimeMessage]]; - - // - // We now look for the Bcc: header. If it is present, we remove it. - // Some servers, like qmail, do not remove it automatically. - // -#warning FIXME - we should fix the case issue when we switch to Pantomime - cleaned_message = [NSMutableData dataWithData: message]; - - // We search only in the headers so we start at 0 until - // we find \r\n\r\n, which is the headers delimiter - r1 = [cleaned_message rangeOfCString: "\r\n\r\n"]; - limit = r1.location-1; - r1 = [cleaned_message rangeOfCString: "\r\nbcc: " - options: 0 - range: NSMakeRange(0,limit)]; - - if (r1.location != NSNotFound) - { - // We search for the first \r\n AFTER the Bcc: header and - // replace the whole thing with \r\n. - unsigned int i; - - for (i = r1.location+7; i < limit; i++) - { - if ([cleaned_message characterAtIndex: i] == '\r' && - (i+1 < limit && [cleaned_message characterAtIndex: i+1] == '\n') && - (i+2 < limit && !isspace([cleaned_message characterAtIndex: i+2]))) - break; - } - - [cleaned_message replaceBytesInRange: NSMakeRange(r1.location, i-r1.location) - withBytes: NULL - length: 0]; - } - dd = [[context activeUser] domainDefaults]; error = [[SOGoMailer mailerWithDomainDefaults: dd] - sendMailData: cleaned_message + sendMailData: message toRecipients: [self allBareRecipients] sender: [self sender] withAuthenticator: [self authenticatorInContext: context] diff --git a/SoObjects/SOGo/SOGoMailer.m b/SoObjects/SOGo/SOGoMailer.m index a1563c0e0..de9ef7008 100644 --- a/SoObjects/SOGo/SOGoMailer.m +++ b/SoObjects/SOGo/SOGoMailer.m @@ -35,6 +35,111 @@ #import "SOGoMailer.h" +// +// Useful extension that comes from Pantomime which is also +// released under the LGPL. We should eventually merge +// this with the same category found in SOPE's NGSmtpClient.m +// or simply drop sope-mime in favor of Pantomime +// +@interface NSMutableData (DataCleanupExtension) + +- (unichar) characterAtIndex: (int) theIndex; +- (NSRange) rangeOfCString: (const char *) theCString; +- (NSRange) rangeOfCString: (const char *) theCString + options: (unsigned int) theOptions + range: (NSRange) theRange; +@end + +@implementation NSMutableData (DataCleanupExtension) + +- (unichar) characterAtIndex: (int) theIndex +{ + const char *bytes; + int i, len; + + len = [self length]; + + if (len == 0 || theIndex >= len) + { + [[NSException exceptionWithName: NSRangeException + reason: @"Index out of range." + userInfo: nil] raise]; + + return (unichar)0; + } + + bytes = [self bytes]; + + for (i = 0; i < theIndex; i++) + { + bytes++; + } + + return (unichar)*bytes; +} + +- (NSRange) rangeOfCString: (const char *) theCString +{ + return [self rangeOfCString: theCString + options: 0 + range: NSMakeRange(0,[self length])]; +} + +-(NSRange) rangeOfCString: (const char *) theCString + options: (unsigned int) theOptions + range: (NSRange) theRange +{ + const char *b, *bytes; + int i, len, slen; + + if (!theCString) + { + return NSMakeRange(NSNotFound,0); + } + + bytes = [self bytes]; + len = [self length]; + slen = strlen(theCString); + + b = bytes; + + if (len > theRange.location + theRange.length) + { + len = theRange.location + theRange.length; + } + + if (theOptions == NSCaseInsensitiveSearch) + { + i = theRange.location; + b += i; + + for (; i <= len-slen; i++, b++) + { + if (!strncasecmp(theCString,b,slen)) + { + return NSMakeRange(i,slen); + } + } + } + else + { + i = theRange.location; + b += i; + + for (; i <= len-slen; i++, b++) + { + if (!memcmp(theCString,b,slen)) + { + return NSMakeRange(i,slen); + } + } + } + + return NSMakeRange(NSNotFound,0); +} + +@end + @implementation SOGoMailer + (SOGoMailer *) mailerWithDomainDefaults: (SOGoDomainDefaults *) dd @@ -236,12 +341,50 @@ reason: @"cannot send message: no sender set"]; else { + NSMutableData *cleaned_message; + NSRange r1; + unsigned int limit; + + // + // We now look for the Bcc: header. If it is present, we remove it. + // Some servers, like qmail, do not remove it automatically. + // +#warning FIXME - we should fix the case issue when we switch to Pantomime + cleaned_message = [NSMutableData dataWithData: data]; + + // We search only in the headers so we start at 0 until + // we find \r\n\r\n, which is the headers delimiter + r1 = [cleaned_message rangeOfCString: "\r\n\r\n"]; + limit = r1.location-1; + r1 = [cleaned_message rangeOfCString: "\r\nBcc: " + options: 0 + range: NSMakeRange(0,limit)]; + + if (r1.location != NSNotFound) + { + // We search for the first \r\n AFTER the Bcc: header and + // replace the whole thing with \r\n. + unsigned int i; + + for (i = r1.location+7; i < limit; i++) + { + if ([cleaned_message characterAtIndex: i] == '\r' && + (i+1 < limit && [cleaned_message characterAtIndex: i+1] == '\n') && + (i+2 < limit && !isspace([cleaned_message characterAtIndex: i+2]))) + break; + } + + [cleaned_message replaceBytesInRange: NSMakeRange(r1.location, i-r1.location) + withBytes: NULL + length: 0]; + } + if ([mailingMechanism isEqualToString: @"sendmail"]) - result = [self _sendmailSendData: data + result = [self _sendmailSendData: cleaned_message toRecipients: recipients sender: [sender pureEMailAddress]]; else - result = [self _smtpSendData: data + result = [self _smtpSendData: cleaned_message toRecipients: recipients sender: [sender pureEMailAddress] withAuthenticator: authenticator