Fix #7424 - better processf or failed emails
authorAlan <alan@roojs.com>
Thu, 29 Sep 2022 08:39:08 +0000 (16:39 +0800)
committerAlan <alan@roojs.com>
Thu, 29 Sep 2022 08:39:08 +0000 (16:39 +0800)
Mailer.php
MessagePreview.php
NotifySend.php
Pman.Dialog.CoreEmailPreview.bjs
Pman.Dialog.CoreEmailPreview.js
templates/mail/MessagePreview.html

index c289c55..3868884 100644 (file)
@@ -241,7 +241,9 @@ class Pman_Core_Mailer {
                 unset($parts[1]['Content-Type']);
             }
             $mime->setTXTBody($parts[2]);
+            $this->textbody = $parts[2];
             $mime->setHTMLBody($htmlbody);
+            
 //            var_dump($mime);exit;
             foreach($this->images as $cid=>$cdata) { 
             
@@ -269,8 +271,10 @@ class Pman_Core_Mailer {
                 if(preg_match('/text\/html/', $header['Content-Type'])){
                     $mime->setHTMLBody($parts[2]);
                     $mime->setTXTBody('This message is in HTML only');
+                    $this->textbody = 'This message is in HTML only';
                 }else{
                     $mime->setTXTBody($parts[2]);
+                    $this->textbody = $parts[2];
                     $mime->setHTMLBody('<PRE>'.htmlspecialchars($parts[2]).'</PRE>');
                 }
             }
index 6a7e94f..09544b8 100644 (file)
@@ -21,17 +21,58 @@ class Pman_Core_MessagePreview extends Pman
     function get($v, $opts=array())
     {
  
-        if(empty($_REQUEST['_id']) || empty($_REQUEST['_table'])){
+        if((empty($_REQUEST['_id']) && empty($_REQUEST['template_name']) )|| empty($_REQUEST['_table'])){
             $this->jerr('Missing Options');
         }
         
         $mlq = DB_DataObject::factory($_REQUEST['_table']);
+        if (!empty($_REQUEST['template_name'])) {
+            $res = $mlq->get('name', $_REQUEST['template_name']);
+        } else {
+            $res = $mlq->get($_REQUEST['_id']);
+        }
+        if (!$res) {
+            $this->jerr("invalid id/name");
+        }
         
-        $mlq->get($_REQUEST['_id']);
+        $this->showHtml = isset($_REQUEST['_as_html']) ? true : false;
         
-        $this->msg = $mlq;
+        
+        if (isset($_REQUEST['ontable']) && !empty($_REQUEST['onid']) && !empty($_REQUEST['evtype'])) {
+            $tn = preg_replace('/[^a-z_]+/i', '', $_REQUEST['ontable']);
+            
+            $t = DB_DataObject::factory($tn);
+            if (!is_a($t, 'DB_DataObject') && !is_a($t, 'PDO_DataObject')) {
+                $this->jerr("invalid URL");
+            }
+            if (!$t->get($_REQUEST['onid'])) {
+                $this->jerr("invalid id");
+            }
+            if (!method_exists($t,'notify'.$_REQUEST['evtype'])) {
+                $this->jerr("invalid evtype");
+            }
+            $m = 'notify'.$_REQUEST['evtype'];
+            $this->msg = (object)$t->$m('test@test.com', false, false, false);
+           // print_R($this->msg->mailer );
+            $this->msg->subject = $this->msg->headers['Subject'];
+            $this->msg->from_email = $mlq->from_email;
+            $this->msg->from_name = $mlq->from_name;
+            $this->msg->plaintext  = $this->msg->mailer->textbody ;
+            $this->msg->bodytext = $this->msg->mailer->htmlbody;
+            $this->msg->rcpts = $this->msg->mailer->rcpts;
+            // htmlbody 
+            //$this->plaintext = 
+            //$data->subject = $data['Subject;
+             
+            
+             
 
-        $this->showHtml = isset($_REQUEST['_as_html']) ? true : false;
+            return;
+        }
+        
+        $this->msg = $mlq;
+        $this->msg->rcpts = "send to <these@people>";
+        
         
     }
     
index e32fc6c..8053239 100644 (file)
@@ -102,7 +102,7 @@ class Pman_Core_NotifySend extends Pman
             $this->errorHandler("invalid id\n");
         }
 
-        if (!$force && strtotime($w->act_when) < strtotime($w->sent)) {
+        if (!$force && !empty($w->sent) && strtotime($w->act_when) < strtotime($w->sent)) {
             
             
             $this->errorHandler("send repeat to early\n");
index addc15a..1bea89d 100644 (file)
 {
- "name" : "Pman.Dialog.CoreEmailPreview",
- "parent" : "",
- "title" : "",
- "path" : "/home/johns/gitlive/Pman.Core/Pman.Dialog.CoreEmailPreview.bjs",
- "permname" : "",
- "modOrder" : "001",
- "strings" : {
-  "4cd8413207629a963225f4314b53adcd" : "Plain",
-  "4c4ad5fca2e7a3f74dbb1ced00381aa4" : "HTML",
-  "006c82ffdd63692a84a259c4f8732842" : "Email Preview",
-  "e0aa021e21dddbd6d8cecec71e9cf564" : "OK"
- },
  "items" : [
   {
-   "listeners" : {
-    "show" : "function (_self)\n{\n    \n    _self.layout.getRegion('center').showPanel(0);\n    _this.panel.load({ \n        url: baseURL + '/Core/MessagePreview', \n        params  : {\n            _id : _this.data.id,\n            _table : _this.data.module\n        },\n        method : 'GET'\n    });\n    _this.hpanel.load({ \n        url: baseURL + '/Core/MessagePreview', \n        params  : {\n            _as_html : 1,\n            _id : _this.data.id,\n            _table : _this.data.module\n        },\n        method : 'GET'\n    });\n        \n}"
-   },
-   "shadow" : true,
-   "autoScroll" : true,
-   "title" : "Email Preview",
-   "xtype" : "LayoutDialog",
-   "width" : 1200,
    "$ xns" : "Roo",
+   "autoScroll" : true,
    "closable" : true,
    "height" : 800,
    "items" : [
     {
+     "$ xns" : "Roo",
+     "* prop" : "center",
      "autoScroll" : true,
-     "xtype" : "LayoutRegion",
      "tabPosition" : "top",
-     "$ xns" : "Roo",
-     "* prop" : "center"
+     "xtype" : "LayoutRegion"
     },
     {
+     "$ xns" : "Roo",
+     "fitContainer" : true,
+     "fitToFrame" : true,
      "listeners" : {
-      "render" : "function (_self)\n{\n    _this.panel = _self;\n}"
+      "render" : [
+       "function (_self)",
+       "{",
+       "    _this.hpanel = _self;",
+       "}"
+      ]
      },
      "region" : "center",
-     "fitToFrame" : true,
-     "title" : "Plain",
-     "xtype" : "ContentPanel",
-     "fitContainer" : true,
-     "$ xns" : "Roo"
+     "title" : "HTML",
+     "xtype" : "ContentPanel"
     },
     {
+     "$ xns" : "Roo",
+     "fitContainer" : true,
+     "fitToFrame" : true,
      "listeners" : {
-      "render" : "function (_self)\n{\n    _this.hpanel = _self;\n}"
+      "render" : [
+       "function (_self)",
+       "{",
+       "    _this.panel = _self;",
+       "}"
+      ]
      },
      "region" : "center",
-     "fitToFrame" : true,
-     "title" : "HTML",
-     "xtype" : "ContentPanel",
-     "fitContainer" : true,
-     "$ xns" : "Roo"
+     "title" : "Plain",
+     "xtype" : "ContentPanel"
     },
     {
+     "$ xns" : "Roo",
+     "* prop" : "buttons[]",
      "listeners" : {
-      "click" : "function (_self, e)\n{\n    _this.dialog.hide();\n}"
+      "click" : [
+       "function (_self, e)",
+       "{",
+       "    _this.dialog.hide();",
+       "}"
+      ]
      },
      "text" : "OK",
-     "xtype" : "Button",
-     "$ xns" : "Roo",
-     "* prop" : "buttons[]"
+     "xtype" : "Button"
     }
-   ]
+   ],
+   "listeners" : {
+    "show" : [
+     "function (_self)",
+     "{",
+     "    ",
+     "    _self.layout.getRegion('center').showPanel(0);",
+     "    _this.panel.load({ ",
+     "        url: baseURL + '/Core/MessagePreview', ",
+     "        params  : {",
+     "            _id : _this.data.id || '',",
+     "            template_name : _this.data.template_name || '',            ",
+     "            _table : _this.data.module,",
+     "            ontable : _this.data.ontable || '',",
+     "            onid : _this.data.onid || '',",
+     "            evtype : _this.data.evtype  || ''",
+     "        },",
+     "        method : 'GET'",
+     "    });",
+     "    _this.hpanel.load({ ",
+     "        url: baseURL + '/Core/MessagePreview', ",
+     "        params  : {",
+     "            _as_html : 1,",
+     "            _id : _this.data.id || '',",
+     "            template_name : _this.data.template_name || '',",
+     "            _table : _this.data.module,",
+     "            ontable : _this.data.ontable || '',",
+     "            onid : _this.data.onid  || '',",
+     "            evtype : _this.data.evtype || ''",
+     "        },",
+     "        method : 'GET'",
+     "    });",
+     "        ",
+     "}"
+    ]
+   },
+   "shadow" : true,
+   "title" : "Email Preview",
+   "width" : 1200,
+   "xtype" : "LayoutDialog"
   }
- ]
+ ],
+ "modOrder" : "001",
+ "name" : "Pman.Dialog.CoreEmailPreview",
+ "parent" : "",
+ "path" : "/home/alan/gitlive/Pman.Core/Pman.Dialog.CoreEmailPreview.bjs",
+ "permname" : "",
+ "strings" : {
+  "006c82ffdd63692a84a259c4f8732842" : "Email Preview",
+  "4c4ad5fca2e7a3f74dbb1ced00381aa4" : "HTML",
+  "4cd8413207629a963225f4314b53adcd" : "Plain",
+  "e0aa021e21dddbd6d8cecec71e9cf564" : "OK"
+ },
+ "title" : ""
 }
\ No newline at end of file
index c045eb0..5acb548 100644 (file)
@@ -24,7 +24,7 @@ Pman.Dialog.CoreEmailPreview = {
 
   this.callback = cb;
   this.data = data;
-  this.dialog.show(this.data._el);
+  this.dialog.show.apply(this.dialog,  Array.prototype.slice.call(arguments).slice(2));
   if (this.form) {
    this.form.reset();
    this.form.setValues(data);
@@ -52,8 +52,12 @@ Pman.Dialog.CoreEmailPreview = {
           _this.panel.load({ 
               url: baseURL + '/Core/MessagePreview', 
               params  : {
-                  _id : _this.data.id,
-                  _table : _this.data.module
+                  _id : _this.data.id || '',
+                  template_name : _this.data.template_name || '',            
+                  _table : _this.data.module,
+                  ontable : _this.data.ontable || '',
+                  onid : _this.data.onid || '',
+                  evtype : _this.data.evtype  || ''
               },
               method : 'GET'
           });
@@ -61,8 +65,12 @@ Pman.Dialog.CoreEmailPreview = {
               url: baseURL + '/Core/MessagePreview', 
               params  : {
                   _as_html : 1,
-                  _id : _this.data.id,
-                  _table : _this.data.module
+                  _id : _this.data.id || '',
+                  template_name : _this.data.template_name || '',
+                  _table : _this.data.module,
+                  ontable : _this.data.ontable || '',
+                  onid : _this.data.onid  || '',
+                  evtype : _this.data.evtype || ''
               },
               method : 'GET'
           });
@@ -98,11 +106,11 @@ Pman.Dialog.CoreEmailPreview = {
       fitContainer : true,
       fitToFrame : true,
       region : 'center',
-      title : _this._strings['4cd8413207629a963225f4314b53adcd'] /* Plain */,
+      title : _this._strings['4c4ad5fca2e7a3f74dbb1ced00381aa4'] /* HTML */,
       listeners : {
        render : function (_self)
         {
-            _this.panel = _self;
+            _this.hpanel = _self;
         }
       },
       xns : Roo,
@@ -113,11 +121,11 @@ Pman.Dialog.CoreEmailPreview = {
       fitContainer : true,
       fitToFrame : true,
       region : 'center',
-      title : _this._strings['4c4ad5fca2e7a3f74dbb1ced00381aa4'] /* HTML */,
+      title : _this._strings['4cd8413207629a963225f4314b53adcd'] /* Plain */,
       listeners : {
        render : function (_self)
         {
-            _this.hpanel = _self;
+            _this.panel = _self;
         }
       },
       xns : Roo,
index 757c105..1dcd636 100644 (file)
@@ -1,7 +1,11 @@
-<code>From : "{msg.from_name}" &lt;{msg.from_email}&gt;</code>
-<br/>
-<code>Subject : {msg.subject}</code>
-<br/>
+<div class="undoreset" style="margin:10px">
+
+<code><B>From:</B> "{msg.from_name}" &lt;{msg.from_email}&gt;<br/>
+<B>Subject:</B> {msg.subject}<br/>
+<B>To:</B> {msg.rcpts}<br/>
+</code>
 {if:!showHtml}
 <br>
 <code>{msg.plaintext:b}</code>
@@ -9,4 +13,4 @@
 <br/>
 {msg.bodytext:h}
 {end:}
-    
+</div>