Bug #16623 [Opn]: When sending mails with attachments, the same boundaries are used
| From: | mk at digitaleprodukte dot de | Date: | Thu, 17 Sep 2009 17:36:14 +0000 |
| Subject: | Bug #16623 [Opn]: When sending mails with attachments, the same boundaries are used | ||
| References: | 1 | Groups: | php.pear.bugs |
| Request: | Send a blank email to pear-bugs+get-1665@lists.php.net to get a copy of this message | ||
Edit report at http://pear.php.net/bugs/bug.php?id=16623&edit=1
ID: 16623
Updated by: mk@digitaleprodukte.de
Reported By: mk at digitaleprodukte dot de
Summary: When sending mails with attachments, the same
boundaries are used
Status: Open
Type: Bug
Package: Mail_Mime
Operating System: Debian Lenny
Package Version: 1.5.2
PHP Version: 5.2.5
Roadmap Versions:
New Comment:
There was a small bug in my workaround, now the correct version
($bounderyNew =
md5($boundary);):
<code>
$mailBody = $mime->get($_build_params);
$mailHeaders = $mime->headers($mailHeaders);
// Workaround, because, if attachments exist the same boundary is used
for several e-mail parts
if (sizeof($this->attachments) > 0) {
preg_match("/boundary=\"(.[^\"]*)\"/e", $mailHeaders["Content-
Type"], $boundary);
$boundary = $boundary[1];
$bounderyNew = md5($boundary);
$mailHeaders["Content-Type"] =
preg_replace('/boundary="(.[^"]*)"/', 'boundary="' .
$bounderyNew .
'"', $mailHeaders["Content-Type"]);
$mailBody = preg_replace("/^\-\-" . $boundary . "/s", "--" .
$bounderyNew, $mailBody);
$mailBody = preg_replace("/" . $boundary . "--$/s", $bounderyNew
. "--", $mailBody);
$mailBody = preg_replace("/" . $boundary . "--(\s*)--" . $boundary
. "/s", $boundary . "--$1--" .
$bounderyNew, $mailBody);
}
$mail =& Mail::factory($this->backend, $this->backendParams);
</code>
Previous Comments:
------------------------------------------------------------------------
[2009-09-17 18:09:05] markusknaup
Description:
------------
I had problems, when attaching a file to an e-mail:
<code>
$mime = new Mail_mime("\n");
$mime->setTXTBody($txtBody);
$mime->setHTMLBody($htmlBody);
if (is_array($attachments)) {
foreach($attachments as $attachment) {
$mime->addAttachment($attachment["file"],
$attachment["contentType"], $attachment["name"],
$attachment["isFile"], $attachment["encoding"]);
}
}
$mailBody = $mime->get($_build_params);
$mailHeaders = $mime->headers($mailHeaders);
$mail =& Mail::factory($this->backend, $this->backendParams);
$mail->send($this->recip, $mailHeaders, $mailBody);
</code>
In this use case the mail was sent, but nearly all webmailers and
e-mail
programs did not show the
attachment(s). I analysed the source code of the sent e-mails and I saw
that the same boundaries were used
for different e-mail parts (here "_d188467fafaf9f24df2e4585a2d76019"):
<code>
To: [E-MAIL-ADDRESS]
Subject: [SUBJECT]
MIME-Version: 1.0
From: [ANOTHER E-MAIL-ADDRESS]
Content-Type: multipart/mixed;
boundary="=_d188467fafaf9f24df2e4585a2d76019"
Date: Thu, 17 Sep 2009 17:37:41 +0200 (CEST)
--_d188467fafaf9f24df2e4585a2d76019
Content-Type: multipart/alternative;
boundary="=_d188467fafaf9f24df2e4585a2d76019"
--=_d188467fafaf9f24df2e4585a2d76019
Content-Transfer-Encoding: base64
Content-Type: text/plain; charset="utf-8"
[CONTENT]
--=_d188467fafaf9f24df2e4585a2d76019
Content-Transfer-Encoding: base64
Content-Type: text/html; charset="utf-8"
[CONTENT]
--=_d188467fafaf9f24df2e4585a2d76019--
--=_d188467fafaf9f24df2e4585a2d76019
Content-Transfer-Encoding: base64
Content-Type: application/pdf;
name="file.pdf";
Content-Disposition: attachment;
filename="file.pdf";
[CONTENT]
--_d188467fafaf9f24df2e4585a2d76019--
</code>
So, I wrote a simple (not optimal) workaround, but this should be fixed
somehow in Mail_mime (if it is a bug):
<code>
$mailBody = $mime->get($_build_params);
$mailHeaders = $mime->headers($mailHeaders);
// Workaround, because, if attachments exist the same boundary is used
for several e-mail parts
if (sizeof($this->attachments) > 0) {
preg_match("/boundary=\"(.[^\"]*)\"/e", $mailHeaders["Content-
Type"], $boundary);
$boundary = $boundary[1];
$bounderyNew = $bounderyNew;
$mailHeaders["Content-Type"] =
preg_replace('/boundary="(.[^"]*)"/', 'boundary="' .
$bounderyNew .
'"', $mailHeaders["Content-Type"]);
$mailBody = preg_replace("/^\-\-" . $boundary . "/s", "--" .
$bounderyNew, $mailBody);
$mailBody = preg_replace("/" . $boundary . "--$/s", $bounderyNew
. "--", $mailBody);
$mailBody = preg_replace("/" . $boundary . "--(\s*)--" . $boundary
. "/s", $boundary . "--$1--" .
$bounderyNew, $mailBody);
}
$mail =& Mail::factory($this->backend, $this->backendParams);
</code>
This changes the boundary of the toplevel e-mail parts.
------------------------------------------------------------------------
--
Edit this bug report at http://pear.php.net/bugs/bug.php?id=16623&edit=1