diff --git a/ActiveSync/SOGoActiveSyncDispatcher.m b/ActiveSync/SOGoActiveSyncDispatcher.m index f56e51fb9..fc8a143a8 100644 --- a/ActiveSync/SOGoActiveSyncDispatcher.m +++ b/ActiveSync/SOGoActiveSyncDispatcher.m @@ -3532,10 +3532,14 @@ void handle_eas_terminate(int signum) { NSString *folderId, *itemId, *realCollectionId; SOGoMicrosoftActiveSyncFolderType folderType; + SOGoMailAccounts *accountsFolder; + SOGoMailFolder *currentFolder; + SOGoUserFolder *userFolder; + SOGoMailObject *mailObject; SOGoUserDefaults *ud; BOOL htmlComposition, isHTML; - id value; + id value, currentCollection; isHTML = NO; ud = [[context activeUser] userDefaults]; @@ -3561,23 +3565,31 @@ void handle_eas_terminate(int signum) value = [theDocumentElement getElementsByTagName: @"ReplaceMime"]; + // We fetch the mail object from the server + userFolder = [[context activeUser] homeFolderInContext: context]; + accountsFolder = [userFolder lookupName: @"Mail" inContext: context acquire: NO]; + currentFolder = [accountsFolder lookupName: @"0" inContext: context acquire: NO]; + + currentCollection = [currentFolder lookupName: [NSString stringWithFormat: @"folder%@", realCollectionId] + inContext: context + acquire: NO]; + + mailObject = [currentCollection lookupName: itemId inContext: context acquire: NO]; + // ReplaceMime IS specified so we must NOT use the server copy // but rather take the data as-is from the client. if ([value count]) { - [self processSendMail: theDocumentElement - inResponse: theResponse]; + [self processSendMail: theDocumentElement inResponse: theResponse]; + if (!isSmartForward) + [mailObject addFlags: @"Answered"]; + else + [mailObject addFlags: @"$Forwarded"]; return; } if (folderType == ActiveSyncMailFolder) { - SOGoMailAccounts *accountsFolder; - SOGoMailFolder *currentFolder; - SOGoUserFolder *userFolder; - SOGoMailObject *mailObject; - id currentCollection; - NGMimeMessage *messageFromSmartForward, *messageToSend; NGMimeMessageParser *parser; NSData *data; @@ -3596,16 +3608,6 @@ void handle_eas_terminate(int signum) int a; - userFolder = [[context activeUser] homeFolderInContext: context]; - accountsFolder = [userFolder lookupName: @"Mail" inContext: context acquire: NO]; - currentFolder = [accountsFolder lookupName: @"0" inContext: context acquire: NO]; - - currentCollection = [currentFolder lookupName: [NSString stringWithFormat: @"folder%@", realCollectionId] - inContext: context - acquire: NO]; - - mailObject = [currentCollection lookupName: itemId inContext: context acquire: NO]; - parser = [[NGMimeMessageParser alloc] init]; data = [[[[(id)[theDocumentElement getElementsByTagName: @"MIME"] lastObject] textValue] stringByDecodingBase64] dataUsingEncoding: NSUTF8StringEncoding]; messageFromSmartForward = [parser parsePartFromData: data];