diff --git a/ActiveSync/SOGoActiveSyncDispatcher.m b/ActiveSync/SOGoActiveSyncDispatcher.m
index 47c0453f5..c9ee242fa 100644
--- a/ActiveSync/SOGoActiveSyncDispatcher.m
+++ b/ActiveSync/SOGoActiveSyncDispatcher.m
@@ -2082,19 +2082,37 @@ void handle_terminate(int signum)
if (![allCollections count])
{
- // We received an empty Ping request. Return status '3' to ask client to resend the request with complete body.
- s = [NSMutableString string];
- [s appendString: @""];
- [s appendString: @""];
- [s appendString: @""];
- [s appendString: @"3"];
- [s appendString: @""];
+ heartbeatInterval = [[[o properties] objectForKey: @"PingHeartbeatInterval"] intValue];
- d = [[s dataUsingEncoding: NSUTF8StringEncoding] xml2wbxml];
+ if (debugOn)
+ [self logWithFormat: @"EAS - Empty Ping request - using cached HeatbeatInterval (%d)", heartbeatInterval];
- [theResponse setContent: d];
+ if (heartbeatInterval > defaultInterval || heartbeatInterval == 0)
+ {
+ heartbeatInterval = defaultInterval;
+ status = 5;
+ }
- return;
+ allFoldersID = [[o properties] objectForKey: @"PingCachedFolders"];
+ if (![allFoldersID count])
+ {
+ // We received an empty Ping request. Return status '3' to ask client to resend the request with complete body.
+ s = [NSMutableString string];
+ [s appendString: @""];
+ [s appendString: @""];
+ [s appendString: @""];
+ [s appendString: @"3"];
+ [s appendString: @""];
+
+ d = [[s dataUsingEncoding: NSUTF8StringEncoding] xml2wbxml];
+
+ [theResponse setContent: d];
+
+ return;
+ }
+
+ if (debugOn)
+ [self logWithFormat: @"EAS - Empty Ping request - using cached folders %@", allFoldersID];
}
else
{
@@ -2104,6 +2122,16 @@ void handle_terminate(int signum)
collectionId = [[(id) [aCollection getElementsByTagName: @"Id"] lastObject] textValue];
[allFoldersID addObject: collectionId];
}
+
+ if (![allFoldersID isEqualToArray: [[o properties] objectForKey: @"PingCachedFolders"]])
+ {
+ if (debugOn)
+ [self logWithFormat: @"EAS - Ping - Save folderlist to cache (HeartbeatInterval: %d) (%@)", heartbeatInterval, allFoldersID];
+
+ [[o properties] setObject: [NSNumber numberWithInteger: heartbeatInterval] forKey: @"PingHeartbeatInterval"];
+ [[o properties] setObject: allFoldersID forKey: @"PingCachedFolders"];
+ [o save];
+ }
}
foldersWithChanges = [NSMutableArray array];