From ef7b919175636b9c15c2a7f48a97925f26a280bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrique=20J=2E=20Hern=C3=A1ndez=20Blasco?= Date: Wed, 12 Nov 2014 16:21:44 +0100 Subject: [PATCH] Return MAPISTORE_ERR_NOT_FOUND when a mail is indexed but not in IMAP server And remove that entry from the indexing table. This avoids to crash getting properties from a no longer available message in the IMAP server, for instance, the `PidTagPredecessorChangeList` attribute. --- OpenChange/MAPIStoreFolder.m | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/OpenChange/MAPIStoreFolder.m b/OpenChange/MAPIStoreFolder.m index 2c0bade3b..5bc292458 100644 --- a/OpenChange/MAPIStoreFolder.m +++ b/OpenChange/MAPIStoreFolder.m @@ -52,6 +52,7 @@ #import #import "SOGoMAPIDBMessage.h" #import "SOGoCacheGCSObject+MAPIStore.h" +#import #include @@ -278,6 +279,12 @@ Class NSExceptionK, MAPIStoreFAIMessageK, MAPIStoreMessageTableK, MAPIStoreFAIMe msgObject = [sogoObject lookupName: messageKey inContext: nil acquire: NO]; + /* If the lookup in the indexing table works, but the IMAP does + not have the message, then the message does not exist in this + folder */ + if (msgObject && [msgObject isKindOfClass: [SOGoMailObject class]] + && ! [(SOGoMailObject *)msgObject doesMailExist]) + return nil; if (msgObject && ![msgObject isKindOfClass: NSExceptionK]) { [msgObject setContext: [[self userContext] woContext]]; @@ -503,6 +510,12 @@ Class NSExceptionK, MAPIStoreFAIMessageK, MAPIStoreMessageTableK, MAPIStoreFAIMe else rc = MAPISTORE_ERR_DENIED; } + else + { + /* Unregistering from indexing table as the backend says the + object was not found */ + [mapping unregisterURLWithID: mid]; + } } return rc; @@ -571,7 +584,7 @@ Class NSExceptionK, MAPIStoreFAIMessageK, MAPIStoreMessageTableK, MAPIStoreFAIMe /* flags that control the behaviour of the operation (MAPISTORE_SOFT_DELETE or MAPISTORE_PERMANENT_DELETE) */ [self logWithFormat: @"-deleteMessageWithMID: mid: 0x%.16llx flags: %d", mid, flags]; - + mapping = [self mapping]; childURL = [mapping urlFromID: mid]; if (childURL)