]> git.mjollnir.org Git - moodle.git/commitdiff
This is part of the phpmailer distribution
authormartin <martin>
Fri, 24 May 2002 06:48:29 +0000 (06:48 +0000)
committermartin <martin>
Fri, 24 May 2002 06:48:29 +0000 (06:48 +0000)
lib/phpmailer/mailerc.php [new file with mode: 0644]

diff --git a/lib/phpmailer/mailerc.php b/lib/phpmailer/mailerc.php
new file mode 100644 (file)
index 0000000..bc4905f
--- /dev/null
@@ -0,0 +1,250 @@
+<?php\r
+////////////////////////////////////////////////////\r
+// mailerc - phpmailer client\r
+//\r
+// Version 0.07, Created 2001-01-03\r
+//\r
+// Client application for sending outgoing \r
+// messages from a file. \r
+//\r
+// Author: Brent R. Matzelle <bmatzelle@yahoo.com>\r
+//\r
+// License: LGPL, see LICENSE\r
+////////////////////////////////////////////////////\r
+\r
+require("class.phpmailer.php");\r
+\r
+// Gather global server arg variables\r
+if(!isset($_SERVER))\r
+    $_SERVER = $HTTP_SERVER_VARS;\r
+$cargv = $_SERVER["argv"];\r
+$cargc = $_SERVER["argc"];\r
+\r
+define("PROG_VERSION", "0.01");\r
+define("PROG_NAME", $cargv[0]);\r
+set_time_limit(0); // unlimited\r
+\r
+// Ignore warning messages\r
+error_reporting(E_ERROR);\r
+\r
+/**\r
+ * mailerc - mailerc extension class\r
+ * @author Brent R. Matzelle\r
+ */\r
+class mailerc extends phpmailer\r
+{\r
+    /**\r
+     * Send an email from a file created with the\r
+     * SendToQueue() function.\r
+     * @public\r
+     * @returns bool\r
+     */\r
+    function SendFromFile($filePath) {\r
+        $qarray = array();\r
+        $to_list = array();\r
+        $header = "";\r
+        $body = "";\r
+\r
+        // Make sure is there and accessible\r
+        if(!is_file($filePath))\r
+        {\r
+            $this->error_handler(sprintf("Cannot access: %s", $filePath));\r
+            return false;\r
+        }\r
+        \r
+        // upon getting header do not forget to gather the \r
+        // server info (date, recieved())\r
+        $qarray = file($filePath);\r
+        \r
+        if(count($qarray) < 1)\r
+        {\r
+            $this->error_handler("Invalid queue file");\r
+            return false;\r
+        }\r
+\r
+        // Create the header and the body (just set header)\r
+        $header = $this->received();\r
+        $header .= sprintf("Date: %s\r\n", $this->rfc_date());\r
+        \r
+        $msg_start = 0;\r
+        for($i = 0; $i < count($qarray); $i++)\r
+        {\r
+            if($qarray[$i] == "----END PQM HEADER----\r\n")\r
+            {\r
+                $msg_start = $i + 1;\r
+                break;\r
+            }\r
+        }\r
+        \r
+        for($i = $msg_start; $i < count($qarray); $i++)\r
+            $body .= $qarray[$i];\r
+\r
+        $this->Mailer = $this->qvar($qarray, "Mailer");\r
+        if($this->Mailer == "sendmail")\r
+        {\r
+            $this->Sendmail = $this->qvar($qarray, "Sendmail");\r
+            $this->Sender   = $this->qvar($qarray, "Sender");\r
+\r
+            if(!$this->sendmail_send($header, $body))\r
+                return false;\r
+        }\r
+        elseif($this->Mailer == "mail")\r
+        {\r
+            $this->Sender  = $this->qvar($qarray, "Sender");\r
+            $this->Subject = $this->qvar($qarray, "Subject");\r
+\r
+            $to_list = explode(";", $this->qvar($qarray, "to"));\r
+            for($i = 0; $i < count($to_list); $i++)\r
+                $this->AddAddress($to_list[0], "");\r
+\r
+            // This might not work because of not sending \r
+            // both a header and body.\r
+            if(!$this->mail_send($header, $body))\r
+                return false;\r
+        }\r
+        elseif($this->Mailer == "smtp")\r
+        {\r
+            $this->Host     = $this->qvar($qarray, "Host");\r
+            $this->Port     = $this->qvar($qarray, "Port");\r
+            $this->Helo     = $this->qvar($qarray, "Helo");\r
+            $this->Timeout  = $this->qvar($qarray, "Timeout");\r
+            $this->SMTPAuth = (int)$this->qvar($qarray, "SMTPAuth");\r
+            $this->Username = $this->qvar($qarray, "Username");\r
+            $this->Password = $this->qvar($qarray, "Password");\r
+            $this->From     = $this->qvar($qarray, "From");\r
+\r
+            $to_addr = $this->qvar($qarray, "to");\r
+            if(!empty($to_addr))\r
+            {\r
+                $to_list = explode(";", $to_addr);\r
+                for($i = 0; $i < count($to_list); $i++)\r
+                    $this->AddAddress($to_list[0], "");\r
+            }\r
+\r
+            $to_addr = $this->qvar($qarray, "cc");\r
+            if(!empty($to_addr))\r
+            {\r
+                $to_list = explode(";", $to_addr);\r
+                for($i = 0; $i < count($to_list); $i++)\r
+                    $this->AddCC($to_list[0], "");\r
+            }\r
+\r
+            $to_addr = $this->qvar($qarray, "bcc");\r
+            if(!empty($to_addr))\r
+            {\r
+                $to_list = explode(";", $to_addr);\r
+                for($i = 0; $i < count($to_list); $i++)\r
+                    $this->AddBCC($to_list[0], "");\r
+            }\r
+\r
+            if(!$this->smtp_send($header, $body))\r
+                return false;\r
+        }\r
+        else\r
+        {\r
+            $this->error_handler(sprintf("%s mailer is not supported", $this->Mailer));\r
+            return false;\r
+        }\r
+        \r
+        return true;\r
+    }\r
+    \r
+    /**\r
+     * Return the given queue variable from the pqm header file. Returns \r
+     * an empty string if the data was not found.\r
+     * @private\r
+     * @return string\r
+     */\r
+    function qvar($qarray, $data) {\r
+        $i = 0;\r
+        $pqm_marker = "----END PQM HEADER----\n";\r
+\r
+        while($qarray[$i] != $pqm_marker)\r
+        {\r
+            $item = explode(": ", $qarray[$i]);\r
+            //echo $item[0] . "\n"; // debug\r
+            if($item[0] == $data)\r
+                return rtrim($item[1]);\r
+            $i++;\r
+        }\r
+\r
+        return ""; // failure\r
+    }\r
+}\r
+\r
+/**\r
+ * Print out the program version information.\r
+ * @private\r
+ * @returns void\r
+ */\r
+function print_version()\r
+{\r
+   printf("mailerc %s - phpmailer client\n\n" .\r
+     "This program is distributed in the hope that it will be useful,\n" .\r
+     "but WITHOUT ANY WARRANTY; without even the implied warranty of \n" .\r
+     "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the \n" .\r
+     "GNU Lesser General Public License for more details.\n\n" .\r
+     "Written by: Brent R. Matzelle\n", PROG_VERSION);\r
+}\r
+\r
+/*\r
+  Print out the help message to the console.\r
+  @private\r
+  @returns void\r
+ */\r
+function print_help()\r
+{\r
+  printf("mailerc %s, phpmailer queue daemon.\n", PROG_VERSION);\r
+  printf("Usage: %s [OPTION] [FILE]\n", PROG_NAME);\r
+  printf("\r
+Options:\r
+  -h,  --help                            print this help.\r
+  -V,  --version                         print version information.\r
+  -s,  --send                            send [FILE]\n");\r
+}\r
+\r
+/**\r
+ * Sends a given message from a pqm (Phpmailer Queue Message) file.\r
+ * @private\r
+ * @returns bool\r
+ */\r
+function send_message($filePath)\r
+{\r
+    // Open the file and read the header contents and set \r
+    // another message.  Then run the phpmailer send file.\r
+    $mail = new mailerc();\r
+    if(!$mail->SendFromFile($filePath))\r
+        printf("error: %s\n", $mail->ErrorInfo);\r
+    else\r
+        printf("success: sent\n");\r
+}\r
+\r
+/*\r
+  Pseudo main()\r
+ */\r
+if($cargc < 1)\r
+{\r
+    print_version();\r
+    exit;\r
+}\r
+\r
+switch($cargv[1])\r
+{\r
+    case "-h":\r
+    case "--help":\r
+        print_help();\r
+        break;\r
+    case "-V":\r
+    case "--version":\r
+        print_version();\r
+        break;\r
+    case "-s":\r
+    case "--send":\r
+        send_message($cargv[2]);\r
+        break;\r
+    default:\r
+        print_help();\r
+}\r
+\r
+return 0;  // return success\r
+?>\r