From 6d6053865f970f40e6dc4e6ac37df8c4d5bf29d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrique=20J=2E=20Hern=C3=A1ndez=20Blasco?= Date: Fri, 13 Mar 2015 00:00:29 +0100 Subject: [PATCH 1/3] Revert "oc-mailfolder: Get seen flag directly from message in preloading" This reverts commit d076e04ad47c8938531450af9f002552328f8fa1. --- OpenChange/MAPIStoreMailFolder.m | 33 ++++++++++++++++++++----------- OpenChange/MAPIStoreMailMessage.h | 1 - OpenChange/MAPIStoreMailMessage.m | 8 -------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/OpenChange/MAPIStoreMailFolder.m b/OpenChange/MAPIStoreMailFolder.m index 0a439e29e..e4c4b8a9b 100644 --- a/OpenChange/MAPIStoreMailFolder.m +++ b/OpenChange/MAPIStoreMailFolder.m @@ -1476,8 +1476,9 @@ _parseCOPYUID (NSString *line, NSArray **destUIDsP) NSUInteger count, max; NSString *messageKey, *messageUid, *bodyPartKey; NGImap4Client *client; - NSArray *fetch; + NSArray *fetch, *flags; NSData *bodyContent; + BOOL unseen; NSMutableArray *unseenUIDs; if (tableType == MAPISTORE_MESSAGE_TABLE) @@ -1489,7 +1490,6 @@ _parseCOPYUID (NSString *line, NSArray **destUIDsP) { bodyPartKeys = [NSMutableSet setWithCapacity: max]; - unseenUIDs = [NSMutableArray arrayWithCapacity: max]; keyAssoc = [NSMutableDictionary dictionaryWithCapacity: max]; for (count = 0; count < max; count++) { @@ -1503,15 +1503,6 @@ _parseCOPYUID (NSString *line, NSArray **destUIDsP) [bodyPartKeys addObject: bodyPartKey]; messageUid = [self messageUIDFromMessageKey: messageKey]; [keyAssoc setObject: bodyPartKey forKey: messageUid]; - /* Fetch flags to remove seen flag if required, - as fetching a message body set the seen flag. - We are not using body.peek[] as - bodyContentPartKey explicitly avoids it. - */ - if (![message read]) - { - [unseenUIDs addObject: messageUid]; - } } } } @@ -1519,6 +1510,24 @@ _parseCOPYUID (NSString *line, NSArray **destUIDsP) client = [[(SOGoMailFolder *) sogoObject imap4Connection] client]; [client select: [sogoObject absoluteImap4Name]]; + /* Fetch flags to remove seen flag if required, + as fetching a message body set the seen flag */ + response = [client fetchUids: [keyAssoc allKeys] + parts: [NSArray arrayWithObjects: @"flags", nil]]; + fetch = [response objectForKey: @"fetch"]; + max = [fetch count]; + unseenUIDs = [NSMutableArray arrayWithCapacity: max]; + for (count = 0; count < max; count++) + { + response = [fetch objectAtIndex: count]; + messageUid = [[response objectForKey: @"uid"] stringValue]; + flags = [response objectForKey: @"flags"]; + unseen = [flags indexOfObject: @"seen"] == NSNotFound; + if (unseen) { + [unseenUIDs addObject: messageUid]; + } + } + response = [client fetchUids: [keyAssoc allKeys] parts: [bodyPartKeys allObjects]]; fetch = [response objectForKey: @"fetch"]; @@ -1541,7 +1550,7 @@ _parseCOPYUID (NSString *line, NSArray **destUIDsP) } } - /* Restore unseen state once the body has been fetched */ + // Restore unseen state once the body has been fetched if ([unseenUIDs count] > 0) { response = [client storeFlags: [NSArray arrayWithObjects: @"seen", nil] diff --git a/OpenChange/MAPIStoreMailMessage.h b/OpenChange/MAPIStoreMailMessage.h index 2f6192c16..fffd0c422 100644 --- a/OpenChange/MAPIStoreMailMessage.h +++ b/OpenChange/MAPIStoreMailMessage.h @@ -74,7 +74,6 @@ /* batch-mode helpers */ - (NSString *) bodyContentPartKey; - (void) setBodyContentFromRawData: (NSData *) rawContent; -- (BOOL) read; /* Unseen from sogoObject */ @end diff --git a/OpenChange/MAPIStoreMailMessage.m b/OpenChange/MAPIStoreMailMessage.m index 4c6fba488..b5caf3355 100644 --- a/OpenChange/MAPIStoreMailMessage.m +++ b/OpenChange/MAPIStoreMailMessage.m @@ -1660,12 +1660,4 @@ _compareBodyKeysByPriority (id entry1, id entry2, void *data) } } -- (BOOL) read -{ - if (!headerSetup) - [self _fetchHeaderData]; - - return [sogoObject read]; -} - @end From f0488607299e7941be4315ad1407ab125b6b7032 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrique=20J=2E=20Hern=C3=A1ndez=20Blasco?= Date: Fri, 13 Mar 2015 00:00:40 +0100 Subject: [PATCH 2/3] Revert "oc-mailfolder: Avoid setting seen flag on preloading message bodies" This reverts commit 7e0cddc06bc520c8eefe1b9190e92443853a15bc. --- OpenChange/MAPIStoreMailFolder.m | 31 +------------------------------ 1 file changed, 1 insertion(+), 30 deletions(-) diff --git a/OpenChange/MAPIStoreMailFolder.m b/OpenChange/MAPIStoreMailFolder.m index e4c4b8a9b..43f8e4d25 100644 --- a/OpenChange/MAPIStoreMailFolder.m +++ b/OpenChange/MAPIStoreMailFolder.m @@ -1476,10 +1476,8 @@ _parseCOPYUID (NSString *line, NSArray **destUIDsP) NSUInteger count, max; NSString *messageKey, *messageUid, *bodyPartKey; NGImap4Client *client; - NSArray *fetch, *flags; + NSArray *fetch; NSData *bodyContent; - BOOL unseen; - NSMutableArray *unseenUIDs; if (tableType == MAPISTORE_MESSAGE_TABLE) { @@ -1509,25 +1507,6 @@ _parseCOPYUID (NSString *line, NSArray **destUIDsP) client = [[(SOGoMailFolder *) sogoObject imap4Connection] client]; [client select: [sogoObject absoluteImap4Name]]; - - /* Fetch flags to remove seen flag if required, - as fetching a message body set the seen flag */ - response = [client fetchUids: [keyAssoc allKeys] - parts: [NSArray arrayWithObjects: @"flags", nil]]; - fetch = [response objectForKey: @"fetch"]; - max = [fetch count]; - unseenUIDs = [NSMutableArray arrayWithCapacity: max]; - for (count = 0; count < max; count++) - { - response = [fetch objectAtIndex: count]; - messageUid = [[response objectForKey: @"uid"] stringValue]; - flags = [response objectForKey: @"flags"]; - unseen = [flags indexOfObject: @"seen"] == NSNotFound; - if (unseen) { - [unseenUIDs addObject: messageUid]; - } - } - response = [client fetchUids: [keyAssoc allKeys] parts: [bodyPartKeys allObjects]]; fetch = [response objectForKey: @"fetch"]; @@ -1549,14 +1528,6 @@ _parseCOPYUID (NSString *line, NSArray **destUIDsP) } } } - - // Restore unseen state once the body has been fetched - if ([unseenUIDs count] > 0) - { - response = [client storeFlags: [NSArray arrayWithObjects: @"seen", nil] - forUIDs: unseenUIDs - addOrRemove: NO]; - } } } From 1c1a75d2c16b5b331c90695f8bee31f1d3ccfd00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrique=20J=2E=20Hern=C3=A1ndez=20Blasco?= Date: Fri, 13 Mar 2015 09:34:21 +0100 Subject: [PATCH 3/3] oc-mail: Use body.peek to preload message bodies In this way, we do not modify the flags (\Seen) on preloading. The IMAP server returns the content without .peek section so it is removed. This also performs the modification intended by the following Pull Request: https://github.com/Zentyal/sogo/pull/50 That tried to avoid set \Seen flag when preloading message bodies on synchronisation. But in this case we are not incrementing the modseq as we are not modifying any messages flags. --- NEWS | 1 + OpenChange/MAPIStoreMailFolder.m | 9 +++++++++ OpenChange/MAPIStoreMailMessage.m | 6 +----- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/NEWS b/NEWS index bae4a7cd6..e05997040 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,7 @@ master ------ Enhancements + - Improve sync speed from Outlook by non-reprocessing already downloaded unread mails - Give support to calendar sharing invitations - Missing contact fields are now saved and available when sharing it (Office, Profession, Manager's name, Assistant's name, Spouse/Partner, Anniversary) diff --git a/OpenChange/MAPIStoreMailFolder.m b/OpenChange/MAPIStoreMailFolder.m index 43f8e4d25..78471e49c 100644 --- a/OpenChange/MAPIStoreMailFolder.m +++ b/OpenChange/MAPIStoreMailFolder.m @@ -1500,6 +1500,15 @@ _parseCOPYUID (NSString *line, NSArray **destUIDsP) { [bodyPartKeys addObject: bodyPartKey]; messageUid = [self messageUIDFromMessageKey: messageKey]; + /* If the bodyPartKey include peek, remove it as it is not returned + as key in the IMAP server response. + + IMAP conversation example: + a4 UID FETCH 1 (UID BODY.PEEK[text]) + * 1 FETCH (UID 1 BODY[TEXT] {1677} + */ + bodyPartKey = [bodyPartKey stringByReplacingOccurrencesOfString: @"body.peek" + withString: @"body"]; [keyAssoc setObject: bodyPartKey forKey: messageUid]; } } diff --git a/OpenChange/MAPIStoreMailMessage.m b/OpenChange/MAPIStoreMailMessage.m index b5caf3355..8c35f4265 100644 --- a/OpenChange/MAPIStoreMailMessage.m +++ b/OpenChange/MAPIStoreMailMessage.m @@ -1627,11 +1627,7 @@ _compareBodyKeysByPriority (id entry1, id entry2, void *data) if (!headerSetup) [self _fetchHeaderData]; - if ([mimeKey hasPrefix: @"body.peek"]) - bodyPartKey = [NSString stringWithFormat: @"body[%@]", - [mimeKey _strippedBodyKey]]; - else - bodyPartKey = mimeKey; + bodyPartKey = mimeKey; return bodyPartKey; }