]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-imap: Fix writing BODYSTRUCTURE for truncated multipart/ part
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Wed, 18 Nov 2020 18:48:11 +0000 (20:48 +0200)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Wed, 2 Dec 2020 07:31:44 +0000 (07:31 +0000)
If the max nesting limit is reached, write the last part out as
application/octet-stream. The original content-type could be confusing
IMAP clients when they don't see any child parts.

src/lib-imap/imap-bodystructure.c
src/lib-imap/test-imap-bodystructure.c

index ab422c00d21d2bda58176e4461b82d818a12af28..bfb6e64197b69ca759b1793882357b43fe0dc272 100644 (file)
@@ -147,6 +147,7 @@ static bool part_is_truncated(const struct message_part *part)
        const struct message_part_data *data = part->data;
 
        i_assert((part->flags & MESSAGE_PART_FLAG_MESSAGE_RFC822) == 0);
+       i_assert((part->flags & MESSAGE_PART_FLAG_MULTIPART) == 0);
 
        if (data->content_type != NULL) {
                if (strcasecmp(data->content_type, "message") == 0 &&
@@ -155,6 +156,11 @@ static bool part_is_truncated(const struct message_part *part)
                           MESSAGE_PART_FLAG_MESSAGE_RFC822. */
                        return TRUE;
                }
+               if (strcasecmp(data->content_type, "multipart") == 0) {
+                       /* It's multipart/, but without
+                          MESSAGE_PART_FLAG_MULTIPART. */
+                       return TRUE;
+               }
        }
        return FALSE;
 }
index 6cb699e12694243114a17c07d948ebc65b8b54c2..2118907e78303eaa3bb955a2011bb8eb7c60cf8c 100644 (file)
@@ -556,6 +556,21 @@ static const struct {
                .bodystructure = "\"message\" \"rfc822\" NIL NIL NIL \"7bit\" 159 (NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL) (\"application\" \"octet-stream\" NIL NIL NIL \"7bit\" 110 NIL NIL NIL NIL) 11 NIL NIL NIL NIL",
                .max_depth = 2,
        },
+       {
+               .input = "Content-Type: multipart/mixed; boundary=1\n"
+                       "\n"
+                       "--1\n"
+                       "Content-Type: multipart/mixed; boundary=2\n"
+                       "\n"
+                       "--2\n"
+                       "Content-Type: multipart/mixed; boundary=3\n"
+                       "\n"
+                       "--3\n"
+                       "\n"
+                       "body\n",
+               .bodystructure = "(\"application\" \"octet-stream\" (\"boundary\" \"2\") NIL NIL \"7bit\" 63 NIL NIL NIL NIL) \"mixed\" (\"boundary\" \"1\") NIL NIL NIL",
+               .max_depth = 2,
+       },
 };
 
 static void test_imap_bodystructure_truncation(void)