From b1436884192d4e8e1ee8e04266df0b676c503f61 Mon Sep 17 00:00:00 2001 From: Ludovic Marcotte Date: Fri, 21 Mar 2014 13:55:59 -0400 Subject: [PATCH] Fix for bug #2669 --- ActiveSync/NSString+ActiveSync.m | 2 +- ActiveSync/SOGoActiveSyncDispatcher+Sync.m | 2 +- ActiveSync/SOGoActiveSyncDispatcher.m | 38 +++++++++++++++++++--- 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/ActiveSync/NSString+ActiveSync.m b/ActiveSync/NSString+ActiveSync.m index 1c7a8ba5b..b1fba0f4c 100644 --- a/ActiveSync/NSString+ActiveSync.m +++ b/ActiveSync/NSString+ActiveSync.m @@ -139,7 +139,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NSString *s; int i; - components = [[[self componentsSeparatedByString: @"/"] lastObject] componentsSeparatedByString: @"&"]; + components = [[[self componentsSeparatedByString: @"?"] lastObject] componentsSeparatedByString: @"&"]; for (i = 0; i < [components count]; i++) { diff --git a/ActiveSync/SOGoActiveSyncDispatcher+Sync.m b/ActiveSync/SOGoActiveSyncDispatcher+Sync.m index 54d827453..2a2382ffa 100644 --- a/ActiveSync/SOGoActiveSyncDispatcher+Sync.m +++ b/ActiveSync/SOGoActiveSyncDispatcher+Sync.m @@ -639,7 +639,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. [s appendString: @""]; mailObject = [theCollection lookupName: uid - inContext: context + inContext: context acquire: 0]; [s appendFormat: @"%@", uid]; diff --git a/ActiveSync/SOGoActiveSyncDispatcher.m b/ActiveSync/SOGoActiveSyncDispatcher.m index 1143219fd..67fdc7e37 100644 --- a/ActiveSync/SOGoActiveSyncDispatcher.m +++ b/ActiveSync/SOGoActiveSyncDispatcher.m @@ -1546,15 +1546,45 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. [context setObject: deviceId forKey: @"DeviceId"]; [context setObject: [[theRequest uri] deviceType] forKey: @"DeviceType"]; - d = [[theRequest content] wbxml2xml]; + cmdName = [[theRequest uri] command]; + + // + // If the MS-ASProtocolVersion header is set to "12.1", the body of the SendMail request is + // is a "message/rfc822" payload - otherwise, it's a WBXML blob. + // + if ([cmdName caseInsensitiveCompare: @"SendMail"] == NSOrderedSame && + [[theRequest headerForKey: @"content-type"] caseInsensitiveCompare: @"message/rfc822"] == NSOrderedSame) + { + NSString *s, *xml; + + if ([[theRequest contentAsString] rangeOfString: @"Date: " + options: NSCaseInsensitiveSearch].location == NSNotFound) + { + NSString *value; + + value = [[NSDate date] descriptionWithCalendarFormat: @"%a, %d %b %Y %H:%M:%S %z" timeZone: [NSTimeZone timeZoneWithName: @"GMT"] locale: nil]; + s = [NSString stringWithFormat: @"Date: %@\n%@", value, [theRequest contentAsString]]; + } + else + { + s = [theRequest contentAsString]; + } + + xml = [NSString stringWithFormat: @"%@", [s stringByEncodingBase64]]; + + d = [xml dataUsingEncoding: NSASCIIStringEncoding]; + } + else + { + d = [[theRequest content] wbxml2xml]; + } + documentElement = nil; if (!d) { // We check if it's a Ping command with no body. - // See http://msdn.microsoft.com/en-us/library/ee200913(v=exchg.80).aspx for details - cmdName = [[theRequest uri] command]; - + // See http://msdn.microsoft.com/en-us/library/ee200913(v=exchg.80).aspx for details if ([cmdName caseInsensitiveCompare: @"Ping"] != NSOrderedSame) return [NSException exceptionWithHTTPStatus: 500]; }