|
本帖最后由 demo 于 2014-2-12 15:04 编辑
I managed to get around this and successfully deal with this image looping & image naming process by using a recently published class found here:
http://www.electrict...ge-attachments/
and followed up that class by using it as an include in the script that creates variables such as $text_part, $html_part, and wrote the following:- /**** The below sequence manages IMAGE Tags in E-mail are supplied by direct URL links ****/
- if (preg_match_all('/<img\s+([^>]*)src="http(s)?:\/\/(.*)"/i', $emailMessage->bodyHTML, $matches)) {
- echo '<br />Detected E-mail Client uses URL links for image tags...continuing News from Mail session<br />';
- }
-
- /**** The below sequence manages IMAGE Tags in E-mail are supplied by attachments ****/
- if (preg_match_all('/src="cid:(.*)"/Uims', $emailMessage->bodyHTML, $matches)) {
-
- if(count($matches)) {
- $search = array();
- $replace = array();
-
- $num_img = sizeof($emailMessage->attachments);
-
- for($i = 1; $i <= $num_img; $i++){
-
- foreach($matches[1] as $match) {
-
- $matchExt = $emailMessage->attachments[$match]['subtype'];
- $fnameExt = (string)$matchExt;
- $fnameExt = strtolower($fnameExt);
- $uniqueFilename = "image$i.$fnameExt";
- $i++;
- file_put_contents("$dirname/$uniqueFilename", $emailMessage->attachments[$match]['data']);
- $search[] = "src="cid:$match"";
- $replace[] = "src="$dirname/$uniqueFilename"";
- }
- $emailMessage->bodyHTML = str_ireplace($search, $replace, $emailMessage->bodyHTML);
- }
- }
- }
-
- /**** The below sequence manages IMAGE Tags in E-mail are supplied by inline image data ****/
-
- if(preg_match_all('/src="data:(image\/(.*);.*,(.*))"/Uims', $emailMessage->bodyHTML, $basematches)) {
- $img_num = sizeof($basematches[2]);
- if(count($basematches[3])) {
-
- $search = array();
- $replace = array();
-
- for($i = 1; $i <= $img_num; $i++) {
-
- foreach($basematches[3] as $base64data) {
-
- $uniqueFilename = "$dirname/image".$i.".png";
- $i++;
- $base64data_decoded = base64_decode($base64data);
- $imCreate = imagecreatefromstring($base64data_decoded);
- if ($imCreate !== false) {
- imagepng($imCreate, $uniqueFilename);
- imagedestroy($imCreate);
- }
- $search[] = "$base64data"";
- $replace[] = "$uniqueFilename"";
- }
- $emailMessage->bodyHTML = str_ireplace($search, $replace, $emailMessage->bodyHTML);
- $emailMessage->bodyHTML = preg_replace("/data:image\/(jpeg|png|bmp|gif);base64,/i", "", $emailMessage->bodyHTML);
- }
- }
- }
复制代码
I am kind of worried about using all that regex to parse this HTML as opposed to finding a DOMDocument solution, but through my research i haven't seen anything that DOMDocuments can do to that length as opposed to PCRE functions. The best one can do is include as many 'possible modifiers' as you can.
I'm just trying to get around another bug where Apple iPhone's standard Mail app splits messages in different parts because of inline attachments, i proved this with some testing.
An example:
--Apple-Mail-1-577088534
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset="us-ascii"
Title: iPhone Email=0A=
Snippet: iPhone Test=0A=
Tags: iphone=2Cemail=2Cpictures=0A=
Category: Member=0A=
Message:=0A=
Brothers and sisters have I none but this man's father is my father's son.=
=0A=
=0A=
--Apple-Mail-1-577088534
Content-Disposition: inline; filename="image.png"
Content-Type: image/png; name="image.png"
Content-Transfer-Encoding: base64
iVBORw0KGgoAAAANSUhEUgAAAUAAAAHgCAYAAADUjLREAAAgAElEQVR4AeydB3xUVfbHTzpJCITe
mwgIWEBRFARBV117WxVde11X176WXeuuZdUt6t+1u4oFe8MK9opiQRAUadJ7S0hIz/zP94YbXh5v
--Apple-Mail-1-577088534
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset="us-ascii"
=0A=
=0A=
Brothers and sisters have I none but this man's father is my father's son.=
=0A=
--Apple-Mail-1-577088534
Content-Disposition: inline; filename="image.jpeg"
Content-Type: image/jpeg; name="image.jpeg"
Content-Transfer-Encoding: base64
/9j/4AAQSkZJRgABAQAAAQABAAD/4gxYSUNDX1BST0ZJTEUAAQEAAAxITGlubwIQAABtbnRyUkdC
IFhZWiAHzgACAAkABgAxAABhY3NwTVNGVAAAAABJRUMgc1JHQgAAAAAAAAAAAAAAAQAA9tYAAQAA
--Apple-Mail-1-577088534
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset="us-ascii"
Brothers and sisters have I none but this man's father is my father's son.=
=0A=
--Apple-Mail-1-577088534
Content-Disposition: inline; filename="image.jpeg"
Content-Type: image/jpeg; name="image.jpeg"
Content-Transfer-Encoding: base64
/9j/4AAQSkZJRgABAQEAYABgAAD/4gxYSUNDX1BST0ZJTEUAAQEAAAxITGlubwIQAABtbnRyUkdC
IFhZWiAHzgACAAkABgAxAABhY3NwTVNGVAAAAABJRUMgc1JHQgAAAAAAAAAAAAAAAQAA9tYAAQAA
--Apple-Mail-1-577088534
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset="us-ascii"
Brothers and sisters have I none but this man's father is my father's son.=
=0A=
--Apple-Mail-1-577088534
Content-Disposition: inline; filename="image.jpeg"
Content-Type: image/jpeg; name="image.jpeg"
Content-Transfer-Encoding: base64
/9j/4AAQSkZJRgABAQEASABIAAD/4QI2RXhpZgAATU0AKgAAAAgACgEPAAIAAAAGAAAAhgEQAAIA
AAALAAAAjAESAAMAAAABAAYAAAEaAAUAAAABAAAAmAEbAAUAAAABAAAAoAEoAAMAAAABAAIAAAEx
--Apple-Mail-1-577088534
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset="us-ascii"
Brothers and sisters have I none but this man's father is my father's son.=
=0A=
=0A=
Brothers and sisters have I none Inline image:=
--Apple-Mail-1-577088534
Content-Disposition: inline; filename="image.jpeg"
Content-Type: image/jpeg; name="image.jpeg"
Content-Transfer-Encoding: base64
/9j/4AAQSkZJRgABAQEASABIAAD/4QI2RXhpZgAATU0AKgAAAAgACgEPAAIAAAAGAAAAhgEQAAIA
AAALAAAAjAESAAMAAAABAAYAAAEaAAUAAAABAAAAmAEbAAUAAAABAAAAoAEoAAMAAAABAAIAAAEx
--Apple-Mail-1-577088534
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset="us-ascii"
but this man's father is my father's son.=
--Apple-Mail-1-577088534--
The email contained multiple lines of the same words where as i just inserted pictures amongst them, and also concluded that the client doesn't use <img> tags, (EXCEPT for when forwarding process, then the client uses <img> tags).
|
|