Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.10.12

Bug #2835 str_replace bug in Mail_mime::&get() /w Patch
Submitted: 2004-11-26 18:05 UTC
From: tacker Assigned: sean
Status: Closed Package: Mail_Mime
PHP Version: Irrelevant OS: Irrelevant
Roadmaps: (Not assigned)    
Subscription  


 [2004-11-26 18:05 UTC] tacker
Description: ------------ Simple str_replace used in /usr/lib/php/Mail/mime.php:433 causes '116.jpg' beeing replaced by cid from '16.jpg' resulting in broken link '1cid:a23708b2617778442151d856dd7151b6' Reproduce code: --------------- --- dl/mime.php 2004-11-26 18:59:43.904791016 +0100 +++ /usr/lib/php/Mail/mime.php 2004-11-26 18:58:38.394750056 +0100 @@ -429,11 +429,23 @@ } 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); + // Sort by string length of filename to fix + // '116.jpg' beeing replaced by cid from '16.jpg' + // resulting in broken link '1cid:a23708b2617778442151d856dd7151b6' + $images_sorted = array(); + foreach ($this->_html_images as $image_key => $value) { + $images_sorted[strlen($value['name'])][] = $image_key; + } + krsort($images_sorted); + foreach ($images_sorted as $image_ids) { + foreach ($image_ids as $image_key) { + $value = $this->_html_images[$image_key]; + $this->_htmlbody = str_replace($value['name'], 'cid:'.$value['cid'], $this->_htmlbody); + } } } + $null = null; $attachments = !empty($this->_parts) ? TRUE : FALSE; $html_images = !empty($this->_html_images) ? TRUE : FALSE;

Comments

 [2004-12-13 15:06 UTC] pear-bug-2835 at ryandesign dot com
There is a second related problem that I reported 18 months ago that should also be fixed. Please see: http://bugs.php.net/bug.php?id=23530
 [2004-12-13 15:09 UTC] sean
Please report a single issue per bug report. Otherwise, bugs become impossible to maintain (ie, there is no "half resolved", or "partial feedback" status.) S
 [2005-01-16 01:24 UTC] sean
This bug has been fixed in CVS. In case this was a documentation problem, the fix will show up at the end of next Sunday (CET) on pear.php.net. In case this was a pear.php.net website problem, the change will show up on the website in short time. Thank you for the report, and for helping us make PEAR better.