diff --git a/ActiveSync/NSDate+ActiveSync.h b/ActiveSync/NSDate+ActiveSync.h index 172552470..60c3e9a72 100644 --- a/ActiveSync/NSDate+ActiveSync.h +++ b/ActiveSync/NSDate+ActiveSync.h @@ -36,6 +36,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. @interface NSDate (ActiveSync) ++ (NSDate *) dateFromFilterType: (NSString *) theFilterType; - (NSString *) activeSyncRepresentation; @end diff --git a/ActiveSync/NSDate+ActiveSync.m b/ActiveSync/NSDate+ActiveSync.m index 58de5b6ab..9139ff86a 100644 --- a/ActiveSync/NSDate+ActiveSync.m +++ b/ActiveSync/NSDate+ActiveSync.m @@ -32,8 +32,58 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #import #import +#define ONE_DAY 86400 + @implementation NSDate (ActiveSync) +// +// See http://msdn.microsoft.com/en-us/library/gg709713(v=exchg.80).aspx for available types +// ++ (NSDate *) dateFromFilterType: (NSString *) theFilterType +{ + NSDate *d; + + d = [self alloc]; + + if (d) + { + int value; + + switch ([theFilterType intValue]) + { + case 1: + value = ONE_DAY; + break; + case 2: + value = 3 * ONE_DAY; + break; + case 3: + value = 7 * ONE_DAY; + break; + case 4: + value = 14 * ONE_DAY; + break; + case 5: + value = 30 * ONE_DAY; + break; + case 6: + value = 90 * ONE_DAY; + break; + case 7: + value = 180 * ONE_DAY; + break; + case 0: + case 8: + default: + return nil; + } + + return [d initWithTimeIntervalSinceNow: -value]; + } + + return d; +} + - (NSString *) activeSyncRepresentation { return [self descriptionWithCalendarFormat: @"%Y%m%dT%H%M%SZ" timeZone: [NSTimeZone timeZoneWithName: @"GMT"] locale: nil]; diff --git a/ActiveSync/SOGoActiveSyncDispatcher+Sync.m b/ActiveSync/SOGoActiveSyncDispatcher+Sync.m index 46f896ed2..6377e68e4 100644 --- a/ActiveSync/SOGoActiveSyncDispatcher+Sync.m +++ b/ActiveSync/SOGoActiveSyncDispatcher+Sync.m @@ -98,6 +98,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "iCalToDo+ActiveSync.h" #include "NGDOMElement+ActiveSync.h" #include "NGVCard+ActiveSync.h" +#include "NSDate+ActiveSync.h" #include "NSData+ActiveSync.h" #include "NSString+ActiveSync.h" #include "SOGoActiveSyncConstants.h" @@ -445,7 +446,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - (void) processSyncGetChanges: (id ) theDocumentElement inCollection: (id) theCollection withSyncKey: (NSString *) theSyncKey - withType: (SOGoMicrosoftActiveSyncFolderType) theFolderType + withFolderType: (SOGoMicrosoftActiveSyncFolderType) theFolderType + withFilterType: (NSDate *) theFilterType inBuffer: (NSMutableString *) theBuffer { int i; @@ -743,9 +745,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. value = [theDocumentElement getElementsByTagName: @"GetChanges"]; getChanges = YES; - if ([value count]) + if ([value count] && [[[value lastObject] textValue] length]) getChanges = [[[value lastObject] textValue] boolValue]; - + first_sync = NO; if ([syncKey isEqualToString: @"0"]) @@ -776,7 +778,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. [self processSyncGetChanges: theDocumentElement inCollection: collection withSyncKey: syncKey - withType: folderType + withFolderType: folderType + withFilterType: [NSDate dateFromFilterType: [[(id)[theDocumentElement getElementsByTagName: @"FilterType"] lastObject] textValue]] inBuffer: theBuffer]; }