MailScanner / v5

MailScanner v5
GNU General Public License v2.0
188 stars 60 forks source link

Signature with an image and no body text #632

Closed moosty-moo closed 1 year ago

moosty-moo commented 1 year ago

Describe the bug When MailScanner adds a signature with an embeded image ( %%IMAGE%% ) and nothing has been typed in the body the received email is garbled. If the email has body text then the email renders fine.

To Reproduce Steps to reproduce the behavior:

  1. Create an HTML email with just a subject and no body text.

Expected behavior The email should render correctly wether there is body text or not

Examples The received email looks like this:

This is a multi-part message in MIME format... ------------669401123-23310-0 Content-Type: text/html; charsetf-8 Content-Transfer-Encoding: quoted-printable MailScanner Signature ------------669401123-23310-0 Content-Type: image/jpeg; nameignature.jpg" Content-Disposition: inline; filenameignature.jpg" Content-Transfer-Encoding: base64 Content-ID: /9j/4AAQSkZJRgABAQEAeAB4AAD/4QDaRXhpZgAATU0AKgAAAAgABgMBAAUA

The source of the garbled email looks like this: Date: Fri, 25 Nov 2022 15:08:12 +0000 Mime-Version: 1.0 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable

The source of the good email looks like this: Date: Fri, 25 Nov 2022 15:12:31 +0000 Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="=_vJdw11kZDJmjOszNuerkiEQV-e-HOXcAv7D0VtuwLzXwFbBU"

github-actions[bot] commented 1 year ago

Thank you for submitting your first issue to MailScanner! We will respond to you soon!

msapiro commented 1 year ago

I don't think it has to do with the body being empty. I suspect the issue is your message with no body text looks like

Date: Fri, 25 Nov 2022 15:08:12 +0000
Mime-Version: 1.0
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable

whereas the message with body text looks like

Date: Fri, 25 Nov 2022 15:12:31 +0000
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary="=_vJdw11kZDJmjOszNuerkiEQV-e-HOXcAv7D0VtuwLzXwFbBU"

--=_vJdw11kZDJmjOszNuerkiEQV-e-HOXcAv7D0VtuwLzXwFbBU
Content-Type: text/plain

plain text body

--=_vJdw11kZDJmjOszNuerkiEQV-e-HOXcAv7D0VtuwLzXwFbBU
Content-Type: text/html

html body
--=_vJdw11kZDJmjOszNuerkiEQV-e-HOXcAv7D0VtuwLzXwFbBU--

I.e., when the message has a body, your MUA creates a multipart/alternative message with text/plain and text/html alternatives and when there is no body text, your MUA creates a text/html message with an empty body.

The issue then is MailScanner adds the signature part without ensuring the message is multipart. It sort of works if the original message is multipart alternative, but it looks like MailScanner adds the signature creating a message like:

Date: Fri, 25 Nov 2022 15:08:12 +0000
Mime-Version: 1.0
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable

This is a multi-part message in MIME format...
------------669401123-23310-0
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable

MailScanner Signature

------------669401123-23310-0
Content-Type: image/jpeg; name="signature.jpg"
Content-Disposition: inline; filename="signature.jpg"
Content-Transfer-Encoding: base64
Content-ID: /9j/4AAQSkZJRgABAQEAeAB4AAD/4QDaRXhpZgAATU0AKgAAAAgABgMBAAUA

whereas the proper message should be like:

Date: Fri, 25 Nov 2022 15:08:12 +0000
Mime-Version: 1.0
Content-Type: multipart mixed; boundary="----------669401123-23310-0"

This is a multi-part message in MIME format...
------------669401123-23310-0
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable

------------669401123-23310-0
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable

MailScanner Signature

------------669401123-23310-0
Content-Type: image/jpeg; name="signature.jpg"
Content-Disposition: inline; filename="signature.jpg"
Content-Transfer-Encoding: base64
Content-ID: /9j/4AAQSkZJRgABAQEAeAB4AAD/4QDaRXhpZgAATU0AKgAAAAgABgMBAAUA

------------669401123-23310-0--

But without seeing the complete raw message from MailScanner, I can't say for sure.

moosty-moo commented 1 year ago

Hi, Many thanks for the response. I failed to mention that the problem doesn't exist in version 4.84.5. I had upgraded to 5.4.5 and the problem was noticed.

It seems to be a result of:

https://github.com/MailScanner/v5/issues/607

This is the source queue file before being processed by MailScanner 5.4.5

V8
T1669550327
K0
N0
P30963
Fbs
$_localhost.domain.local [127.0.0.1]
$rESMTP
$sdevel-vm.domain.local
${daemon_flags}
S<chris@domain.local>
rRFC822; chris@domain.local
RPFD:<chris@domain.local>
H?P?Return-Path: <~Ag>
H??Received: from devel-vm.domain.local (localhost.domain.local [127.0.0.1])
    by devel-vm.domain.local (8.16.1/8.16.1) with ESMTP id 2ARBwlo1019845
    for <chris@domain.local>; Sun, 27 Nov 2022 11:58:47 GMT
H?x?Full-Name: Christopher Moore
H??Received: by devel-vm.domain.local (kopano-spooler) with MAPI; Sun, 27 Nov
 2022 11:58:47 +0000
