DataObjects/core.sql
[Pman.Core] / Mailer.php
index 8fc6021..c7417c3 100644 (file)
@@ -172,7 +172,7 @@ class Pman_Core_Mailer {
             //exit;
         } 
         
-        $isMine = false;
+        $isMime = false;
         
         require_once 'Mail/mime.php';
         $mime = new Mail_mime(array(
@@ -208,33 +208,40 @@ class Pman_Core_Mailer {
                     $cdata['contentid']
                 );
             }
-            $isMine = true;
+            $isMime = true;
         }
         
-        if($this->attachments){
+        if(!empty($this->attachments)){
             //if got a attachments
-            
             $header = $mime->headers($parts[1]);
             
-            if(preg_match('/text\/html/', $header['Content-Type'])){
-                $mime->setHTMLBody($parts[2]);
-            }else{
-                $mime->setTXTBody($parts[2]);
+            if (isset($parts[1]['Content-Type'])) {
+                unset($parts[1]['Content-Type']);
             }
             
+            if (!$isMime) {
+            
+                if(preg_match('/text\/html/', $header['Content-Type'])){
+                    $mime->setHTMLBody($parts[2]);
+                    $mime->setTXTBody('This message is in HTML only');
+                }else{
+                    $mime->setTXTBody($parts[2]);
+                    $mime->setHTMLBody('<PRE>'.htmlspecialchars($parts[2]).'</PRE>');
+                }
+            }
             foreach($this->attachments as $attch){
                 $mime->addAttachment(
                         $attch['file'],
                         $attch['mimetype'],
-                        $attch['name'],
-                        false
+                        (!empty($attch['name'])) ? $attch['name'] : '',
+                        true
                 );
             }
             
-            $isMine = true;
+            $isMime = true;
         }
         
-        if($isMine){
+        if($isMime){
             $parts[2] = $mime->get();
             $parts[1] = $mime->headers($parts[1]);
         }