From: Kevin McCarthy Date: Thu, 14 Sep 2017 19:43:32 +0000 (-0700) Subject: Improve imap fetch handler to accept an initial UID. (closes #3969) X-Git-Tag: mutt-1-9-1-rel~4 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=963c8ff0dfeb5900ec6ba8a0122ac5d7923b912a;p=mutt Improve imap fetch handler to accept an initial UID. (closes #3969) Gmail sends flag updates with a UID before the FLAGS. The handler was very simple, and so ignored the flag update in that case. Pull the code from msg_parse_fetch(), paring down to just UID and FLAGS. This will handle arbitrary order data items. --- diff --git a/imap/command.c b/imap/command.c index 496154e8..891efb74 100644 --- a/imap/command.c +++ b/imap/command.c @@ -649,7 +649,7 @@ static void cmd_parse_expunge (IMAP_DATA* idata, const char* s) * Of course, a lot of code here duplicates code in message.c. */ static void cmd_parse_fetch (IMAP_DATA* idata, char* s) { - unsigned int msn; + unsigned int msn, uid; HEADER *h; dprint (3, (debugfile, "Handling FETCH\n")); @@ -680,18 +680,41 @@ static void cmd_parse_fetch (IMAP_DATA* idata, char* s) } s++; - if (ascii_strncasecmp ("FLAGS", s, 5) != 0) + while (*s) { - dprint (2, (debugfile, "Only handle FLAGS updates\n")); - return; - } + SKIPWS (s); - /* If server flags could conflict with mutt's flags, reopen the mailbox. */ - if (h->changed) - idata->reopen |= IMAP_EXPUNGE_PENDING; - else { - imap_set_flags (idata, h, s); - idata->check_status = IMAP_FLAGS_PENDING; + if (ascii_strncasecmp ("FLAGS", s, 5) == 0) + { + /* If server flags could conflict with mutt's flags, reopen the mailbox. */ + if (h->changed) + idata->reopen |= IMAP_EXPUNGE_PENDING; + else + { + imap_set_flags (idata, h, s); + idata->check_status = IMAP_FLAGS_PENDING; + } + return; + } + else if (ascii_strncasecmp ("UID", s, 3) == 0) + { + s += 3; + SKIPWS (s); + uid = (unsigned int) atoi (s); + if (uid != HEADER_DATA(h)->uid) + { + dprint (2, (debugfile, "FETCH UID vs MSN mismatch. Skipping update.\n")); + return; + } + s = imap_next_word (s); + } + else if (*s == ')') + s++; /* end of request */ + else if (*s) + { + dprint (2, (debugfile, "Only handle FLAGS updates\n")); + return; + } } } diff --git a/imap/message.c b/imap/message.c index 8282ec10..4c882165 100644 --- a/imap/message.c +++ b/imap/message.c @@ -1196,7 +1196,7 @@ char* imap_set_flags (IMAP_DATA* idata, HEADER* h, char* s) hd = h->data; newh.data = hd; - dprint (2, (debugfile, "imap_fetch_message: parsing FLAGS\n")); + dprint (2, (debugfile, "imap_set_flags: parsing FLAGS\n")); if ((s = msg_parse_flags (&newh, s)) == NULL) return NULL;