mail icon indicating copy to clipboard operation
mail copied to clipboard

Multipart / Attachment handling overview

Open kesselb opened this issue 2 years ago • 2 comments

The purpose of this issue is to document known issues with our multipart and attachment handling.

Hidden attachments

Original report https://github.com/nextcloud/mail/issues/5282 and partly fixed by https://github.com/nextcloud/mail/pull/5339.

Sample eml
Return-Path: <[email protected]>
Delivered-To: [email protected]
Received: from fcf416df7902
	by fcf416df7902 with LMTP
	id oKwwBSNDuWSRAQAAuSYRyA
	(envelope-from <[email protected]>)
	for <[email protected]>; Thu, 20 Jul 2023 14:22:27 +0000
Received: from localhost (unknown [172.19.0.1])
	by fcf416df7902 (Postfix) with ESMTP id 063732260B32
	for <[email protected]>; Thu, 20 Jul 2023 14:22:27 +0000 (UTC)
From: [email protected]
To: [email protected]
Subject: Patches
Message-ID: <20230720162227.Horde.tQbO75MfhHKIerc-38l3V5j@pc>
User-Agent: Horde Application Framework 5
Date: Thu, 20 Jul 2023 16:22:27 +0200
Content-Type: multipart/mixed; boundary="=_ltOS0Zz8DtIKjXr3jbdMGDN"
MIME-Version: 1.0

This message is in MIME format.

--=_ltOS0Zz8DtIKjXr3jbdMGDN
Content-Type: multipart/alternative; boundary="=_sVhlJCYnkclzOHfh6XZ-w5L"

This message is in MIME format.

--=_sVhlJCYnkclzOHfh6XZ-w5L
Content-Type: text/html; charset=utf-8
Content-Description: HTML Version of Message

<html><meta http-equiv="content-type" content="text/html; charset=UTF-8"><body>Hello Hello</body><html>
--=_sVhlJCYnkclzOHfh6XZ-w5L
Content-Type: text/plain; charset=utf-8
Content-Description: Plaintext Version of Message

Hello Hello
--=_sVhlJCYnkclzOHfh6XZ-w5L--

--=_ltOS0Zz8DtIKjXr3jbdMGDN
Content-Type: text/x-patch; name=some.patch
Content-Disposition: inline; filename=some.patch

hello world
--=_ltOS0Zz8DtIKjXr3jbdMGDN--

Generated via: https://github.com/kesselb/weird-emails/blob/main/attachment_content_disposition_inline.php

Message structure
graph TD;
    multipart/mixed-->multipart/alternative;
    multipart/alternative-->text/html;
    multipart/alternative-->text/plain;
    multipart/mixed-->text/x-patch;
  
Screenshots

Mail

Screenshot from 2023-07-20 18-09-07

Thunderbird

Screenshot from 2023-07-20 18-08-39

HTML message Content-Disposition for text/x-patch is inline

Issue: We assume that mime parts with content-disposition = inline are referenced in via content-id / cid in the html document. Is the mime part not referenced, it's hidden.

Possible solutions:

  1. Merge inlineAttachments and attachments like for text/plain emails.
  2. If content-disposition = inline && content-id = null, then treat mime part as regular attachment.

Hidden message

Sample eml
Return-Path: <[email protected]>
Delivered-To: [email protected]
Received: from fcf416df7902
	by fcf416df7902 with LMTP
	id lko6KsJTuWQUBAAAuSYRyA
	(envelope-from <[email protected]>)
	for <[email protected]>; Thu, 20 Jul 2023 15:33:22 +0000
Received: from localhost (unknown [172.19.0.1])
	by fcf416df7902 (Postfix) with ESMTP id 9BEA52260B32
	for <[email protected]>; Thu, 20 Jul 2023 15:33:22 +0000 (UTC)
