DataObjects/Core_notify.php
[Pman.Core] / Mailer.php
index 2ec116d..40f9772 100644 (file)
@@ -40,7 +40,7 @@
  */
 
 class Pman_Core_Mailer {
-    
+    var $debug          = false;
     var $page           = false; /* usually a html_flexyframework_page */
     var $contents       = false; /* object or array */
     var $template       = false; /* string */
@@ -108,28 +108,21 @@ class Pman_Core_Mailer {
             $htmlbody =  $htmltemplate->bufferedOutputObject($content);
             
             // for the html body, we may want to convert the attachments to images.
-            
+//            var_dump($htmlbody);exit;
             $htmlbody = $this->htmlbodytoCID($htmlbody);
             
               
         }
-        
         $tmp_opts['nonHTML'] = true;
-        
+        // $tmp_opts['force'] = true;
         $template = new HTML_Template_Flexy(  $tmp_opts );
         
         $template->compile('mail/'. $templateFile.'.txt');
         
         /* use variables from this object to ouput data. */
         $mailtext = $template->bufferedOutputObject($content);
-        
-        
-        
-        
-        
-        
-        
-        
+        //print_r($mailtext);exit;
+       
         
         
         //echo "<PRE>";print_R($mailtext);
@@ -157,11 +150,16 @@ class Pman_Core_Mailer {
         
         if ($htmlbody !== false) {
             require_once 'Mail/mime.php';
-            $mime = new Mail_mime(array('eol' => "\n"));
+            $mime = new Mail_mime(array('eol' => "\n",
+//                                    'html_encoding' => 'base64',
+                                    'html_charset' => 'utf-8',
+                                    'text_charset' => 'utf-8',
+                                    'head_charset' => 'utf-8'
+                ));
             
             $mime->setTXTBody($parts[2]);
             $mime->setHTMLBody($htmlbody);
-            
+//            var_dump($mime);exit;
             foreach($this->images as $cid=>$cdata) { 
             
                 $mime->addHTMLImage(
@@ -177,8 +175,6 @@ class Pman_Core_Mailer {
         
         }
         
-        
-        
        // list($recipents,$headers,$body) = $parts;
         return array(
             'recipents' => $parts[0],
@@ -193,8 +189,12 @@ class Pman_Core_Mailer {
         if (is_a($email, 'PEAR_Error')) {
             return $email;
         }
+        if ($this->debug) {
+            echo '<PRE>';echo htmlspecialchars(print_r($email,true));
+        }
         ///$recipents = array($this->email);
         $mailOptions = PEAR::getStaticProperty('Mail','options');
+        //print_R($mailOptions);exit;
         $mail = Mail::factory("SMTP",$mailOptions);
         $headers['Date'] = date('r'); 
         if (PEAR::isError($mail)) {
@@ -216,7 +216,7 @@ class Pman_Core_Mailer {
     function htmlbodytoCID($html)
     {
         $dom = new DOMDocument;
-        $dom->loadHTML($html);
+        $dom->loadHTML('<?xml encoding="UTF-8">' .$html);
         $imgs= $dom->getElementsByTagName('img');
         
         foreach ($imgs as $i=>$img) {
@@ -237,7 +237,8 @@ class Pman_Core_Mailer {
     {
         
         if ($url[0] == '/') {
-            $file = $this->page->rootDir . $url;
+            $ff = HTML_FlexyFramework::get();
+            $file = $ff->rootDir . $url;
             require_once 'File/MimeType.php';
             $m  = new File_MimeType();
             $mt = $m->fromFilename($file);
@@ -275,14 +276,19 @@ class Pman_Core_Mailer {
         
         // CACHE???
         // 2 files --- the info file.. and the actual file...
-        $cache = ini_get('session.save_path').'/Pman_Core_Mailer/' . md5($url);
+        // add user
+        // unix only...
+        $uinfo = posix_getpwuid( posix_getuid () ); 
+        $user = $uinfo['name']; 
+        
+        $cache = ini_get('session.save_path')."/Pman_Core_Mailer-{$user}/" . md5($url);
         if (file_exists($cache) and filemtime($cache) > strtotime('NOW - 1 WEEK')) {
             $ret =  json_decode($cache);
             $ret['file'] = $cache . '.data';
             return $ret;
         }
         if (!file_exists(dirname($cache))) {
-            mkdir(dirname($cache),0666, true);
+            mkdir(dirname($cache),0700, true);
         }
         
         require_once 'HTTP/Request.php';