Automatic installer.php lang files by installer_builder (20070726)
[moodle-linuxchix.git] / lib / phpmailer / mailerc.php
blob4b1752cd84f783e457678dd77a6bfb913c9c95b6
1 <?php
2 ////////////////////////////////////////////////////
3 // mailerc - phpmailer client
4 //
5 // Version 0.07, Created 2001-01-03
6 //
7 // Client application for sending outgoing
8 // messages from a file.
9 //
10 // Author: Brent R. Matzelle <bmatzelle@yahoo.com>
12 // License: LGPL, see LICENSE
13 ////////////////////////////////////////////////////
15 require("class.phpmailer.php");
17 // Gather global server arg variables
18 if(!isset($_SERVER))
19 $_SERVER = $HTTP_SERVER_VARS;
20 $cargv = $_SERVER["argv"];
21 $cargc = $_SERVER["argc"];
23 define("PROG_VERSION", "0.01");
24 define("PROG_NAME", $cargv[0]);
25 @set_time_limit(0); // unlimited
27 // Ignore warning messages
28 error_reporting(E_ERROR);
30 /**
31 * mailerc - mailerc extension class
32 * @author Brent R. Matzelle
34 class mailerc extends phpmailer
36 /**
37 * Send an email from a file created with the
38 * SendToQueue() function.
39 * @public
40 * @returns bool
42 function SendFromFile($filePath) {
43 $qarray = array();
44 $to_list = array();
45 $header = "";
46 $body = "";
48 // Make sure is there and accessible
49 if(!is_file($filePath))
51 $this->error_handler(sprintf("Cannot access: %s", $filePath));
52 return false;
55 // upon getting header do not forget to gather the
56 // server info (date, recieved())
57 $qarray = file($filePath);
59 if(count($qarray) < 1)
61 $this->error_handler("Invalid queue file");
62 return false;
65 // Create the header and the body (just set header)
66 $header = $this->received();
67 $header .= sprintf("Date: %s\r\n", $this->rfc_date());
69 $msg_start = 0;
70 for($i = 0; $i < count($qarray); $i++)
72 if($qarray[$i] == "----END PQM HEADER----\r\n")
74 $msg_start = $i + 1;
75 break;
79 for($i = $msg_start; $i < count($qarray); $i++)
80 $body .= $qarray[$i];
82 $this->Mailer = $this->qvar($qarray, "Mailer");
83 if($this->Mailer == "sendmail")
85 $this->Sendmail = $this->qvar($qarray, "Sendmail");
86 $this->Sender = $this->qvar($qarray, "Sender");
88 if(!$this->sendmail_send($header, $body))
89 return false;
91 elseif($this->Mailer == "mail")
93 $this->Sender = $this->qvar($qarray, "Sender");
94 $this->Subject = $this->qvar($qarray, "Subject");
96 $to_list = explode(";", $this->qvar($qarray, "to"));
97 for($i = 0; $i < count($to_list); $i++)
98 $this->AddAddress($to_list[0], "");
100 // This might not work because of not sending
101 // both a header and body.
102 if(!$this->mail_send($header, $body))
103 return false;
105 elseif($this->Mailer == "smtp")
107 $this->Host = $this->qvar($qarray, "Host");
108 $this->Port = $this->qvar($qarray, "Port");
109 $this->Helo = $this->qvar($qarray, "Helo");
110 $this->Timeout = $this->qvar($qarray, "Timeout");
111 $this->SMTPAuth = (int)$this->qvar($qarray, "SMTPAuth");
112 $this->Username = $this->qvar($qarray, "Username");
113 $this->Password = $this->qvar($qarray, "Password");
114 $this->From = $this->qvar($qarray, "From");
116 $to_addr = $this->qvar($qarray, "to");
117 if(!empty($to_addr))
119 $to_list = explode(";", $to_addr);
120 for($i = 0; $i < count($to_list); $i++)
121 $this->AddAddress($to_list[0], "");
124 $to_addr = $this->qvar($qarray, "cc");
125 if(!empty($to_addr))
127 $to_list = explode(";", $to_addr);
128 for($i = 0; $i < count($to_list); $i++)
129 $this->AddCC($to_list[0], "");
132 $to_addr = $this->qvar($qarray, "bcc");
133 if(!empty($to_addr))
135 $to_list = explode(";", $to_addr);
136 for($i = 0; $i < count($to_list); $i++)
137 $this->AddBCC($to_list[0], "");
140 if(!$this->smtp_send($header, $body))
141 return false;
143 else
145 $this->error_handler(sprintf("%s mailer is not supported", $this->Mailer));
146 return false;
149 return true;
153 * Return the given queue variable from the pqm header file. Returns
154 * an empty string if the data was not found.
155 * @private
156 * @return string
158 function qvar($qarray, $data) {
159 $i = 0;
160 $pqm_marker = "----END PQM HEADER----\n";
162 while($qarray[$i] != $pqm_marker)
164 $item = explode(": ", $qarray[$i]);
165 //echo $item[0] . "\n"; // debug
166 if($item[0] == $data)
167 return rtrim($item[1]);
168 $i++;
171 return ""; // failure
176 * Print out the program version information.
177 * @private
178 * @returns void
180 function print_version()
182 printf("mailerc %s - phpmailer client\n\n" .
183 "This program is distributed in the hope that it will be useful,\n" .
184 "but WITHOUT ANY WARRANTY; without even the implied warranty of \n" .
185 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the \n" .
186 "GNU Lesser General Public License for more details.\n\n" .
187 "Written by: Brent R. Matzelle\n", PROG_VERSION);
191 Print out the help message to the console.
192 @private
193 @returns void
195 function print_help()
197 printf("mailerc %s, phpmailer queue daemon.\n", PROG_VERSION);
198 printf("Usage: %s [OPTION] [FILE]\n", PROG_NAME);
199 printf("
200 Options:
201 -h, --help print this help.
202 -V, --version print version information.
203 -s, --send send [FILE]\n");
207 * Sends a given message from a pqm (Phpmailer Queue Message) file.
208 * @private
209 * @returns bool
211 function send_message($filePath)
213 // Open the file and read the header contents and set
214 // another message. Then run the phpmailer send file.
215 $mail = new mailerc();
216 if(!$mail->SendFromFile($filePath))
217 printf("error: %s\n", $mail->ErrorInfo);
218 else
219 printf("success: sent\n");
223 Pseudo main()
225 if($cargc < 1)
227 print_version();
228 exit;
231 switch($cargv[1])
233 case "-h":
234 case "--help":
235 print_help();
236 break;
237 case "-V":
238 case "--version":
239 print_version();
240 break;
241 case "-s":
242 case "--send":
243 send_message($cargv[2]);
244 break;
245 default:
246 print_help();
249 return 0; // return success