diff --git a/ActiveSync/NSString+ActiveSync.h b/ActiveSync/NSString+ActiveSync.h
index 963b3d00a..8a59b6764 100644
--- a/ActiveSync/NSString+ActiveSync.h
+++ b/ActiveSync/NSString+ActiveSync.h
@@ -53,6 +53,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- (NSString *) itemid;
- (BOOL) acceptsMultiPart;
- (NSData *) convertHexStringToBytes;
+- (NSString *) protocolVersion;
@end
diff --git a/ActiveSync/NSString+ActiveSync.m b/ActiveSync/NSString+ActiveSync.m
index 223f34b77..1cfdd9c7b 100644
--- a/ActiveSync/NSString+ActiveSync.m
+++ b/ActiveSync/NSString+ActiveSync.m
@@ -138,6 +138,27 @@ static NSArray *easCommandParameters = nil;
return o;
}
+- (NSString *) protocolVersion
+{
+ NSMutableArray *components;
+
+ components = [NSMutableArray arrayWithArray: [[[self componentsSeparatedByString: @"?"] lastObject] componentsSeparatedByString: @"&"]];
+
+ // We handle BASE64 encoded queryStrings. See http://msdn.microsoft.com/en-us/library/ee160227%28v=exchg.80%29.aspx for details.
+ if ([components count] == 1)
+ {
+ NSData *queryString;
+ const char* qs_bytes;
+
+ queryString = [[components objectAtIndex: 0] dataByDecodingBase64];
+ qs_bytes = (const char*)[queryString bytes];
+
+ return [NSString stringWithFormat:@"%.1f", (float)((uint8_t)qs_bytes[0]/10)];
+ }
+
+ return nil;
+}
+
- (NSString *) _valueForParameter: (NSString *) theParameter
{
NSMutableArray *components;
diff --git a/ActiveSync/SOGoActiveSyncDispatcher.m b/ActiveSync/SOGoActiveSyncDispatcher.m
index 44671edd9..0010ce7da 100644
--- a/ActiveSync/SOGoActiveSyncDispatcher.m
+++ b/ActiveSync/SOGoActiveSyncDispatcher.m
@@ -3345,6 +3345,12 @@ void handle_eas_terminate(int signum)
[context setObject: [[theRequest uri] deviceType] forKey: @"DeviceType"];
[context setObject: [[theRequest uri] attachmentName] forKey: @"AttachmentName"];
+ // Save ASProtocolVersion to context
+ if ([[context request] headerForKey: @"MS-ASProtocolVersion"])
+ [context setObject: [[context request] headerForKey: @"MS-ASProtocolVersion"] forKey: @"ASProtocolVersion"];
+ else
+ [context setObject: [[theRequest uri] protocolVersion] forKey: @"ASProtocolVersion"];
+
cmdName = [[theRequest uri] command];
// We make sure our cache table exists
diff --git a/ActiveSync/SOGoMailObject+ActiveSync.m b/ActiveSync/SOGoMailObject+ActiveSync.m
index 5911e43b8..71575ae60 100644
--- a/ActiveSync/SOGoMailObject+ActiveSync.m
+++ b/ActiveSync/SOGoMailObject+ActiveSync.m
@@ -1003,7 +1003,7 @@ struct GlobalObjectId {
[s appendFormat: @"%@", [globalObjId activeSyncRepresentationInContext: context]];
// We set the right message type - we must set AS version to 14.1 for this
- if ([[[context request] headerForKey: @"MS-ASProtocolVersion"] isEqualToString: @"14.1"])
+ if ([[context valueForKey: @"ASProtocolVersion"] floatValue] >= 14.1)
[s appendFormat: @"%d", 1];
[s appendString: @""];
@@ -1169,7 +1169,7 @@ struct GlobalObjectId {
truncated = 0;
}
- if ([[[context request] headerForKey: @"MS-ASProtocolVersion"] isEqualToString: @"2.5"])
+ if ([[context valueForKey: @"ASProtocolVersion"] isEqualToString: @"2.5"])
{
[s appendFormat: @"
%@", content];
[s appendFormat: @"%d", truncated];
@@ -1204,7 +1204,7 @@ struct GlobalObjectId {
{
int i;
- if ([[[context request] headerForKey: @"MS-ASProtocolVersion"] isEqualToString: @"2.5"])
+ if ([[context valueForKey: @"ASProtocolVersion"] isEqualToString: @"2.5"])
[s appendString: @""];
else
[s appendString: @""];
@@ -1219,12 +1219,12 @@ struct GlobalObjectId {
// FileReference must be a unique identifier across the whole store. We use the following structure:
// mail//
// mail/INBOX/2
- if ([[[context request] headerForKey: @"MS-ASProtocolVersion"] isEqualToString: @"2.5"])
+ if ([[context valueForKey: @"ASProtocolVersion"] isEqualToString: @"2.5"])
[s appendFormat: @"mail/%@/%@/%@", [[[self container] relativeImap4Name] stringByEscapingURL], [self nameInContainer], [value objectForKey: @"path"]];
else
[s appendFormat: @"mail/%@/%@/%@", [[[self container] relativeImap4Name] stringByEscapingURL], [self nameInContainer], [value objectForKey: @"path"]];
- if ([[[context request] headerForKey: @"MS-ASProtocolVersion"] isEqualToString: @"2.5"])
+ if ([[context valueForKey: @"ASProtocolVersion"] isEqualToString: @"2.5"])
{
[s appendFormat: @"%d", 1];
[s appendFormat: @"%d", [[value objectForKey: @"size"] intValue]];
@@ -1267,8 +1267,7 @@ struct GlobalObjectId {
[s appendFormat: @""];
}
- if ([[[context request] headerForKey: @"MS-ASProtocolVersion"] isEqualToString: @"14.0"] ||
- [[[context request] headerForKey: @"MS-ASProtocolVersion"] isEqualToString: @"14.1"])
+ if ([[context valueForKey: @"ASProtocolVersion"] floatValue] >= 14.0)
{
id value;
NSString *reference;
diff --git a/ActiveSync/iCalEvent+ActiveSync.m b/ActiveSync/iCalEvent+ActiveSync.m
index 8568877ff..8a34f0e18 100644
--- a/ActiveSync/iCalEvent+ActiveSync.m
+++ b/ActiveSync/iCalEvent+ActiveSync.m
@@ -251,7 +251,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// otherwise it'll prevent WP8 phones from sync'ing. See #3028 for details.
o = [o activeSyncRepresentationInContext: context];
- if ([[[context request] headerForKey: @"MS-ASProtocolVersion"] isEqualToString: @"2.5"])
+ if ([[context valueForKey: @"ASProtocolVersion"] isEqualToString: @"2.5"])
{
[s appendFormat: @"%@", o];
[s appendString: @"0"];
@@ -494,7 +494,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
}
// FIXME: merge with iCalToDo
- if ([[[context request] headerForKey: @"MS-ASProtocolVersion"] isEqualToString: @"2.5"])
+ if ([[context valueForKey: @"ASProtocolVersion"] isEqualToString: @"2.5"])
{
if ((o = [theValues objectForKey: @"Body"]))
[self setComment: o];
diff --git a/ActiveSync/iCalToDo+ActiveSync.m b/ActiveSync/iCalToDo+ActiveSync.m
index 94e0f9756..6aa7e0da5 100644
--- a/ActiveSync/iCalToDo+ActiveSync.m
+++ b/ActiveSync/iCalToDo+ActiveSync.m
@@ -131,7 +131,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// otherwise it'll prevent WP8 phones from sync'ing. See #3028 for details.
o = [o activeSyncRepresentationInContext: context];
- if ([[[context request] headerForKey: @"MS-ASProtocolVersion"] isEqualToString: @"2.5"])
+ if ([[context valueForKey: @"ASProtocolVersion"] isEqualToString: @"2.5"])
{
[s appendFormat: @"%@", o];
[s appendString: @"0"];
@@ -165,7 +165,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
[self setSummary: o];
// FIXME: merge with iCalEvent
- if ([[[context request] headerForKey: @"MS-ASProtocolVersion"] isEqualToString: @"2.5"])
+ if ([[context valueForKey: @"ASProtocolVersion"] isEqualToString: @"2.5"])
{
if ((o = [theValues objectForKey: @"Body"]))
[self setComment: o];