Search code examples
exchange-serverimap

Phantom messages in Exchange Calendar folder


I'm developing an IMAP client, and testing it against a Microsoft Exchange server. When I select the Calendar mailbox, UID SEARCH suggests that there are messages in the mailbox, but UID FETCH cannot fetch them:

S: * OK The Microsoft Exchange IMAP4 service is ready.
...
C: 38 SELECT "Calendar"
S: * 13 EXISTS
S: * 0 RECENT
S: * FLAGS (\Seen \Answered \Flagged \Deleted \Draft $MDNSent)
S: * OK [PERMANENTFLAGS (\Seen \Answered \Flagged \Deleted \Draft $MDNSent)] Permanent flags
S: * OK [UIDVALIDITY 37122] UIDVALIDITY value
S: * OK [UIDNEXT 190] The next unique identifier value
S: 38 OK [READ-WRITE] SELECT completed.
C: 39 UID SEARCH OR UNSEEN FLAGGED
C: 40 UID SEARCH SEEN UNFLAGGED SINCE 19-Oct-2014
S: * SEARCH
S: 39 OK SEARCH completed.
S: * SEARCH 90 183
S: 40 OK SEARCH completed.
C: 41 UID FETCH 90,183 (ENVELOPE INTERNALDATE FLAGS BODY.PEEK[])
S: 41 OK FETCH completed.

I presume that Calendar is some kind of virtual mailbox, but this behaviour doesn't make sense to me — why would the server return the message uids in UID SEARCH if it's not possible to FETCH them? Is there any way to fetch these messages, or somehow manipulate them using IMAP?


Update: After being upgraded to 2010 SP3, it seems like the Exchange server had a change of heart. Now it at least returns something in response to the FETCH command:

C: 120 UID FETCH 773,948 (ENVELOPE INTERNALDATE FLAGS BODY.PEEK[])
S: * 16 FETCH (ENVELOPE (NIL "Retrieval using the IMAP4 protocol failed for the following message: 773" (("Microsoft Exchange Server 2010" NIL NIL ".MISSING-HOST-NAME.")) NIL NIL (("██████████" NIL "██████████" "██████████")) NIL NIL NIL NIL) INTERNALDATE "05-Mar-2015 17:22:02 +0000" FLAGS (\Seen) BODY[] {783}
S: <783 bytes omitted>
S:  UID 773)
S: * 17 FETCH (ENVELOPE (NIL "Retrieval using the IMAP4 protocol failed for the following message: 948" (("Microsoft Exchange Server 2010" NIL NIL ".MISSING-HOST-NAME.")) NIL NIL (("██████████" NIL "██████████" "██████████")) NIL NIL NIL NIL) INTERNALDATE "11-Mar-2015 17:56:04 +0000" FLAGS (\Seen) BODY[] {747}
S: <747 bytes omitted>
S:  UID 948)
S: 120 OK FETCH completed.

The messages look like this:

MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
From: Microsoft Exchange Server 2010
To: ███████████ <████████@██████████.com>
Subject: Retrieval using the IMAP4 protocol failed for the following
 message: 773
Content-Transfer-Encoding: quoted-printable

The server couldn't retrieve the following message:

Subject: "████ █████ ███████ ██ ████ ███ █████ ███████.. ███ ███ ██████ ███=
██!"
From: "███████████  ██████████" ("/O=3D████████/OU=3D████████ █████████████=
█ █████ (███████████████)/CN=3D██████████/CN=3D███████████  █████████████")
Sent date: 3/5/2015 5:22:02 PM

The message hasn't been deleted. You might be able to view it using either =
Outlook or Outlook Web App. You can also contact the sender to find out wha=
t the message says.=

Solution

  • Sounds like a server bug. It is not a secret that Exchange "implaments IMAP" in order to be able to tick a required checkbox when evaluating tenders. You will see other bugs in there as well.

    It might be interesting to get a list of all UIDs which that mailbox allegedly contains, and to try fetching them one-by-one to see if at least some of them return some usable value. However, considering that this is a mailbox called "Calendar", chances are that it's just some random Exchange export of data which only make sense via MAPI. Random googling results in https://technet.microsoft.com/en-us/library/aa998606%28v=exchg.150%29.aspx which suggests that Exchange can be configured to offer these calendar data in various formats. Maybe your server is "misconfigured".

    TL;DR: it's Exchange. Don't waste time on it.