| Recommend this page to a friend! |
| PHP MIME Email Message Parser | > | All threads | > | embedded/inline images not showing | > | (Un) Subscribe thread alerts |
| |||||||||||||||
Hello,
To begin with, excellent scripts!! kudos! I've managed to get everything working as expected, yet, today when making a test, i found out that embedded images (the ones you insert in outlook or any email program working in html mode by using "insert" as oppposed to "attach") are not showing at all. They do show up in both arrays (results & decoded) as beeing there, but they dont show up when echoing $results['Data'], they just show as broken images.. Excerpt from var_dump($results) : array(11) { ["Type"]=> string(4) "html" ["Description"]=> string(12) "HTML message" ["Encoding"]=> string(10) "iso-8859-1" ["Data"]=> string(16956) "--- On Thu, 3/19/09, ---- wrote: ---- From: -----" ["Related"]=> array(2) { [0]=> array(7) { ["Type"]=> string(5) "image" ["SubType"]=> string(4) "jpeg" ["Description"]=> string(29) "Image file in the JPEG format" ["Data"]=> string(24626) "HERE GOES THE EMBEDDED FILE .. I REMOVED IT FOR PRACTICAL REASONS (IT DISPLAYS AS GARBAGE)" ["FileName"]=> string(12) "image001.jpg" ["FileDisposition"]=> string(6) "inline" ["ContentID"]=> string(40) "[email protected]" } -------- Echo var_dump($decoded[0]) : array(3) { ["Headers"]=> array(19) { ["return-path:"]=> string(20) "" ["envelope-to:"]=> string(23) "[email protected]" ["delivery-date:"]=> string(31) "Fri, 20 Mar 2009 03:25:37 +0000" ["received:"]=> array(3) { [0]=> string(209) "from web33406.mail.mud.yahoo.com ([68.142.206.138])by nserver.nstiac.com with smtp (Exim 4.69)(envelope-from )id 1LkVMS-00040a-3yfor [email protected]; Fri, 20 Mar 2009 03:25:37 +0000" [1]=> string(62) "(qmail 35807 invoked by uid 60001); 20 Mar 2009 03:25:30 -0000" [2]=> string(93) "from [201.139.146.247] by web33406.mail.mud.yahoo.com via HTTP; Thu, 19 Mar 2009 20:25:30 PDT" } ["dkim-signature:"]=> string(388) "v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1237519530; bh=JfTWpQryr6NC01lXsiHSvurbxwKP9UfKO7W8DINTXAI=; h=Message-ID:X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:MIME-Version:Content-Type; b=WPsGlpmmqS8AxdSsAE7GtN6kujAyw3OgD4odLmJkqsipG7kpim0ujMhdM0b39vUh3XH8x3LJeLKqWIeLj5X52tQEuyVSVR9myiqOX1OgRYH3LcswsMNweabcqHwpVxiY+E/f8ANgWEBLdfxxLaWfpeEhUaH+2HIhGz3ZFxOOvo8=" ["domainkey-signature:"]=> string(316) "a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:MIME-Version:Content-Type; b=mUAsEmOzQCr6rX9NPqJt7h82ou0mjGMHPjFwkI+j08NeGs27Cgok8tFly6qrnTw4KIHoj0Sztiv2i4RBfQ/RhiZ83oq2iCxXCWlb930zCGJzxUpcFnz9gCIX0fW5Dk4vX9rXmR8QWAFAvne5SnyXTrhLy5WpdWg1buNvRtqXY/o=;" ["message-id:"]=> string(45) "<[email protected]>" ["x-ymail-osg:"]=> string(208) "DH64jtcVM1kVt3RGInb_kKXhl.zDdva4kZiT5FcqISYQEh2iqQsMI_bKfsNc7S99N8N8TfgULK4_zbGryzQoZoeX_Xm7jqOgWIBTTvJ.v7iziWSbaeYB_Cet6BV1ik5AQ.wa9rEIvhM_qMWWOkJqEK8ObMiqt_RmvS8M4OGxqg4oQur7r6DvTDXndG0EH7.YcWd2mWL_4HtHRZM-" ["x-mailer:"]=> string(53) "YahooMailClassic/5.1.20 YahooMailWebService/0.7.289.1" ["date:"]=> string(37) "Thu, 19 Mar 2009 20:25:30 -0700 (PDT)" ["from:"]=> string(35) "xxxxxxx" ["subject:"]=> string(30) "Fw: xxxxxxxxxx" ["to:"]=> string(23) "[email protected]" ["mime-version:"]=> string(3) "1.0" ["content-type:"]=> string(63) "multipart/alternative; boundary="0-937715851-1237519530=:10397"" ["x-spam-status:"]=> string(14) "No, score=-1.9" ["x-spam-score:"]=> string(3) "-18" ["x-spam-bar:"]=> string(1) "-" ["x-spam-flag:"]=> string(2) "NO" } ["Parts"]=> array(2) { [0]=> array(5) { ["Headers"]=> array(2) { ["content-type:"]=> string(30) "text/plain; charset=iso-8859-1" ["content-transfer-encoding:"]=> string(16) "quoted-printable" } ["Parts"]=> array(0) { } ["BodyFile"]=> string(52) "/home/xxxxxxxxxxxxxxxxxxxx/part1" ["BodyPart"]=> int(1) ["BodyLength"]=> int(2041) } [1]=> array(2) { ["Headers"]=> array(1) { ["content-type:"]=> string(60) "multipart/related; boundary="0-1139419408-1237519530=:10397"" } ["Parts"]=> array(3) { [0]=> array(5) { ["Headers"]=> array(2) { ["content-type:"]=> string(29) "text/html; charset=iso-8859-1" ["content-transfer-encoding:"]=> string(16) "quoted-printable" } ["Parts"]=> array(0) { } ["BodyFile"]=> string(52) "/home/xxxxxxxxxxxxxxxxxxxx/part2" ["BodyPart"]=> int(2) ["BodyLength"]=> int(16956) } [1]=> array(7) { ["Headers"]=> array(4) { ["content-type:"]=> string(49) "image/jpeg; x-unix-mode=0666; name="image001.jpg"" ["content-transfer-encoding:"]=> string(6) "base64" ["content-id:"]=> string(42) "<[email protected]>" ["content-disposition:"]=> string(31) "inline; filename="image001.jpg"" } ["Parts"]=> array(0) { } ["FileName"]=> string(12) "image001.jpg" ["FileDisposition"]=> string(6) "inline" ["BodyFile"]=> string(59) "/home/xxxxxxxxxxxxxxxxxxxx/image001.jpg" ["BodyPart"]=> int(3) ["BodyLength"]=> int(24626) } [2]=> array(7) { ["Headers"]=> array(4) { ["content-type:"]=> string(49) "image/jpeg; x-unix-mode=0666; name="image004.jpg"" ["content-transfer-encoding:"]=> string(6) "base64" ["content-id:"]=> string(42) "<[email protected]>" ["content-disposition:"]=> string(31) "inline; filename="image004.jpg"" } ["Parts"]=> array(0) { } ["FileName"]=> string(12) "image004.jpg" ["FileDisposition"]=> string(6) "inline" ["BodyFile"]=> string(59) "/home/xxxxxxxxxxxxxxxxxxxx/image004.jpg" ["BodyPart"]=> int(4) ["BodyLength"]=> int(60061) } } } } ["ExtractedAddresses"]=> array(3) { ["return-path:"]=> array(1) { [0]=> array(1) { ["address"]=> string(18) "[email protected]" } } ["from:"]=> array(1) { [0]=> array(2) { ["address"]=> string(18) "[email protected]" ["name"]=> string(14) "xxxxxxxxx" } } ["to:"]=> array(1) { [0]=> array(1) { ["address"]=> string(23) "[email protected]" } } } }
The part that has the HTML of the message has URLs for the images like this:
cid:some_image_identifier.gif You need to replace those URLs with the URLs of the images parts after decoded.
Hello Manuel,
Thank you for your qui reply. Once again, i have to insist on what an amazing, awesome set of scripts you've created. Now.. how do i do what you suggest for the inline images? I've noticed several posts asking the same question and the same answer is given back by you: "you need to do a script to replace the cid with the url" what is the url for inline images? cant be a http..or an image in my directory since i'm not saving the body parts. Even then, how do i know which body part file belongs to which image?. Is'nt there a way of solving this within the mime_parser class? I dont have the knowledge of doing it, but most email clients do this without any trouble, and with the increasing amount of people using html email i think this would be very useful in your class. Best regards & thank you!
What you need to do is parse your HTML <img> tags and look for those with cid: URLs.
The string after cid: is the content identifier of the image part in the message that is contained in the multipart/alternative message. What you need to do to display the message is to make the class save the body parts to some directory. Then you replace the cid: URLs with an URL of a script that gets the corresponding body part with matching Content-ID: header and serves the image with the respective MIME type defined by the Content-Type: header. Admitedly this is not a trivial thing. Maybe in the future the class will incorporate something to make this an easier task. For now, you need to work out some code to this yourself. |
info at phpclasses dot org.
