From faa5d83cf64b87caac5c963edeb1f51d09af99c8 Mon Sep 17 00:00:00 2001 From: Ludovic Marcotte Date: Wed, 25 Nov 2015 15:08:24 -0500 Subject: [PATCH] (fix) EAS fix on qp-encoded subjects (#3390) --- ActiveSync/SOGoActiveSyncDispatcher.m | 21 ++++++++++++++++++--- NEWS | 1 + 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/ActiveSync/SOGoActiveSyncDispatcher.m b/ActiveSync/SOGoActiveSyncDispatcher.m index 7f2f11657..eae24fcf3 100644 --- a/ActiveSync/SOGoActiveSyncDispatcher.m +++ b/ActiveSync/SOGoActiveSyncDispatcher.m @@ -2573,7 +2573,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NSString *fullName, *email; const char *bytes; - int i, len; + int i, e, len; BOOL found_header; // We get the mail's data @@ -2622,6 +2622,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. { found_header = YES; i = i + 2; // \r\n + bytes = bytes + 2; break; } @@ -2629,12 +2630,26 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. i++; } + // We search for the first \r\n AFTER the From: header to get the length of the string to replace. + e = i; + while (e < len) + { + if ((*bytes == '\r') && (*(bytes+1) == '\n')) + { + e = e + 2; + break; + } + + bytes++; + e++; + } + // Update/Add the From header in the MIMEBody of the SendMail request. // Any other way to modify the mail body would break s/mime emails. if (found_header) { // Change the From header - [data replaceBytesInRange: NSMakeRange(i, [[message headerForKey: @"from"] length]+8) // start of the From header found - length of the parsed from-header-value + 8 (From:+\r\n+1) + [data replaceBytesInRange: NSMakeRange(i, (NSUInteger)(e-i)) withBytes: [new_from_header bytes] length: [new_from_header length]]; } @@ -3160,7 +3175,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. nil]]; #endif - s = [NSString stringWithFormat: @"Date: %@\n%@", value, [theRequest contentAsString]]; + s = [NSString stringWithFormat: @"Date: %@\r\n%@", value, [theRequest contentAsString]]; } else { diff --git a/NEWS b/NEWS index 45bd8d075..48b6f58e3 100644 --- a/NEWS +++ b/NEWS @@ -11,6 +11,7 @@ Enhancements Bug fixes - JavaScript exception when printing events from calendars with no assigned color (#3203) - EAS fix for wrong charset being used (#3392) + - EAS fix on qp-encoded subjects (#3390) 2.3.3a (2015-11-18) -------------------