H??Subject: Sig Test
H??From: "Christopher Moore" <chris@domain.local>
H??To: "Christopher Moore" <chris@domain.local>
H??Date: Sun, 27 Nov 2022 11:58:47 +0000
H??Mime-Version: 1.0
H??Content-Type: text/html; charset=utf-8
H??Content-Transfer-Encoding: quoted-printable
H??X-Priority: 3 (Normal)
H??X-Mailer: Kopano 8.7.16
H??Message-Id: <kcEE.ZvpSnA1bSnSxSGz9YUHmwQ.gLX/mlcC2QE@devel-vm.domain.local>

This is the queue file after being processed - this will display the garbled email

V8
T1669550327
K0
N0
P30963
Fbs
$_localhost.domain.local [127.0.0.1]
$rESMTP
$sdevel-vm.domain.local
${daemon_flags}
S<chris@domain.local>
rRFC822; chris@domain.local
RPFD:<chris@domain.local>
H?P?Return-Path: <~Ag>
H??Received: from devel-vm.domain.local (localhost.domain.local [127.0.0.1])
    by devel-vm.domain.local (8.16.1/8.16.1) with ESMTP id 2ARBwlo1019845
    for <chris@domain.local>; Sun, 27 Nov 2022 11:58:47 GMT
H?x?Full-Name: Christopher Moore
H??Received: by devel-vm.domain.local (kopano-spooler) with MAPI; Sun, 27 Nov
 2022 11:58:47 +0000
H??Subject: Sig Test
H??From: "Christopher Moore" <chris@domain.local>
H??To: "Christopher Moore" <chris@domain.local>
H??Date: Sun, 27 Nov 2022 11:58:47 +0000
H??Mime-Version: 1.0
H??Content-Type: text/html; charset=utf-8
H??Content-Transfer-Encoding: quoted-printable
H??X-Priority: 3 (Normal)
H??X-Mailer: Kopano 8.7.16
H??Message-Id: <kcEE.ZvpSnA1bSnSxSGz9YUHmwQ.gLX/mlcC2QE@devel-vm.domain.local>
HX-1047330220-MailScanner-Information: Please contact your Email administrator for more information
HX-1047330220-MailScanner-ID: 2ARBwlo1019845
HX-1047330220-MailScanner: Found to be clean
HX-1047330220-MailScanner-MCPCheck:
HX-1047330220-MailScanner-SpamCheck:
HX-1047330220-MailScanner-From: chris@domain.local
HX-1047330220-MailScanner-Watermark: 1670155322.173@Gsyp4c0ZWkt7ropxLYWZ0A
HX-Spam-Status: No
.

This is the same source queue file, above, after being processed via MailScanner 5.4.5 with #https://github.com/MailScanner/v5/issues/607 removed

  #  if ($this->{headermodified}) {
    $global::MS->{mta}->AddHeadersToQf($this, $this->{entity}->stringify_header);
  #  } else {
  #    $global::MS->{mta}->AddHeadersToQf($this);
  #  }

This will go on to render correcly.

V8
T1669550327
K0
N0
P30963
Fbs
$_localhost.domain.local [127.0.0.1]
$rESMTP
$sdevel-vm.domain.local
${daemon_flags}
S<chris@domain.local>
rRFC822; chris@domain.local
RPFD:<chris@domain.local>
H?P?Return-Path: <~Ag>
H??Received: from devel-vm.domain.local (localhost.domain.local [127.0.0.1])
    by devel-vm.domain.local (8.16.1/8.16.1) with ESMTP id 2ARBwlo1019845
    for <chris@domain.local>; Sun, 27 Nov 2022 11:58:47 GMT
H?x?Full-Name: Christopher Moore
H??Received: by devel-vm.domain.local (kopano-spooler) with MAPI; Sun, 27 Nov
 2022 11:58:47 +0000
H??Subject: Sig Test
H??From: "Christopher Moore" <chris@domain.local>
H??To: "Christopher Moore" <chris@domain.local>
H??Date: Sun, 27 Nov 2022 11:58:47 +0000
H??Mime-Version: 1.0
H??X-Priority: 3 (Normal)
H??X-Mailer: Kopano 8.7.16
H??Message-Id: <kcEE.ZvpSnA1bSnSxSGz9YUHmwQ.gLX/mlcC2QE@devel-vm.domain.local>
H??Content-type: multipart/related; boundary="----------=_1669557803-1345-0"
HX-1047330220-MailScanner-Information: Please contact your Email administrator for more information
HX-1047330220-MailScanner-ID: 2ARBwlo1019845
HX-1047330220-MailScanner: Found to be clean
HX-1047330220-MailScanner-MCPCheck:
HX-1047330220-MailScanner-SpamCheck:
HX-1047330220-MailScanner-From: chris@domain.local
HX-1047330220-MailScanner-Watermark: 1670162599.80371@k3XTl/Y3G79JxEyj7TX/Tw
HX-Spam-Status: No
.
shawniverson commented 1 year ago

Looks like we need to stringify your header in your case as well. Working on tracking down...

moosty-moo commented 1 year ago

Fantastic. Give me a shout if you also need the sendmail queue data file(s).

moosty-moo commented 1 year ago

Tested and working fine.