]> granicus.if.org Git - neomutt/commitdiff
Improve imap fetch handler to accept an initial UID. (closes #3969)
authorKevin McCarthy <kevin@8t8.us>
Thu, 14 Sep 2017 19:43:32 +0000 (12:43 -0700)
committerRichard Russon <rich@flatcap.org>
Thu, 14 Sep 2017 21:45:53 +0000 (22:45 +0100)
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.

imap/command.c
imap/message.c

index 49a2255fc278c0ebba505155f8cd381a2c428b2e..b6cf98a42d791c5be1b709284c3f464bfe1398ca 100644 (file)
@@ -257,7 +257,7 @@ static void cmd_parse_expunge(struct ImapData *idata, const char *s)
  */
 static void cmd_parse_fetch(struct ImapData *idata, char *s)
 {
-  unsigned int msn;
+  unsigned int msn, uid;
   struct Header *h = NULL;
 
   mutt_debug(3, "Handling FETCH\n");
@@ -288,19 +288,41 @@ static void cmd_parse_fetch(struct ImapData *idata, char *s)
   }
   s++;
 
-  if (mutt_strncasecmp("FLAGS", s, 5) != 0)
+  while (*s)
   {
-    mutt_debug(2, "Only handle FLAGS updates\n");
-    return;
-  }
+    SKIPWS(s);
 
-  /* If server flags could conflict with neomutt'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 (mutt_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 (mutt_strncasecmp("UID", s, 3) == 0)
+    {
+      s += 3;
+      SKIPWS(s);
+      uid = (unsigned int) atoi(s);
+      if (uid != HEADER_DATA(h)->uid)
+      {
+        mutt_debug(2, "FETCH UID vs MSN mismatch.  Skipping update.\n");
+        return;
+      }
+      s = imap_next_word(s);
+    }
+    else if (*s == ')')
+      s++; /* end of request */
+    else if (*s)
+    {
+      mutt_debug(2, "Only handle FLAGS updates\n");
+      return;
+    }
   }
 }
 
index e48c3dbbb4d152cb732138a8a6fdc6b0101a8ad4..ef07117691ba2de83f7e3ba6b0da9434ddcf9d36 100644 (file)
@@ -1444,7 +1444,7 @@ char *imap_set_flags(struct ImapData *idata, struct Header *h, char *s)
   hd = h->data;
   newh.data = hd;
 
-  mutt_debug(2, "imap_fetch_message: parsing FLAGS\n");
+  mutt_debug(2, "imap_set_flags: parsing FLAGS\n");
   if ((s = msg_parse_flags(&newh, s)) == NULL)
     return NULL;