diff --git a/ActiveSync/SOGoActiveSyncDispatcher+Sync.m b/ActiveSync/SOGoActiveSyncDispatcher+Sync.m index b214984d1..54d827453 100644 --- a/ActiveSync/SOGoActiveSyncDispatcher+Sync.m +++ b/ActiveSync/SOGoActiveSyncDispatcher+Sync.m @@ -64,6 +64,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #import #import +#import #import #import #import @@ -567,8 +568,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. default: { NSMutableArray *addedOrChangedMessages; + NSString *uid, *command, *key; SOGoMailObject *mailObject; - NSString *uid, *command; NSDictionary *aMessage; NSArray *allMessages; int deleted_count; @@ -618,6 +619,20 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. uid = [[[aMessage allKeys] lastObject] stringValue]; command = [[aMessage allValues] lastObject]; + // We check for Outlook stupidity to avoid creating duplicates - see the comment + // in SOGoActiveSyncDispatcher.m: -processMoveItems:inResponse: for more details. + key = [NSString stringWithFormat: @"%@+%@+%@+%@", + [[context activeUser] login], + [context objectForKey: @"DeviceType"], + [theCollection displayName], + uid]; + + if ([[SOGoCache sharedCache] valueForKey: key]) + { + [[SOGoCache sharedCache] removeValueForKey: key]; + command = @"changed"; + } + if ([command isEqualToString: @"added"]) [s appendString: @""]; else diff --git a/ActiveSync/SOGoActiveSyncDispatcher.m b/ActiveSync/SOGoActiveSyncDispatcher.m index 5a64cf6c8..1143219fd 100644 --- a/ActiveSync/SOGoActiveSyncDispatcher.m +++ b/ActiveSync/SOGoActiveSyncDispatcher.m @@ -76,6 +76,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #import #import +#import #import #import #import @@ -880,10 +881,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NSDictionary *response; NSString *v; - - // userFolder = [[context activeUser] homeFolderInContext: context]; - // accountsFolder = [userFolder lookupName: @"Mail" inContext: context acquire: NO]; - // currentFolder = [accountsFolder lookupName: @"0" inContext: context acquire: NO]; currentCollection = [self collectionFromId: srcFolderId type: srcFolderType]; @@ -925,6 +922,28 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NSMutableString *s; NSData *d; + // + // If the MoveItems operation is initiated by an Outlook client, we save the "deviceType+dstMessageId" to use it later in order to + // modify the Sync command from "add" to "change" (see SOGoActiveSyncDispatcher+Sync.m: -processSyncGetChanges: ...). + // This is to avoid Outlook creating dupes when moving messages across folfers. + // + if ([[context objectForKey: @"DeviceType"] isEqualToString: @"WindowsOutlook15"]) + { + NSString *key; + + // The key must be pretty verbose. We use the +++ + key = [NSString stringWithFormat: @"%@+%@+%@+%@", + [[context activeUser] login], + [context objectForKey: @"DeviceType"], + dstFolderId, + dstMessageId]; + + + [[SOGoCache sharedCache] setValue: @"MovedItem" + forKey: key]; + } + + // Everything is alright, lets return the proper response. "Status == 3" means success. s = [NSMutableString string]; @@ -1522,9 +1541,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ASSIGN(context, theContext); - // Get the device ID and "stash" it + // Get the device ID, device type and "stash" them deviceId = [[theRequest uri] deviceId]; [context setObject: deviceId forKey: @"DeviceId"]; + [context setObject: [[theRequest uri] deviceType] forKey: @"DeviceType"]; d = [[theRequest content] wbxml2xml]; documentElement = nil;