Open vlk-charles opened 3 weeks ago
Also I just noticed that Content-Transfer-Encoding: 8bit
is also only present in mail1.log
. This is allowed for multipart/mixed
as it is one of the "identity" encodings. If the value is taken from the first part however, this could easily end up being one of the transformative encodings (quoted-printable
or base64
). That is not allowed.
If transformative encoding is set on the first part like so:
$mailMessage1 = new Laminas\Mail\Message();
$mailMessage2 = new Laminas\Mail\Message();
$mimeMessage = new Laminas\Mime\Message();
$mimeMessage->addPart((new Laminas\Mime\Part('part one'))->setType('text/plain')->setCharset('UTF-8')->setEncoding(Laminas\Mime\Mime::ENCODING_BASE64));
$mailMessage1->setBody($mimeMessage);
$mimeMessage->addPart((new Laminas\Mime\Part('part two'))->setFileName('attachment.txt')->setDisposition(Laminas\Mime\Mime::DISPOSITION_ATTACHMENT));
$mailMessage1->setBody($mimeMessage);
$mailMessage2->setBody($mimeMessage);
$transport = new Laminas\Mail\Transport\File(new Laminas\Mail\Transport\FileOptions(['path' => '/tmp', 'callback' => function() {return 'mail1.log';}]));
$transport->send($mailMessage1);
$transport->getOptions()->setCallback(function() {return 'mail2.log';});
$transport->send($mailMessage2);
mailMessage1
is now completely broken:
for i in 1 2; do head -n 6 </tmp/mail$i.log; echo; done
Date: Sat, 24 Aug 2024 00:15:40 +0000
MIME-Version: 1.0
Content-Type: multipart/mixed;
charset="UTF-8";
boundary="=_526f145ae69cd5c075e04bf74285380d"
Content-Transfer-Encoding: base64
Date: Sat, 24 Aug 2024 00:15:40 +0000
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="=_526f145ae69cd5c075e04bf74285380d"
This is a message in Mime Format. If you see this, your mail reader does not support this format.
Basically calling setBody
more than once has unexpected results.
I think simply adding
$this->clearHeaderByName('content-type');
$this->clearHeaderByName('content-transfer-encoding');
before this line would pretty much solve it.
Bug Report
Summary
If a
Mail\Message
had a single-part body previously andsetBody()
is called again with a multi-partMime\Message
, theContent-Type
gets changed tomultipart/mixed
but the additionalparameters
such ascharset
are kept. I don't thinkcharset
is allowed onmultipart/mixed
or at least it doesn't make much sense.Current behavior
How to reproduce
Note that
mailMessage2->setBody
was only called at the end and has therefore nocharset
whereasmailMessage1->setBody
was also called intermediately and hascharset="UTF-8"
set.Expected behavior