Mailer.php
[Pman.Core] / Mailer.php
index 7086962..832b6b9 100644 (file)
@@ -171,7 +171,7 @@ class Pman_Core_Mailer {
             // for the html body, we may want to convert the attachments to images.
 //            var_dump($htmlbody);exit;
             
-            if($content->body_cls && strlen($content->body_cls)){
+            if(!empty($content->body_cls) && strlen($content->body_cls)){
                 $htmlbody = $this->htmlbodySetClass($htmlbody, $content->body_cls);
             }
             
@@ -386,6 +386,8 @@ class Pman_Core_Mailer {
         @$dom->loadHTML('<?xml encoding="UTF-8">' .$html);
         $imgs= $dom->getElementsByTagName('img');
         
+        $urls = array();
+        
         foreach ($imgs as $i=>$img) {
             $url  = $img->getAttribute('src');
             if (preg_match('#^cid:#', $url)) {
@@ -396,13 +398,36 @@ class Pman_Core_Mailer {
                 continue;
             }
             
-            $conv = $this->fetchImage($url);
-            $this->images[$conv['contentid']] = $conv;
+            if(!array_key_exists($url, $urls)){
+                $conv = $this->fetchImage($url);
+                $urls[$url] = $conv;
+                $this->images[$conv['contentid']] = $conv;
+            } else {
+                $conv = $urls[$url];
+            }
             
             $img->setAttribute('src', 'cid:' . $conv['contentid']);
+        }
+        
+        /*
+        foreach ($imgs as $i=>$img) {
+            $url  = $img->getAttribute('src');
+            if (preg_match('#^cid:#', $url)) {
+                continue;
+            }
+            $me = $img->getAttribute('mailembed');
+            if ($me == 'no') {
+                continue;
+            }
             
+            $conv = $this->fetchImage($url);
+            $this->images[$conv['contentid']] = $conv;
             
+            $img->setAttribute('src', 'cid:' . $conv['contentid']);
         }
+        * 
+        */
+        
         return $dom->saveHTML();
         
         
@@ -502,7 +527,7 @@ class Pman_Core_Mailer {
         
         $class = $dom->createAttribute('class');
         $class->value = $cls;
-        $body->appendChild($class);
+        $body->item(0)->appendChild($class);
         
         return $dom->saveHTML();
     }