Add safety check for reordered attachments
authorAndre Heinecke <aheinecke@gnupg.org>
Fri, 12 Apr 2019 07:46:27 +0000 (09:46 +0200)
committerAndre Heinecke <aheinecke@gnupg.org>
Fri, 12 Apr 2019 09:16:39 +0000 (11:16 +0200)
* src/mapihelp.cpp (mapi_mark_or_create_moss_attach): When
there are two MOSS attachments check for content_type.

--
Sometimes the attachments are not in the order we expect.
This happened somehow if a draft encrypted by us was opened in
the Web interface.

src/mapihelp.cpp

index 4a4d0e9..a11774c 100644 (file)
@@ -3589,7 +3589,21 @@ mapi_mark_or_create_moss_attach (LPMESSAGE message, LPMESSAGE parsed_message,
           else if (!part2)
             {
               /* If we have two MOSS attachments we use
-                 the second one. */
+                 the second one if the first one is not the octet-stream. */
+              if (table[part1 - 1].content_type &&
+                    !strcmp (table[part1 - 1].content_type, "application/octet-stream"))
+                {
+                  /* This is rare so debug it. Happend when drafts were
+                     encrypted / decrypted and another client was running */
+                  log_debug ("%s:%s: Have two MOSS attachments but the "
+                             "first one is the octet stream", SRCNAME,
+                             __func__);
+                  int tmp = part1;
+                  part1 = i + 1;
+                  part2 = tmp;
+                  break;
+                }
+
               part2 = i + 1;
               break;
             }