From: [email protected]
To: [email protected]
Subject: Multipart with multiple parts
Message-ID: <20230720173322.Horde.Lbu6mga1p0l6Yh4ZFm-Exh4@pc>
User-Agent: Horde Application Framework 5
Date: Thu, 20 Jul 2023 17:33:22 +0200
Content-Type: multipart/mixed; boundary="=_Xs2dih_sEN07PRgH-bx7MWq"
MIME-Version: 1.0

This message is in MIME format.

--=_Xs2dih_sEN07PRgH-bx7MWq
Content-Type: text/html; charset=utf-8
Content-Description: HTML Version of Message

<html><meta http-equiv="content-type" content="text/html; charset=UTF-8"><body>Hello Hello</body><html>
--=_Xs2dih_sEN07PRgH-bx7MWq
Content-Type: text/html; charset=utf-8
Content-Description: HTML Version of Message

<html><meta http-equiv="content-type" content="text/html; charset=UTF-8"><body>Hope you are dooing fine</body><html>
--=_Xs2dih_sEN07PRgH-bx7MWq--

Generated via: https://github.com/kesselb/weird-emails/blob/main/multipart_with_multiple_parts.php

Message structure
graph TD;
    multipart/mixed-->text/html;
    multipart/mixed-->text/html;
Screenshots

Mail

Screenshot from 2023-07-20 18-33-16

Thunderbird

Screenshot from 2023-07-20 18-33-24

Multipart message with multiple text/html parts.

Issue: We show the first text/html part. Without looking at the source, you don't know there's something else.

Possible solutions:

  1. Render both text/html parts
  2. Add the mime parts as attachment

kesselb avatar Jul 20 '23 15:07 kesselb

Some possible mime structures...

multipart/mixed
  text/plain, content-disposition=inline - A
  multipart/mixed
    multipart/alternative
      multipart/mixed
        text/plain, content-disposition=inline - B
        image/jpeg, content-disposition=inline - C
        text/plain, content-disposition=inline - D
      multipart/related
        text/html - E
        image/jpeg - F
    image/jpeg, content-disposition=attachment - G
    application/x-excel - H
    message/rfc822 - J
  text/plain, content-disposition=inline - K

In this case, the above algorithm would decompose this to:

textBody => [ A, B, C, D, K ]
htmlBody => [ A, E, K ]
attachments => [ C, F, G, H, J ]

SebastianKrupinski avatar Aug 05 '24 11:08 SebastianKrupinski

Hi, here is a simplified sample of one more mime structure, that fails to display correctly in Nextcloud Mail. This is is a Domain-based Message Authentication, Reporting, and Conformance (DMARC) aggregate report sent by Google (some information removed from message). Basically, it is a MIME message whose Content-Type is application/zip (attachment only, no other parts/content):

p.s. Just found - this is also discussed in #4423 !

Return-Path: <[email protected]>
Delivered-To: [email protected]
Received: from mail.example.com
	by mail.example.com with LMTP
	id tZvOJQASw2ZcsA4ARJn5MQ
	(envelope-from <[email protected]>)
	for <[email protected]>; Mon, 19 Aug 2024 12:36:00 +0300
MIME-Version: 1.0
X-Received: by 2002:a05:6820:1acc:b0:5d5:d7fc:955c with SMTP id
 006d021491bc7-5da9801a875mr10422414eaf.5.1724060153323; Mon, 19 Aug 2024
 02:35:53 -0700 (PDT)
Date: Sun, 18 Aug 2024 16:59:59 -0700
Message-ID: <[email protected]>
Subject: Report domain: example.com Submitter: google.com Report-ID: 6356864336886002680
From: [email protected]
To: [email protected]
Content-Type: application/zip; 
	name="google.com!example.com!1723939200!1724025599.zip"
Content-Disposition: attachment; 
	filename="google.com!example.com!1723939200!1724025599.zip"
Content-Transfer-Encoding: base64

UEsDB... <actual-base64-content-as-well-as-unrelated-headers-removed> ...AAAA=

ivarsg avatar Aug 20 '24 07:08 ivarsg