#23530 [NEW]: Mail_Mime image URL replacement error
| From: | pear-bugs-NOSPAM-7may2003 at ryandesign dot com | Date: | Wed, 07 May 2003 17:33:35 +0000 |
| Subject: | #23530 [NEW]: Mail_Mime image URL replacement error | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-16034@lists.php.net to get a copy of this message | ||
From: pear-bugs-NOSPAM-7may2003 at ryandesign dot com
Operating system: Linux
PHP version: 4.3.2RC1
PHP Bug Type: PEAR related
Bug description: Mail_Mime image URL replacement error
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 bug report at http://bugs.php.net/?id=23530&edit=1
--
Try a CVS snapshot: http://bugs.php.net/fix.php?id=23530&r=trysnapshot
Fixed in CVS: http://bugs.php.net/fix.php?id=23530&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=23530&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=23530&r=needtrace
Try newer version: http://bugs.php.net/fix.php?id=23530&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=23530&r=support
Expected behavior: http://bugs.php.net/fix.php?id=23530&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=23530&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=23530&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=23530&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=23530&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=23530&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=23530&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=23530&r=gnused