Skip to content

Commit

Permalink
(fix) fixed bogus headers generation when stripping folded bcc header…
Browse files Browse the repository at this point in the history
…s (fixes #3664)
  • Loading branch information
extrafu committed May 10, 2016
1 parent f425d61 commit d601608
Showing 1 changed file with 48 additions and 10 deletions.
58 changes: 48 additions & 10 deletions SoObjects/Mailer/SOGoDraftObject.m
Expand Up @@ -103,6 +103,7 @@ - (NSString *) imap4FolderNameForURL: (NSURL *) url;
//
@interface NSMutableData (DataCleanupExtension)

- (unichar) characterAtIndex: (int) theIndex;
- (NSRange) rangeOfCString: (const char *) theCString;
- (NSRange) rangeOfCString: (const char *) theCString
options: (unsigned int) theOptions
Expand All @@ -111,6 +112,32 @@ - (NSRange) rangeOfCString: (const char *) theCString

@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
Expand Down Expand Up @@ -1874,9 +1901,9 @@ - (NSException *) sendMailAndCopyToSent: (BOOL) copyToSent
NSURL *sourceIMAP4URL;
NSException *error;
NSData *message;
NSRange r1, r2;
/* send mail */
NSRange r1;

unsigned int limit;

// We strip the BCC fields prior sending any mails
NGMimeMessageGenerator *generator;
Expand All @@ -1890,21 +1917,32 @@ - (NSException *) sendMailAndCopyToSent: (BOOL) copyToSent
//
#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,r1.location-1)];
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.
r2 = [cleaned_message rangeOfCString: "\r\n"
options: 0
range: NSMakeRange(NSMaxRange(r1)+1,[cleaned_message length]-NSMaxRange(r1)-1)];
[cleaned_message replaceBytesInRange: NSMakeRange(r1.location, NSMaxRange(r2)-r1.location)
withBytes: "\r\n"
length: 2];
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];
Expand Down

0 comments on commit d601608

Please sign in to comment.