gryphonshafer / Email-Mailer

Multi-purpose emailer for HTML, auto-text, attachments, and templates
1 stars 1 forks source link

content-type (well, the charset part) and content-transfer-encoding only work in text only emails #9

Closed mat813 closed 3 years ago

mat813 commented 3 years ago

When an email has only a text part, and no html or attachments, the headers passed get through to the Email::MIME->create level, and it works because the body is directly the text part.

When an attachment is added, the Email::MIME->create bit that generates the text mime part has no headers, and ends up having no content-transfer-encoding nor content-type.

If an HTML part is added, the HTML part has a correct encoding, type and charset, but the text part only has text/plain as the content-type, and it is missing the charset and it has no content-transfer-encoding.

For example:

Email::Mailer->new(
  subject=>"Bob",
  from => "bob\@example.org",
  to=>"bob\@example.org",
  text => "Béton",
  transport => Email::Sender::Transport::Print->new)->send;

Will output:

ENVELOPE TO  : bob@example.org
ENVELOPE FROM: bob@example.org
---------- begin message
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=us-ascii
Message-Id: <16200416780.979D4.11429@aching.in.mat.cc>
From: bob@example.org
Subject: Bob
To: bob@example.org
Date: Mon, 3 May 2021 13:34:38 +0200
MIME-Version: 1.0

B=E9ton=
---------- end message

But if I add an html part:

Email::Mailer->new(
  subject=>"Bob",
  from => "bob\@example.org",
  to=>"bob\@example.org",
  text => "Béton",
  html => "<p>Béton</p>",
  transport => Email::Sender::Transport::Print->new)->send;

The text/plain entry is bad:

ENVELOPE TO  : bob@example.org
ENVELOPE FROM: bob@example.org
---------- begin message
Content-Transfer-Encoding: 7bit
Content-Type: multipart/mixed; boundary=16200417532.cb486De.17773
Message-Id: <16200417530.6e8af7E.17773@aching.in.mat.cc>
From: bob@example.org
Subject: Bob
To: bob@example.org
Date: Mon, 3 May 2021 13:35:53 +0200
MIME-Version: 1.0

--16200417532.cb486De.17773
Date: Mon, 3 May 2021 13:35:53 +0200
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary=16200417531.cac2Cb.17773
Content-Transfer-Encoding: 7bit

--16200417531.cac2Cb.17773
Date: Mon, 3 May 2021 13:35:53 +0200
MIME-Version: 1.0
Content-Type: text/plain

Béton
--16200417531.cac2Cb.17773
Date: Mon, 3 May 2021 13:35:53 +0200
MIME-Version: 1.0
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<p>B=C3=A9ton</p>=

--16200417531.cac2Cb.17773--

--16200417532.cb486De.17773--
---------- end message

If I only add an attachment though:

Email::Mailer->new(
  subject=>"Bob",
  from => "bob\@example.org",
  to=>"bob\@example.org",
  text => "Béton",
  attachments => [{
    source => __FILE__,
  }],
  transport => Email::Sender::Transport::Print->new)->send;

The first text part gets no headers at all:

ENVELOPE TO  : bob@example.org
ENVELOPE FROM: bob@example.org
---------- begin message
Content-Transfer-Encoding: 7bit
Content-Type: multipart/mixed; boundary=16200420391.Af927C9.35338
Message-Id: <16200420390.79a0.35338@aching.in.mat.cc>
From: bob@example.org
Subject: Bob
To: bob@example.org
Date: Mon, 3 May 2021 13:40:39 +0200
MIME-Version: 1.0

--16200420391.Af927C9.35338
Date: Mon, 3 May 2021 13:40:39 +0200
MIME-Version: 1.0

Béton
--16200420391.Af927C9.35338
Date: Mon, 3 May 2021 13:40:39 +0200
MIME-Version: 1.0
Content-Type: application/octet-stream; name=a.pl
Content-Disposition: attachment; filename=a.pl
Content-Transfer-Encoding: base64

cmVxdWlyZSBFbWFpbDo6TWFpbGVyOwpyZXF1aXJlIEVtYWlsOjpTZW5kZXI6OlRyYW5zcG9ydDo6
UHJpbnQ7CgpFbWFpbDo6TWFpbGVyLT5uZXcoCiAgc3ViamVjdD0+IkJvYiIsCiAgZnJvbSA9PiAi
Ym9iXEBleGFtcGxlLm9yZyIsCiAgdG89PiJib2JcQGV4YW1wbGUub3JnIiwKICB0ZXh0ID0+ICJC
w6l0b24iLAogIGF0dGFjaG1lbnRzID0+IFt7CiAgICBzb3VyY2UgPT4gX19GSUxFX18sCiAgfV0s
CiAgdHJhbnNwb3J0ID0+IEVtYWlsOjpTZW5kZXI6OlRyYW5zcG9ydDo6UHJpbnQtPm5ldyktPnNl
bmQ7Cg==

--16200420391.Af927C9.35338--
---------- end message
gryphonshafer commented 3 years ago

Thanks for the bug report. I'll look into this today.