From 1162f87e4326868160cfddaa524efd1386b34133 Mon Sep 17 00:00:00 2001
From: Malf Furious <m@lfurio.us>
Date: Tue, 13 Jun 2017 22:35:17 -0400
Subject: Add mesg function emailMesg()

---
 app/class/mesg.class.php | 50 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)

(limited to 'app')

diff --git a/app/class/mesg.class.php b/app/class/mesg.class.php
index 6c84d4f..da52fa6 100644
--- a/app/class/mesg.class.php
+++ b/app/class/mesg.class.php
@@ -282,6 +282,56 @@ class mesg extends object
         $this->delObj();
         return $issue;
     }
+
+    /*
+     * Email this message to parents, owners, members.  In the case that
+     * this is an issue message or a reply message, the assignee or original
+     * author is also included.  Attachments are included in mailing.  Any
+     * duplicates in the rcpt list are removed before sending.  Success
+     * or failure is returned.
+     */
+    public function emailMesg() : bool
+    {
+        $parent = $this->getParent();
+
+        if (!$parent)
+            return true;
+
+        $rcpt = $this->getMembers();
+        $rcpt[] = $this->getOwner();
+
+        switch ($parent->objtype)
+        {
+            case "user":
+                $rcpt[] = $parent;
+                $subj = $this->author . " PM from " . $this->getAuthor()->getDisplayName();
+                break;
+
+            case "issue":
+                $rcpt[] = $parent->getAssignee();
+                $pad = $parent->getPad();
+                $subj = $parent->guid . " " . $pad->name . " [#" . $parent->numb . "] " . $parent->name;
+                break;
+
+            case "mesg":
+            case "log":
+                $rcpt[] = $parent->getAuthor();
+                $pad = $parent->getParent();
+                $subj = $parent->guid . " " . $pad->name . " // " . $parent->name;
+                break;
+        }
+
+        $rcpt = object::arrayUnique($rcpt);
+        $attachPath = ($this->getAttachment() ? "dynmic/attach/" . $this->guid : NULL);
+
+        foreach ($rcpt as $r)
+        {
+            if (!$r->sendEmail($subj, $this->mesg, $attachPath, $this->attachment))
+                return false;
+        }
+
+        return true;
+    }
 }
 
 ?>
-- 
cgit v1.2.3