#23530 [Opn]: Mail_Mime image URL replacement error
| From: | arnaud@php.net | Date: | Mon, 26 May 2003 13:56:44 +0000 |
| Subject: | #23530 [Opn]: Mail_Mime image URL replacement error | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-16712@lists.php.net to get a copy of this message | ||
ID: 23530
Updated by: arnaud@php.net
Reported By: pear-bugs-NOSPAM-7may2003 at ryandesign dot com
Status: Open
Bug Type: PEAR related
Operating System: Linux
PHP Version: 4.3.2RC1
New Comment:
who is maintaining Mail_Mime now ?
Previous Comments:
------------------------------------------------------------------------
[2003-05-07 12:33:35] pear-bugs-NOSPAM-7may2003 at ryandesign dot com
Hello. I've been spending the day playing with sending MIME email with
included HTML images, using the Mail_Mime part of PEAR. I've run into
two bugs, which both have the same fix.
Suppose I try to send an HTML mail with the following source:
<img src="image.gif">
This image is called image.gif.
<p>
<img src="another_image.gif">
This image is called another_image.gif.
Suppose that I attach the two images using addHTMLImage, and that I do
so in the order in which they're specified in the source -- "image.gif"
first, "another_image.gif" second. When I send the message, the HTML
will have been translated like, for example, this:
<img src=3D"cid:6a7258f7707824eb9df3e93d8983fc64">
This image is called cid:6a7258f7707824eb9df3e93d8983fc64.
<p>
<img src=3D"another_cid:6a7258f7707824eb9df3e93d8983fc64">
This image is called another_cid:6a7258f7707824eb9df3e93d8983fc64.
You can immediately see that there are two things wrong. First, it has
replaced occurrences of the image name within the text with the CID
tag. This should not be done. It should only replace the image names
where they occur within a "src" or "background" attribute of a tag, or
a "url" function in a stylesheet, or similar.
Second, you can see that because the name of the first image was
contained within the name of the second image, the second image has
been destroyed.
Here's the culprit. At the beginning of the "get" function in Mime.php
there are lines that look like this:
if (!empty($this->_html_images) AND isset($this->_htmlbody)) {
foreach ($this->_html_images as $value) {
$this->_htmlbody = str_replace($value['name'],
'cid:'.$value['cid'], $this->_htmlbody);
}
}
The replace is much too general. I would suggest replacing using a
regular expression. Something like this:
$this->_htmlbody = preg_replace(
'/(\s+(?:src|background))\s*=\s*(?:"' .
$value['name'] . '"|' . $value['name'] .
')(?=[\s>])/si',
'$1="cid:' . $value['cid'] . '"',
$this->_htmlbody
);
Of course this doesn't take care of the "url" function notation that
can be used in CSS and there may be other considerations.... but I
think it's a better method than the one currently in place.
For now, users can use a workaround for the second point: make an array
of images you want to add, sort it in descending order by length, and
then use the addHTMLImage function on each element of the array.
You can email me at pear bug report 7 may 2003 at ryan design dot com.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=23530&edit=1