]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-imap: Don't generate invalid BODYSTRUCTURE when reaching MIME part limit
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Fri, 11 Sep 2020 07:57:51 +0000 (10:57 +0300)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Thu, 5 Nov 2020 16:09:22 +0000 (18:09 +0200)
If the last MIME part was message/rfc822 and its child was truncated away,
BODYSTRUCTURE was missing the ENVELOPE and BODY[STRUCTURE] parts. Fixed by
writing empty dummy ones.

src/lib-imap/imap-bodystructure.c

index 4e379e56a9e75e8c4bdeba37fa921743eb828f7e..e3da1090b4f2cbaa2bbacefde06720da53b6d358 100644 (file)
@@ -146,11 +146,25 @@ static void part_write_body(const struct message_part *part,
                            string_t *str, bool extended)
 {
        const struct message_part_data *data = part->data;
-       bool text;
+       bool text, message_rfc822;
 
        i_assert(part->data != NULL);
 
-       if ((part->flags & MESSAGE_PART_FLAG_MESSAGE_RFC822) != 0) {
+       if ((part->flags & MESSAGE_PART_FLAG_MESSAGE_RFC822) != 0)
+               message_rfc822 = TRUE;
+       else if (data->content_type != NULL &&
+                strcasecmp(data->content_type, "message") == 0 &&
+                strcasecmp(data->content_subtype, "rfc822") == 0) {
+               /* It's message/rfc822, but without
+                  MESSAGE_PART_FLAG_MESSAGE_RFC822. That likely means maximum
+                  MIME part count was reached while parsing the mail. Write
+                  the missing child mail's ENVELOPE and BODY as empty dummy
+                  values. */
+               message_rfc822 = TRUE;
+       } else
+               message_rfc822 = FALSE;
+
+       if (message_rfc822) {
                str_append(str, "\"message\" \"rfc822\"");
                text = FALSE;
        } else {
@@ -200,6 +214,17 @@ static void part_write_body(const struct message_part *part,
 
                part_write_bodystructure_siblings(part->children, str, extended);
                str_printfa(str, " %u", part->body_size.lines);
+       } else if (message_rfc822) {
+               /* truncated MIME part - write out dummy values */
+               i_assert(part->children == NULL);
+
+               str_append(str, " (NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL) ");
+
+               if (!extended)
+                       str_append(str, EMPTY_BODY);
+               else
+                       str_append(str, EMPTY_BODYSTRUCTURE);
+               str_printfa(str, " %u", part->body_size.lines);
        }
 
        if (!extended)