diff --git a/OpenChange/MAPIStoreMailFolder.h b/OpenChange/MAPIStoreMailFolder.h index d7ec7aaaf..0a01476fe 100644 --- a/OpenChange/MAPIStoreMailFolder.h +++ b/OpenChange/MAPIStoreMailFolder.h @@ -44,6 +44,8 @@ /* synchronisation & versioning */ - (BOOL) synchroniseCache; +- (void) synchronizeUpdatedFolder: (NSNumber *) lastModseq + withMapping: (NSMutableDictionary *) mapping; - (NSNumber *) modseqFromMessageChangeNumber: (NSString *) changeNum; - (NSString *) messageUIDFromMessageKey: (NSString *) messageKey; - (NSString *) changeNumberForMessageUID: (NSString *) messageUid; diff --git a/OpenChange/MAPIStoreMailFolder.m b/OpenChange/MAPIStoreMailFolder.m index 28fcca431..c9e168d81 100644 --- a/OpenChange/MAPIStoreMailFolder.m +++ b/OpenChange/MAPIStoreMailFolder.m @@ -70,6 +70,7 @@ static Class SOGoMailFolderK, MAPIStoreMailFolderK, MAPIStoreOutboxFolderK; #undef DEBUG #include #include +#include #include #include @@ -663,15 +664,76 @@ _compareFetchResultsByMODSEQ (id entry1, id entry2, void *data) if (foundChange) { + [self synchronizeUpdatedFolder: lastModseq + withMapping: mapping]; + ti = [NSNumber numberWithDouble: [now timeIntervalSince1970]]; [currentProperties setObject: ti forKey: @"SyncLastSynchronisationDate"]; [versionsMessage save]; } + return rc; } - + +- (void) synchronizeUpdatedFolder: (NSNumber *) lastModseq + withMapping: (NSMutableDictionary *) mapping +{ + /* This method should be called whenever something has changed on the folder. + Then we will perform two actions: + 1 - Update its PidTagChangeNumber property. + 2 - Store relationship PidTagChangenumber with lastModseq value on the + mapping given as parameter */ + uint64_t *current_cn; + struct SRow row; + struct SPropValue prop; + uint64_t fid; + const char *username; + struct openchangedb_context *oc_ctx; + enum MAPISTATUS retval; + TALLOC_CTX *local_mem_ctx = NULL; + + row.cValues = 1; + prop.ulPropTag = PidTagChangeNumber; + prop.value.d = 0; // It doesn't matter, it will be autogenerated + row.lpProps = ∝ + + /* We are doing a "touch" operation to update change number of this folder */ + username = [[self context] connectionInfo]->username; + oc_ctx = [[self context] connectionInfo]->oc_ctx; + fid = [self objectId]; + retval = openchangedb_set_folder_properties(oc_ctx, username, fid, &row); + if (retval != MAPI_E_SUCCESS) + { + [self errorWithFormat:@"%s: Error setting change number on %"PRIu64, + __PRETTY_FUNCTION__, fid]; + return; + } + + local_mem_ctx = talloc_named(NULL, 0, __PRETTY_FUNCTION__); + if (local_mem_ctx == NULL) + { + [self errorWithFormat:@"%s: Error with talloc_named, out of memory?", + __PRETTY_FUNCTION__]; + return; + } + retval = openchangedb_get_folder_property(local_mem_ctx, oc_ctx, username, + PidTagChangeNumber, fid, + (void **) ¤t_cn); + if (retval != MAPI_E_SUCCESS) + { + [self errorWithFormat:@"%s: Error getting change number on %"PRIu64, + __PRETTY_FUNCTION__, fid]; + talloc_free(local_mem_ctx); + return; + } + + [mapping setObject: lastModseq + forKey: [NSString stringWithUnsignedLongLong: *current_cn]]; + talloc_free(local_mem_ctx); +} + - (NSNumber *) modseqFromMessageChangeNumber: (NSString *) changeNum { NSDictionary *mapping;