DataObjects/core.sql
[Pman.Core] / Mailer.php
index cc74af3..2a46d47 100644 (file)
        replaceImages => true|false,
        locale => 'en' .... or zh_hk....
        rcpts => array()   // override recipients..
+       attachments => array(
+        array(
+          file: 
+          name : (optional) - uses basename of file
+          mimetype : 
+        ), 
+        ......
+  
     ]
  *
  *  recipents is gathered from the resulting template
@@ -52,7 +60,7 @@ class Pman_Core_Mailer {
     
     var $html_locale = false; // eg. 'en' or 'zh_HK'
     var $images         = array(); // generated list of cid images for sending
-    
+    var $attachments = false;
     
     function Pman_Core_Mailer($args) {
         foreach($args as $k=>$v) {
@@ -116,11 +124,11 @@ class Pman_Core_Mailer {
         }
         
         $htmlbody = false;
-        
-
+        $html_tmp_opts = $tmp_opts;
+        $htmltemplate = new HTML_Template_Flexy( $html_tmp_opts );
         if (is_string($htmltemplate->resolvePath('mail/'.$templateFile.'.body.html')) ) {
             // then we have a multi-part email...
-            $html_tmp_opts = $tmp_opts;
+            
             if (!empty($this->html_locale)) {
                 $html_tmp_opts['locale'] = $this->html_locale;
             }
@@ -202,6 +210,66 @@ class Pman_Core_Mailer {
             $parts[1] = $mime->headers($parts[1]);
         
         }
+//        echo '<PRE>';
+//        print_r('parts');
+//        print_r($parts);exit;
+        if($this->attachments){
+            //if got a attachments
+            $contentType = 'Content-Type: text/plain; charset=utf-8';
+            if (isset($parts[1]['Content-Type'])) {
+                $contentType = $parts[1]['Content-Type'];
+                unset($parts[1]['Content-Type']);
+            }
+            $random_hash = md5(date('r', time()));
+            $parts[1]['Content-Type'] = "multipart/mixed; boundary=mixed-$random_hash";
+            
+$str = "
+--mixed-$random_hash
+Content-Type: multipart/alternative; boundary=alt-$random_hash
+
+--alt-$random_hash
+Content-Type: $contentType
+
+{$parts[2]}
+
+--alt-$random_hash--
+
+";
+
+foreach($this->attachments as $attch){
+$str .= "
+--mixed-$random_hash
+Content-Type: {$attch['mimetype']}; ".
+((empty($attch['name'])) ? '' : "name=\"{$attch['name']}\"") .
+"Content-Transfer-Encoding: base64 
+Content-Disposition: attachment
+
+{$attch['file']}
+";
+}
+            $str .= "--mixed-$random_hash--";
+
+            $parts[2] = $str;
+//            --mixed-{t.random_hash}
+//Content-Type: multipart/alternative; boundary=alt-{t.random_hash}
+//
+//--alt-{t.random_hash}
+//Content-Type: text/plain; charset=utf-8
+//Content-Transfer-Encoding: 7bit
+//
+//{t.msg}
+//
+//--alt-{t.random_hash}--
+//
+//--mixed-{t.random_hash}
+//Content-Type: application/pdf; name="doc.pdf"
+//Content-Transfer-Encoding: base64 
+//Content-Disposition: attachment
+//
+//{t.attach}
+//--mixed-{t.random_hash}--
+        }
+        
         
        // list($recipents,$headers,$body) = $parts;
         return array(