Ticket #19677: phpmailer-5.2.diff

File phpmailer-5.2.diff, 42.6 KB (added by westi, 17 months ago)

PHP 5.2 for WordPress

Line 
1Index: class-phpmailer.php
2===================================================================
3--- class-phpmailer.php (revision 19621)
4+++ class-phpmailer.php (working copy)
5@@ -2,15 +2,15 @@
6 /*~ class.phpmailer.php
7 .---------------------------------------------------------------------------.
8 |  Software: PHPMailer - PHP email class                                    |
9-|   Version: 5.1                                                            |
10-|   Contact: via sourceforge.net support pages (also www.worxware.com)      |
11-|      Info: http://phpmailer.sourceforge.net                               |
12-|   Support: http://sourceforge.net/projects/phpmailer/                     |
13+|   Version: 5.2                                                            |
14+|      Site: https://code.google.com/a/apache-extras.org/p/phpmailer/       |
15 | ------------------------------------------------------------------------- |
16-|     Admin: Andy Prevost (project admininistrator)                         |
17+|     Admin: Jim Jagielski (project admininistrator)                        |
18 |   Authors: Andy Prevost (codeworxtech) codeworxtech@users.sourceforge.net |
19 |          : Marcus Bointon (coolbru) coolbru@users.sourceforge.net         |
20+|          : Jim Jagielski (jimjag) jimjag@gmail.com                        |
21 |   Founder: Brent R. Matzelle (original founder)                           |
22+| Copyright (c) 2010-2011, Jim Jagielski. All Rights Reserved.               |
23 | Copyright (c) 2004-2009, Andy Prevost. All Rights Reserved.               |
24 | Copyright (c) 2001-2003, Brent R. Matzelle                                |
25 | ------------------------------------------------------------------------- |
26@@ -19,11 +19,6 @@
27 | This program is distributed in the hope that it will be useful - WITHOUT  |
28 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or     |
29 | FITNESS FOR A PARTICULAR PURPOSE.                                         |
30-| ------------------------------------------------------------------------- |
31-| We offer a number of paid services (www.worxware.com):                    |
32-| - Web Hosting on highly optimized fast and secure servers                 |
33-| - Technology Consulting                                                   |
34-| - Oursourcing (highly qualified programmers and graphic designers)        |
35 '---------------------------------------------------------------------------'
36 */
37 
38@@ -33,8 +28,10 @@
39  * @package PHPMailer
40  * @author Andy Prevost
41  * @author Marcus Bointon
42+ * @author Jim Jagielski
43+ * @copyright 2010 - 2011 Jim Jagielski
44  * @copyright 2004 - 2009 Andy Prevost
45- * @version $Id: class.phpmailer.php 447 2009-05-25 01:36:38Z codeworxtech $
46+ * @version $Id: class.phpmailer.php 450 2010-06-23 16:46:33Z coolbru $
47  * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
48  */
49 
50@@ -119,6 +116,20 @@
51   public $AltBody           = '';
52 
53   /**
54+   * Stores the complete compiled MIME message body.
55+   * @var string
56+   * @access protected
57+   */
58+  protected $MIMEBody       = '';
59+
60+  /**
61+   * Stores the complete compiled MIME message headers.
62+   * @var string
63+   * @access protected
64+   */
65+  protected $MIMEHeader     = '';
66+
67+  /**
68    * Sets word wrapping on the body of the message to a given number of
69    * characters.
70    * @var int
71@@ -271,6 +282,12 @@
72 
73   /**
74    * Used with DKIM DNS Resource Record
75+   * @var string
76+   */
77+  public $DKIM_passphrase   = '';
78+
79+  /**
80+   * Used with DKIM DNS Resource Record
81    * optional, in format of email address 'you@yourdomain.com'
82    * @var string
83    */
84@@ -300,28 +317,34 @@
85    * Sets the PHPMailer Version number
86    * @var string
87    */
88-  public $Version         = '5.1';
89+  public $Version         = '5.2';
90 
91+  /**
92+   * What to use in the X-Mailer header
93+   * @var string
94+   */
95+  public $XMailer         = '';
96+
97   /////////////////////////////////////////////////
98   // PROPERTIES, PRIVATE AND PROTECTED
99   /////////////////////////////////////////////////
100 
101-  private   $smtp           = NULL;
102-  private   $to             = array();
103-  private   $cc             = array();
104-  private   $bcc            = array();
105-  private   $ReplyTo        = array();
106-  private   $all_recipients = array();
107-  private   $attachment     = array();
108-  private   $CustomHeader   = array();
109-  private   $message_type   = '';
110-  private   $boundary       = array();
111-  protected $language       = array();
112-  private   $error_count    = 0;
113-  private   $sign_cert_file = "";
114-  private   $sign_key_file  = "";
115-  private   $sign_key_pass  = "";
116-  private   $exceptions     = false;
117+  protected   $smtp           = NULL;
118+  protected   $to             = array();
119+  protected   $cc             = array();
120+  protected   $bcc            = array();
121+  protected   $ReplyTo        = array();
122+  protected   $all_recipients = array();
123+  protected   $attachment     = array();
124+  protected   $CustomHeader   = array();
125+  protected   $message_type   = '';
126+  protected   $boundary       = array();
127+  protected   $language       = array();
128+  protected   $error_count    = 0;
129+  protected   $sign_cert_file = '';
130+  protected   $sign_key_file  = '';
131+  protected   $sign_key_pass  = '';
132+  protected   $exceptions     = false;
133 
134   /////////////////////////////////////////////////
135   // CONSTANTS
136@@ -447,11 +470,15 @@
137    * @param string $address The email address to send to
138    * @param string $name
139    * @return boolean true on success, false if address already used or invalid in some way
140-   * @access private
141+   * @access protected
142    */
143-  private function AddAnAddress($kind, $address, $name = '') {
144+  protected function AddAnAddress($kind, $address, $name = '') {
145     if (!preg_match('/^(to|cc|bcc|ReplyTo)$/', $kind)) {
146-      echo 'Invalid recipient array: ' . $kind;
147+      $this->SetError($this->Lang('Invalid recipient array').': '.$kind);
148+      if ($this->exceptions) {
149+        throw new phpmailerException('Invalid recipient array: ' . $kind);
150+      }
151+      echo $this->Lang('Invalid recipient array').': '.$kind;
152       return false;
153     }
154     $address = trim($address);
155@@ -485,7 +512,7 @@
156  * @param string $name
157  * @return boolean
158  */
159-  public function SetFrom($address, $name = '',$auto=1) {
160+  public function SetFrom($address, $name = '', $auto = 1) {
161     $address = trim($address);
162     $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
163     if (!self::ValidateAddress($address)) {
164@@ -544,6 +571,19 @@
165    */
166   public function Send() {
167     try {
168+      if(!$this->PreSend()) return false;
169+      return $this->PostSend();
170+    } catch (phpmailerException $e) {
171+      $this->SetError($e->getMessage());
172+      if ($this->exceptions) {
173+        throw $e;
174+      }
175+      return false;
176+    }
177+  }
178+
179+  protected function PreSend() {
180+    try {
181       if ((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
182         throw new phpmailerException($this->Lang('provide_address'), self::STOP_CRITICAL);
183       }
184@@ -555,27 +595,41 @@
185 
186       $this->error_count = 0; // reset errors
187       $this->SetMessageType();
188-      $header = $this->CreateHeader();
189-      $body = $this->CreateBody();
190-
191+      //Refuse to send an empty message
192       if (empty($this->Body)) {
193         throw new phpmailerException($this->Lang('empty_message'), self::STOP_CRITICAL);
194       }
195 
196+      $this->MIMEHeader = $this->CreateHeader();
197+      $this->MIMEBody = $this->CreateBody();
198+
199+
200       // digitally sign with DKIM if enabled
201       if ($this->DKIM_domain && $this->DKIM_private) {
202-        $header_dkim = $this->DKIM_Add($header,$this->Subject,$body);
203-        $header = str_replace("\r\n","\n",$header_dkim) . $header;
204+        $header_dkim = $this->DKIM_Add($this->MIMEHeader, $this->EncodeHeader($this->SecureHeader($this->Subject)), $this->MIMEBody);
205+        $this->MIMEHeader = str_replace("\r\n", "\n", $header_dkim) . $this->MIMEHeader;
206       }
207 
208+      return true;
209+    } catch (phpmailerException $e) {
210+      $this->SetError($e->getMessage());
211+      if ($this->exceptions) {
212+        throw $e;
213+      }
214+      return false;
215+    }
216+  }
217+
218+  protected function PostSend() {
219+    try {
220       // Choose the mailer and send through it
221       switch($this->Mailer) {
222         case 'sendmail':
223-          return $this->SendmailSend($header, $body);
224+          return $this->SendmailSend($this->MIMEHeader, $this->MIMEBody);
225         case 'smtp':
226-          return $this->SmtpSend($header, $body);
227+          return $this->SmtpSend($this->MIMEHeader, $this->MIMEBody);
228         default:
229-          return $this->MailSend($header, $body);
230+          return $this->MailSend($this->MIMEHeader, $this->MIMEBody);
231       }
232 
233     } catch (phpmailerException $e) {
234@@ -612,7 +666,7 @@
235         $result = pclose($mail);
236         // implement call back function if it exists
237         $isSent = ($result == 0) ? 1 : 0;
238-        $this->doCallback($isSent,$val,$this->cc,$this->bcc,$this->Subject,$body);
239+        $this->doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body);
240         if($result != 0) {
241           throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
242         }
243@@ -626,7 +680,7 @@
244       $result = pclose($mail);
245       // implement call back function if it exists
246       $isSent = ($result == 0) ? 1 : 0;
247-      $this->doCallback($isSent,$this->to,$this->cc,$this->bcc,$this->Subject,$body);
248+      $this->doCallback($isSent, $this->to, $this->cc, $this->bcc, $this->Subject, $body);
249       if($result != 0) {
250         throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
251       }
252@@ -648,8 +702,12 @@
253     }
254     $to = implode(', ', $toArr);
255 
256-    $params = sprintf("-oi -f %s", $this->Sender);
257-    if ($this->Sender != '' && strlen(ini_get('safe_mode'))< 1) {
258+    if (empty($this->Sender)) {
259+      $params = "-oi -f %s";
260+    } else {
261+      $params = sprintf("-oi -f %s", $this->Sender);
262+    }
263+    if ($this->Sender != '' and !ini_get('safe_mode')) {
264       $old_from = ini_get('sendmail_from');
265       ini_set('sendmail_from', $this->Sender);
266       if ($this->SingleTo === true && count($toArr) > 1) {
267@@ -657,13 +715,13 @@
268           $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
269           // implement call back function if it exists
270           $isSent = ($rt == 1) ? 1 : 0;
271-          $this->doCallback($isSent,$val,$this->cc,$this->bcc,$this->Subject,$body);
272+          $this->doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body);
273         }
274       } else {
275         $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
276         // implement call back function if it exists
277         $isSent = ($rt == 1) ? 1 : 0;
278-        $this->doCallback($isSent,$to,$this->cc,$this->bcc,$this->Subject,$body);
279+        $this->doCallback($isSent, $to, $this->cc, $this->bcc, $this->Subject, $body);
280       }
281     } else {
282       if ($this->SingleTo === true && count($toArr) > 1) {
283@@ -671,13 +729,13 @@
284           $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
285           // implement call back function if it exists
286           $isSent = ($rt == 1) ? 1 : 0;
287-          $this->doCallback($isSent,$val,$this->cc,$this->bcc,$this->Subject,$body);
288+          $this->doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body);
289         }
290       } else {
291         $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header);
292         // implement call back function if it exists
293         $isSent = ($rt == 1) ? 1 : 0;
294-        $this->doCallback($isSent,$to,$this->cc,$this->bcc,$this->Subject,$body);
295+        $this->doCallback($isSent, $to, $this->cc, $this->bcc, $this->Subject, $body);
296       }
297     }
298     if (isset($old_from)) {
299@@ -699,7 +757,7 @@
300    * @return bool
301    */
302   protected function SmtpSend($header, $body) {
303-    require_once $this->PluginDir . 'class-smtp.php';
304+    require_once $this->PluginDir . 'class.smtp.php';
305     $bad_rcpt = array();
306 
307     if(!$this->SmtpConnect()) {
308@@ -716,11 +774,11 @@
309         $bad_rcpt[] = $to[0];
310         // implement call back function if it exists
311         $isSent = 0;
312-        $this->doCallback($isSent,$to[0],'','',$this->Subject,$body);
313+        $this->doCallback($isSent, $to[0], '', '', $this->Subject, $body);
314       } else {
315         // implement call back function if it exists
316         $isSent = 1;
317-        $this->doCallback($isSent,$to[0],'','',$this->Subject,$body);
318+        $this->doCallback($isSent, $to[0], '', '', $this->Subject, $body);
319       }
320     }
321     foreach($this->cc as $cc) {
322@@ -728,11 +786,11 @@
323         $bad_rcpt[] = $cc[0];
324         // implement call back function if it exists
325         $isSent = 0;
326-        $this->doCallback($isSent,'',$cc[0],'',$this->Subject,$body);
327+        $this->doCallback($isSent, '', $cc[0], '', $this->Subject, $body);
328       } else {
329         // implement call back function if it exists
330         $isSent = 1;
331-        $this->doCallback($isSent,'',$cc[0],'',$this->Subject,$body);
332+        $this->doCallback($isSent, '', $cc[0], '', $this->Subject, $body);
333       }
334     }
335     foreach($this->bcc as $bcc) {
336@@ -740,11 +798,11 @@
337         $bad_rcpt[] = $bcc[0];
338         // implement call back function if it exists
339         $isSent = 0;
340-        $this->doCallback($isSent,'','',$bcc[0],$this->Subject,$body);
341+        $this->doCallback($isSent, '', '', $bcc[0], $this->Subject, $body);
342       } else {
343         // implement call back function if it exists
344         $isSent = 1;
345-        $this->doCallback($isSent,'','',$bcc[0],$this->Subject,$body);
346+        $this->doCallback($isSent, '', '', $bcc[0], $this->Subject, $body);
347       }
348     }
349 
350@@ -942,7 +1000,7 @@
351 
352     $line = explode($this->LE, $message);
353     $message = '';
354-    for ($i=0 ;$i < count($line); $i++) {
355+    for ($i = 0 ;$i < count($line); $i++) {
356       $line_part = explode(' ', $line[$i]);
357       $buf = '';
358       for ($e = 0; $e<count($line_part); $e++) {
359@@ -1056,7 +1114,9 @@
360 
361     switch($this->message_type) {
362       case 'alt':
363-      case 'alt_attachments':
364+      case 'alt_inline':
365+      case 'alt_attach':
366+      case 'alt_inline_attach':
367         $this->AltBody = $this->WrapText($this->AltBody, $this->WordWrap);
368         break;
369       default:
370@@ -1077,6 +1137,7 @@
371     $uniq_id = md5(uniqid(time()));
372     $this->boundary[1] = 'b1_' . $uniq_id;
373     $this->boundary[2] = 'b2_' . $uniq_id;
374+    $this->boundary[3] = 'b3_' . $uniq_id;
375 
376     $result .= $this->HeaderLine('Date', self::RFCDate());
377     if($this->Sender == '') {
378@@ -1125,12 +1186,16 @@
379     }
380 
381     if($this->MessageID != '') {
382-      $result .= $this->HeaderLine('Message-ID',$this->MessageID);
383+      $result .= $this->HeaderLine('Message-ID', $this->MessageID);
384     } else {
385       $result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE);
386     }
387     $result .= $this->HeaderLine('X-Priority', $this->Priority);
388-    $result .= $this->HeaderLine('X-Mailer', 'PHPMailer '.$this->Version.' (phpmailer.sourceforge.net)');
389+    if($this->XMailer) {
390+      $result .= $this->HeaderLine('X-Mailer', $this->XMailer);
391+    } else {
392+      $result .= $this->HeaderLine('X-Mailer', 'PHPMailer '.$this->Version.' (http://code.google.com/a/apache-extras.org/p/phpmailer/)');
393+    }
394 
395     if($this->ConfirmReadingTo != '') {
396       $result .= $this->HeaderLine('Disposition-Notification-To', '<' . trim($this->ConfirmReadingTo) . '>');
397@@ -1158,18 +1223,21 @@
398     switch($this->message_type) {
399       case 'plain':
400         $result .= $this->HeaderLine('Content-Transfer-Encoding', $this->Encoding);
401-        $result .= sprintf("Content-Type: %s; charset=\"%s\"", $this->ContentType, $this->CharSet);
402+        $result .= $this->TextLine('Content-Type: '.$this->ContentType.'; charset="'.$this->CharSet.'"');
403         break;
404-      case 'attachments':
405-      case 'alt_attachments':
406-        if($this->InlineImageExists()){
407-          $result .= sprintf("Content-Type: %s;%s\ttype=\"text/html\";%s\tboundary=\"%s\"%s", 'multipart/related', $this->LE, $this->LE, $this->boundary[1], $this->LE);
408-        } else {
409-          $result .= $this->HeaderLine('Content-Type', 'multipart/mixed;');
410-          $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
411-        }
412+      case 'inline':
413+        $result .= $this->HeaderLine('Content-Type', 'multipart/related;');
414+        $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
415         break;
416+      case 'attach':
417+      case 'inline_attach':
418+      case 'alt_attach':
419+      case 'alt_inline_attach':
420+        $result .= $this->HeaderLine('Content-Type', 'multipart/mixed;');
421+        $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
422+        break;
423       case 'alt':
424+      case 'alt_inline':
425         $result .= $this->HeaderLine('Content-Type', 'multipart/alternative;');
426         $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
427         break;
428@@ -1197,6 +1265,33 @@
429     $this->SetWordWrap();
430 
431     switch($this->message_type) {
432+      case 'plain':
433+        $body .= $this->EncodeString($this->Body, $this->Encoding);
434+        break;
435+      case 'inline':
436+        $body .= $this->GetBoundary($this->boundary[1], '', '', '');
437+        $body .= $this->EncodeString($this->Body, $this->Encoding);
438+        $body .= $this->LE.$this->LE;
439+        $body .= $this->AttachAll("inline", $this->boundary[1]);
440+        break;
441+      case 'attach':
442+        $body .= $this->GetBoundary($this->boundary[1], '', '', '');
443+        $body .= $this->EncodeString($this->Body, $this->Encoding);
444+        $body .= $this->LE.$this->LE;
445+        $body .= $this->AttachAll("attachment", $this->boundary[1]);
446+        break;
447+      case 'inline_attach':
448+        $body .= $this->TextLine("--" . $this->boundary[1]);
449+        $body .= $this->HeaderLine('Content-Type', 'multipart/related;');
450+        $body .= $this->TextLine("\tboundary=\"" . $this->boundary[2] . '"');
451+        $body .= $this->LE;
452+        $body .= $this->GetBoundary($this->boundary[2], '', '', '');
453+        $body .= $this->EncodeString($this->Body, $this->Encoding);
454+        $body .= $this->LE.$this->LE;
455+        $body .= $this->AttachAll("inline", $this->boundary[2]);
456+        $body .= $this->LE;
457+        $body .= $this->AttachAll("attachment", $this->boundary[1]);
458+        break;
459       case 'alt':
460         $body .= $this->GetBoundary($this->boundary[1], '', 'text/plain', '');
461         $body .= $this->EncodeString($this->AltBody, $this->Encoding);
462@@ -1206,26 +1301,56 @@
463         $body .= $this->LE.$this->LE;
464         $body .= $this->EndBoundary($this->boundary[1]);
465         break;
466-      case 'plain':
467+      case 'alt_inline':
468+        $body .= $this->GetBoundary($this->boundary[1], '', 'text/plain', '');
469+        $body .= $this->EncodeString($this->AltBody, $this->Encoding);
470+        $body .= $this->LE.$this->LE;
471+        $body .= $this->TextLine("--" . $this->boundary[1]);
472+        $body .= $this->HeaderLine('Content-Type', 'multipart/related;');
473+        $body .= $this->TextLine("\tboundary=\"" . $this->boundary[2] . '"');
474+        $body .= $this->LE;
475+        $body .= $this->GetBoundary($this->boundary[2], '', 'text/html', '');
476         $body .= $this->EncodeString($this->Body, $this->Encoding);
477+        $body .= $this->LE.$this->LE;
478+        $body .= $this->AttachAll("inline", $this->boundary[2]);
479+        $body .= $this->LE;
480+        $body .= $this->EndBoundary($this->boundary[1]);
481         break;
482-      case 'attachments':
483-        $body .= $this->GetBoundary($this->boundary[1], '', '', '');
484+      case 'alt_attach':
485+        $body .= $this->TextLine("--" . $this->boundary[1]);
486+        $body .= $this->HeaderLine('Content-Type', 'multipart/alternative;');
487+        $body .= $this->TextLine("\tboundary=\"" . $this->boundary[2] . '"');
488+        $body .= $this->LE;
489+        $body .= $this->GetBoundary($this->boundary[2], '', 'text/plain', '');
490+        $body .= $this->EncodeString($this->AltBody, $this->Encoding);
491+        $body .= $this->LE.$this->LE;
492+        $body .= $this->GetBoundary($this->boundary[2], '', 'text/html', '');
493         $body .= $this->EncodeString($this->Body, $this->Encoding);
494+        $body .= $this->LE.$this->LE;
495+        $body .= $this->EndBoundary($this->boundary[2]);
496         $body .= $this->LE;
497-        $body .= $this->AttachAll();
498+        $body .= $this->AttachAll("attachment", $this->boundary[1]);
499         break;
500-      case 'alt_attachments':
501-        $body .= sprintf("--%s%s", $this->boundary[1], $this->LE);
502-        $body .= sprintf("Content-Type: %s;%s" . "\tboundary=\"%s\"%s", 'multipart/alternative', $this->LE, $this->boundary[2], $this->LE.$this->LE);
503-        $body .= $this->GetBoundary($this->boundary[2], '', 'text/plain', '') . $this->LE; // Create text body
504+      case 'alt_inline_attach':
505+        $body .= $this->TextLine("--" . $this->boundary[1]);
506+        $body .= $this->HeaderLine('Content-Type', 'multipart/alternative;');
507+        $body .= $this->TextLine("\tboundary=\"" . $this->boundary[2] . '"');
508+        $body .= $this->LE;
509+        $body .= $this->GetBoundary($this->boundary[2], '', 'text/plain', '');
510         $body .= $this->EncodeString($this->AltBody, $this->Encoding);
511         $body .= $this->LE.$this->LE;
512-        $body .= $this->GetBoundary($this->boundary[2], '', 'text/html', '') . $this->LE; // Create the HTML body
513+        $body .= $this->TextLine("--" . $this->boundary[2]);
514+        $body .= $this->HeaderLine('Content-Type', 'multipart/related;');
515+        $body .= $this->TextLine("\tboundary=\"" . $this->boundary[3] . '"');
516+        $body .= $this->LE;
517+        $body .= $this->GetBoundary($this->boundary[3], '', 'text/html', '');
518         $body .= $this->EncodeString($this->Body, $this->Encoding);
519         $body .= $this->LE.$this->LE;
520+        $body .= $this->AttachAll("inline", $this->boundary[3]);
521+        $body .= $this->LE;
522         $body .= $this->EndBoundary($this->boundary[2]);
523-        $body .= $this->AttachAll();
524+        $body .= $this->LE;
525+        $body .= $this->AttachAll("attachment", $this->boundary[1]);
526         break;
527     }
528 
529@@ -1258,9 +1383,10 @@
530 
531   /**
532    * Returns the start of a message boundary.
533-   * @access private
534+   * @access protected
535+   * @return string
536    */
537-  private function GetBoundary($boundary, $charSet, $contentType, $encoding) {
538+  protected function GetBoundary($boundary, $charSet, $contentType, $encoding) {
539     $result = '';
540     if($charSet == '') {
541       $charSet = $this->CharSet;
542@@ -1272,7 +1398,7 @@
543       $encoding = $this->Encoding;
544     }
545     $result .= $this->TextLine('--' . $boundary);
546-    $result .= sprintf("Content-Type: %s; charset = \"%s\"", $contentType, $charSet);
547+    $result .= sprintf("Content-Type: %s; charset=\"%s\"", $contentType, $charSet);
548     $result .= $this->LE;
549     $result .= $this->HeaderLine('Content-Transfer-Encoding', $encoding);
550     $result .= $this->LE;
551@@ -1282,31 +1408,25 @@
552 
553   /**
554    * Returns the end of a message boundary.
555-   * @access private
556+   * @access protected
557+   * @return string
558    */
559-  private function EndBoundary($boundary) {
560+  protected function EndBoundary($boundary) {
561     return $this->LE . '--' . $boundary . '--' . $this->LE;
562   }
563 
564   /**
565    * Sets the message type.
566-   * @access private
567+   * @access protected
568    * @return void
569    */
570-  private function SetMessageType() {
571-    if(count($this->attachment) < 1 && strlen($this->AltBody) < 1) {
572-      $this->message_type = 'plain';
573-    } else {
574-      if(count($this->attachment) > 0) {
575-        $this->message_type = 'attachments';
576-      }
577-      if(strlen($this->AltBody) > 0 && count($this->attachment) < 1) {
578-        $this->message_type = 'alt';
579-      }
580-      if(strlen($this->AltBody) > 0 && count($this->attachment) > 0) {
581-        $this->message_type = 'alt_attachments';
582-      }
583-    }
584+  protected function SetMessageType() {
585+    $this->message_type = array();
586+    if($this->AlternativeExists()) $this->message_type[] = "alt";
587+    if($this->InlineImageExists()) $this->message_type[] = "inline";
588+    if($this->AttachmentExists()) $this->message_type[] = "attach";
589+    $this->message_type = implode("_", $this->message_type);
590+    if($this->message_type == "") $this->message_type = "plain";
591   }
592 
593   /**
594@@ -1386,10 +1506,10 @@
595   /**
596    * Attaches all fs, string, and binary attachments to the message.
597    * Returns an empty string on failure.
598-   * @access private
599+   * @access protected
600    * @return string
601    */
602-  private function AttachAll() {
603+  protected function AttachAll($disposition_type, $boundary) {
604     // Return text of body
605     $mime = array();
606     $cidUniq = array();
607@@ -1397,54 +1517,58 @@
608 
609     // Add all attachments
610     foreach ($this->attachment as $attachment) {
611-      // Check for string attachment
612-      $bString = $attachment[5];
613-      if ($bString) {
614-        $string = $attachment[0];
615-      } else {
616-        $path = $attachment[0];
617-      }
618+      // CHECK IF IT IS A VALID DISPOSITION_FILTER
619+      if($attachment[6] == $disposition_type) {
620+        // Check for string attachment
621+        $bString = $attachment[5];
622+        if ($bString) {
623+          $string = $attachment[0];
624+        } else {
625+          $path = $attachment[0];
626+        }
627 
628-      if (in_array($attachment[0], $incl)) { continue; }
629-      $filename    = $attachment[1];
630-      $name        = $attachment[2];
631-      $encoding    = $attachment[3];
632-      $type        = $attachment[4];
633-      $disposition = $attachment[6];
634-      $cid         = $attachment[7];
635-      $incl[]      = $attachment[0];
636-      if ( $disposition == 'inline' && isset($cidUniq[$cid]) ) { continue; }
637-      $cidUniq[$cid] = true;
638+        $inclhash = md5(serialize($attachment));
639+        if (in_array($inclhash, $incl)) { continue; }
640+        $incl[]      = $inclhash;
641+        $filename    = $attachment[1];
642+        $name        = $attachment[2];
643+        $encoding    = $attachment[3];
644+        $type        = $attachment[4];
645+        $disposition = $attachment[6];
646+        $cid         = $attachment[7];
647+        if ( $disposition == 'inline' && isset($cidUniq[$cid]) ) { continue; }
648+        $cidUniq[$cid] = true;
649 
650-      $mime[] = sprintf("--%s%s", $this->boundary[1], $this->LE);
651-      $mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $this->EncodeHeader($this->SecureHeader($name)), $this->LE);
652-      $mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE);
653+        $mime[] = sprintf("--%s%s", $boundary, $this->LE);
654+        $mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $this->EncodeHeader($this->SecureHeader($name)), $this->LE);
655+        $mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE);
656 
657-      if($disposition == 'inline') {
658-        $mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE);
659-      }
660+        if($disposition == 'inline') {
661+          $mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE);
662+        }
663 
664-      $mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s", $disposition, $this->EncodeHeader($this->SecureHeader($name)), $this->LE.$this->LE);
665+        $mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s", $disposition, $this->EncodeHeader($this->SecureHeader($name)), $this->LE.$this->LE);
666 
667-      // Encode as string attachment
668-      if($bString) {
669-        $mime[] = $this->EncodeString($string, $encoding);
670-        if($this->IsError()) {
671-          return '';
672+        // Encode as string attachment
673+        if($bString) {
674+          $mime[] = $this->EncodeString($string, $encoding);
675+          if($this->IsError()) {
676+            return '';
677+          }
678+          $mime[] = $this->LE.$this->LE;
679+        } else {
680+          $mime[] = $this->EncodeFile($path, $encoding);
681+          if($this->IsError()) {
682+            return '';
683+          }
684+          $mime[] = $this->LE.$this->LE;
685         }
686-        $mime[] = $this->LE.$this->LE;
687-      } else {
688-        $mime[] = $this->EncodeFile($path, $encoding);
689-        if($this->IsError()) {
690-          return '';
691-        }
692-        $mime[] = $this->LE.$this->LE;
693       }
694     }
695 
696-    $mime[] = sprintf("--%s--%s", $this->boundary[1], $this->LE);
697+    $mime[] = sprintf("--%s--%s", $boundary, $this->LE);
698 
699-    return join('', $mime);
700+    return implode("", $mime);
701   }
702 
703   /**
704@@ -1453,10 +1577,10 @@
705    * @param string $path The full path to the file
706    * @param string $encoding The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable'
707    * @see EncodeFile()
708-   * @access private
709+   * @access protected
710    * @return string
711    */
712-  private function EncodeFile($path, $encoding = 'base64') {
713+  protected function EncodeFile($path, $encoding = 'base64') {
714     try {
715       if (!is_readable($path)) {
716         throw new phpmailerException($this->Lang('file_open') . $path, self::STOP_CONTINUE);
717@@ -1466,13 +1590,15 @@
718           return false;
719         }
720       }
721-      if (PHP_VERSION < 6) {
722+      if (version_compare(PHP_VERSION, '5.3.0', '<')) {
723         $magic_quotes = get_magic_quotes_runtime();
724         set_magic_quotes_runtime(0);
725       }
726       $file_buffer  = file_get_contents($path);
727       $file_buffer  = $this->EncodeString($file_buffer, $encoding);
728-      if (PHP_VERSION < 6) { set_magic_quotes_runtime($magic_quotes); }
729+      if (version_compare(PHP_VERSION, '5.3.0', '<')) {
730+        set_magic_quotes_runtime($magic_quotes);
731+      }
732       return $file_buffer;
733     } catch (Exception $e) {
734       $this->SetError($e->getMessage());
735@@ -1488,7 +1614,7 @@
736    * @access public
737    * @return string
738    */
739-  public function EncodeString ($str, $encoding = 'base64') {
740+  public function EncodeString($str, $encoding = 'base64') {
741     $encoded = '';
742     switch(strtolower($encoding)) {
743       case 'base64':
744@@ -1637,7 +1763,7 @@
745   * @return string
746   */
747   public function EncodeQPphp( $input = '', $line_max = 76, $space_conv = false) {
748-    $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
749+    $hex = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F');
750     $lines = preg_split('/(?:\r\n|\r|\n)/', $input);
751     $eol = "\r\n";
752     $escape = '=';
753@@ -1718,7 +1844,7 @@
754    * @access public
755    * @return string
756    */
757-  public function EncodeQ ($str, $position = 'text') {
758+  public function EncodeQ($str, $position = 'text') {
759     // There should not be any EOL in the string
760     $encoded = preg_replace('/[\r\n]*/', '', $str);
761 
762@@ -1733,7 +1859,7 @@
763         // Replace every high ascii, control =, ? and _ characters
764         //TODO using /e (equivalent to eval()) is probably not a good idea
765         $encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e',
766-              "'='.sprintf('%02X', ord('\\1'))", $encoded);
767+                                "'='.sprintf('%02X', ord(stripslashes('\\1')))", $encoded);
768         break;
769     }
770 
771@@ -1807,6 +1933,20 @@
772     return true;
773   }
774 
775+  public function AddStringEmbeddedImage($string, $cid, $filename = '', $encoding = 'base64', $type = 'application/octet-stream') {
776+    // Append to $attachment array
777+    $this->attachment[] = array(
778+      0 => $string,
779+      1 => $filename,
780+      2 => basename($filename),
781+      3 => $encoding,
782+      4 => $type,
783+      5 => true,  // isStringAttachment
784+      6 => 'inline',
785+      7 => $cid
786+    );
787+  }
788+
789   /**
790    * Returns true if an inline attachment is present.
791    * @access public
792@@ -1821,6 +1961,19 @@
793     return false;
794   }
795 
796+  public function AttachmentExists() {
797+    foreach($this->attachment as $attachment) {
798+      if ($attachment[6] == 'attachment') {
799+        return true;
800+      }
801+    }
802+    return false;
803+  }
804+
805+  public function AlternativeExists() {
806+    return strlen($this->AltBody)>0;
807+  }
808+
809   /////////////////////////////////////////////////
810   // CLASS METHODS, MESSAGE RESET
811   /////////////////////////////////////////////////
812@@ -1933,10 +2086,10 @@
813 
814   /**
815    * Returns the server hostname or 'localhost.localdomain' if unknown.
816-   * @access private
817+   * @access protected
818    * @return string
819    */
820-  private function ServerHostname() {
821+  protected function ServerHostname() {
822     if (!empty($this->Hostname)) {
823       $result = $this->Hostname;
824     } elseif (isset($_SERVER['SERVER_NAME'])) {
825@@ -1950,10 +2103,10 @@
826 
827   /**
828    * Returns a message in the appropriate language.
829-   * @access private
830+   * @access protected
831    * @return string
832    */
833-  private function Lang($key) {
834+  protected function Lang($key) {
835     if(count($this->language) < 1) {
836       $this->SetLanguage('en'); // set the default language
837     }
838@@ -1976,10 +2129,10 @@
839 
840   /**
841    * Changes every end of line from CR or LF to CRLF.
842-   * @access private
843+   * @access public
844    * @return string
845    */
846-  private function FixEOL($str) {
847+  public function FixEOL($str) {
848     $str = str_replace("\r\n", "\n", $str);
849     $str = str_replace("\r", "\n", $str);
850     $str = str_replace("\n", $this->LE, $str);
851@@ -2005,16 +2158,16 @@
852     if(isset($images[2])) {
853       foreach($images[2] as $i => $url) {
854         // do not change urls for absolute images (thanks to corvuscorax)
855-        if (!preg_match('#^[A-z]+://#',$url)) {
856+        if (!preg_match('#^[A-z]+://#', $url)) {
857           $filename = basename($url);
858           $directory = dirname($url);
859-          ($directory == '.')?$directory='':'';
860+          ($directory == '.') ? $directory='': '';
861           $cid = 'cid:' . md5($filename);
862           $ext = pathinfo($filename, PATHINFO_EXTENSION);
863           $mimeType  = self::_mime_types($ext);
864-          if ( strlen($basedir) > 1 && substr($basedir,-1) != '/') { $basedir .= '/'; }
865-          if ( strlen($directory) > 1 && substr($directory,-1) != '/') { $directory .= '/'; }
866-          if ( $this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64',$mimeType) ) {
867+          if ( strlen($basedir) > 1 && substr($basedir, -1) != '/') { $basedir .= '/'; }
868+          if ( strlen($directory) > 1 && substr($directory, -1) != '/') { $directory .= '/'; }
869+          if ( $this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64', $mimeType) ) {
870             $message = preg_replace("/".$images[1][$i]."=\"".preg_quote($url, '/')."\"/Ui", $images[1][$i]."=\"".$cid."\"", $message);
871           }
872         }
873@@ -2022,7 +2175,7 @@
874     }
875     $this->IsHTML(true);
876     $this->Body = $message;
877-    $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s','',$message)));
878+    $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s', '', $message)));
879     if (!empty($textMsg) && empty($this->AltBody)) {
880       $this->AltBody = html_entity_decode($textMsg);
881     }
882@@ -2192,14 +2345,14 @@
883    * @param string $key_pass Password for private key
884    */
885   public function DKIM_QP($txt) {
886-    $tmp="";
887-    $line="";
888-    for ($i=0;$i<strlen($txt);$i++) {
889-      $ord=ord($txt[$i]);
890+    $tmp = '';
891+    $line = '';
892+    for ($i = 0; $i < strlen($txt); $i++) {
893+      $ord = ord($txt[$i]);
894       if ( ((0x21 <= $ord) && ($ord <= 0x3A)) || $ord == 0x3C || ((0x3E <= $ord) && ($ord <= 0x7E)) ) {
895-        $line.=$txt[$i];
896+        $line .= $txt[$i];
897       } else {
898-        $line.="=".sprintf("%02X",$ord);
899+        $line .= "=".sprintf("%02X", $ord);
900       }
901     }
902     return $line;
903@@ -2213,8 +2366,8 @@
904    */
905   public function DKIM_Sign($s) {
906     $privKeyStr = file_get_contents($this->DKIM_private);
907-    if ($this->DKIM_passphrase!='') {
908-      $privKey = openssl_pkey_get_private($privKeyStr,$this->DKIM_passphrase);
909+    if ($this->DKIM_passphrase != '') {
910+      $privKey = openssl_pkey_get_private($privKeyStr, $this->DKIM_passphrase);
911     } else {
912       $privKey = $privKeyStr;
913     }
914@@ -2230,15 +2383,15 @@
915    * @param string $s Header
916    */
917   public function DKIM_HeaderC($s) {
918-    $s=preg_replace("/\r\n\s+/"," ",$s);
919-    $lines=explode("\r\n",$s);
920-    foreach ($lines as $key=>$line) {
921-      list($heading,$value)=explode(":",$line,2);
922-      $heading=strtolower($heading);
923-      $value=preg_replace("/\s+/"," ",$value) ; // Compress useless spaces
924-      $lines[$key]=$heading.":".trim($value) ; // Don't forget to remove WSP around the value
925+    $s = preg_replace("/\r\n\s+/", " ", $s);
926+    $lines = explode("\r\n", $s);
927+    foreach ($lines as $key => $line) {
928+      list($heading, $value) = explode(":", $line, 2);
929+      $heading = strtolower($heading);
930+      $value = preg_replace("/\s+/", " ", $value) ; // Compress useless spaces
931+      $lines[$key] = $heading.":".trim($value) ; // Don't forget to remove WSP around the value
932     }
933-    $s=implode("\r\n",$lines);
934+    $s = implode("\r\n", $lines);
935     return $s;
936   }
937 
938@@ -2251,11 +2404,11 @@
939   public function DKIM_BodyC($body) {
940     if ($body == '') return "\r\n";
941     // stabilize line endings
942-    $body=str_replace("\r\n","\n",$body);
943-    $body=str_replace("\n","\r\n",$body);
944+    $body = str_replace("\r\n", "\n", $body);
945+    $body = str_replace("\n", "\r\n", $body);
946     // END stabilize line endings
947-    while (substr($body,strlen($body)-4,4) == "\r\n\r\n") {
948-      $body=substr($body,0,strlen($body)-2);
949+    while (substr($body, strlen($body) - 4, 4) == "\r\n\r\n") {
950+      $body = substr($body, 0, strlen($body) - 2);
951     }
952     return $body;
953   }
954@@ -2268,23 +2421,23 @@
955    * @param string $subject Subject
956    * @param string $body Body
957    */
958-  public function DKIM_Add($headers_line,$subject,$body) {
959+  public function DKIM_Add($headers_line, $subject, $body) {
960     $DKIMsignatureType    = 'rsa-sha1'; // Signature & hash algorithms
961     $DKIMcanonicalization = 'relaxed/simple'; // Canonicalization of header/body
962     $DKIMquery            = 'dns/txt'; // Query method
963     $DKIMtime             = time() ; // Signature Timestamp = seconds since 00:00:00 - Jan 1, 1970 (UTC time zone)
964     $subject_header       = "Subject: $subject";
965-    $headers              = explode("\r\n",$headers_line);
966+    $headers              = explode($this->LE, $headers_line);
967     foreach($headers as $header) {
968-      if (strpos($header,'From:') === 0) {
969-        $from_header=$header;
970-      } elseif (strpos($header,'To:') === 0) {
971-        $to_header=$header;
972+      if (strpos($header, 'From:') === 0) {
973+        $from_header = $header;
974+      } elseif (strpos($header, 'To:') === 0) {
975+        $to_header = $header;
976       }
977     }
978-    $from     = str_replace('|','=7C',$this->DKIM_QP($from_header));
979-    $to       = str_replace('|','=7C',$this->DKIM_QP($to_header));
980-    $subject  = str_replace('|','=7C',$this->DKIM_QP($subject_header)) ; // Copied header fields (dkim-quoted-printable
981+    $from     = str_replace('|', '=7C', $this->DKIM_QP($from_header));
982+    $to       = str_replace('|', '=7C', $this->DKIM_QP($to_header));
983+    $subject  = str_replace('|', '=7C', $this->DKIM_QP($subject_header)) ; // Copied header fields (dkim-quoted-printable
984     $body     = $this->DKIM_BodyC($body);
985     $DKIMlen  = strlen($body) ; // Length of body
986     $DKIMb64  = base64_encode(pack("H*", sha1($body))) ; // Base64 of packed binary SHA-1 hash of body
987@@ -2303,10 +2456,10 @@
988     return "X-PHPMAILER-DKIM: phpmailer.worxware.com\r\n".$dkimhdrs.$signed."\r\n";
989   }
990 
991-  protected function doCallback($isSent,$to,$cc,$bcc,$subject,$body) {
992+  protected function doCallback($isSent, $to, $cc, $bcc, $subject, $body) {
993     if (!empty($this->action_function) && function_exists($this->action_function)) {
994-      $params = array($isSent,$to,$cc,$bcc,$subject,$body);
995-      call_user_func_array($this->action_function,$params);
996+      $params = array($isSent, $to, $cc, $bcc, $subject, $body);
997+      call_user_func_array($this->action_function, $params);
998     }
999   }
1000 }
1001@@ -2317,4 +2470,4 @@
1002     return $errorMsg;
1003   }
1004 }
1005-?>
1006\ No newline at end of file
1007+?>
1008Index: class-smtp.php
1009===================================================================
1010--- class-smtp.php      (revision 19631)
1011+++ class-smtp.php      (working copy)
1012@@ -2,15 +2,15 @@
1013 /*~ class.smtp.php
1014 .---------------------------------------------------------------------------.
1015 |  Software: PHPMailer - PHP email class                                    |
1016-|   Version: 5.1                                                            |
1017-|   Contact: via sourceforge.net support pages (also www.codeworxtech.com)  |
1018-|      Info: http://phpmailer.sourceforge.net                               |
1019-|   Support: http://sourceforge.net/projects/phpmailer/                     |
1020+|   Version: 5.2                                                            |
1021+|      Site: https://code.google.com/a/apache-extras.org/p/phpmailer/       |
1022 | ------------------------------------------------------------------------- |
1023-|     Admin: Andy Prevost (project admininistrator)                         |
1024+|     Admin: Jim Jagielski (project admininistrator)                        |
1025 |   Authors: Andy Prevost (codeworxtech) codeworxtech@users.sourceforge.net |
1026 |          : Marcus Bointon (coolbru) coolbru@users.sourceforge.net         |
1027+|          : Jim Jagielski (jimjag) jimjag@gmail.com                        |
1028 |   Founder: Brent R. Matzelle (original founder)                           |
1029+| Copyright (c) 2010-2011, Jim Jagielski. All Rights Reserved.               |
1030 | Copyright (c) 2004-2009, Andy Prevost. All Rights Reserved.               |
1031 | Copyright (c) 2001-2003, Brent R. Matzelle                                |
1032 | ------------------------------------------------------------------------- |
1033@@ -19,11 +19,6 @@
1034 | This program is distributed in the hope that it will be useful - WITHOUT  |
1035 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or     |
1036 | FITNESS FOR A PARTICULAR PURPOSE.                                         |
1037-| ------------------------------------------------------------------------- |
1038-| We offer a number of paid services (www.codeworxtech.com):                |
1039-| - Web Hosting on highly optimized fast and secure servers                 |
1040-| - Technology Consulting                                                   |
1041-| - Oursourcing (highly qualified programmers and graphic designers)        |
1042 '---------------------------------------------------------------------------'
1043 */
1044 
1045@@ -34,8 +29,10 @@
1046  * @author Andy Prevost
1047  * @author Marcus Bointon
1048  * @copyright 2004 - 2008 Andy Prevost
1049+ * @author Jim Jagielski
1050+ * @copyright 2010 - 2011 Jim Jagielski
1051  * @license http://www.gnu.org/copyleft/lesser.html Distributed under the Lesser General Public License (LGPL)
1052- * @version $Id: class.smtp.php 444 2009-05-05 11:22:26Z coolbru $
1053+ * @version $Id: class.smtp.php 450 2010-06-23 16:46:33Z coolbru $
1054  */
1055 
1056 /**
1057@@ -71,6 +68,12 @@
1058    */
1059   public $do_verp = false;
1060 
1061+  /**
1062+   * Sets the SMTP PHPMailer Version number
1063+   * @var string
1064+   */
1065+  public $Version         = '5.2';
1066+
1067   /////////////////////////////////////////////////
1068   // PROPERTIES, PRIVATE AND PROTECTED
1069   /////////////////////////////////////////////////
1070@@ -811,4 +814,4 @@
1071 
1072 }
1073 
1074-?>
1075\ No newline at end of file
1076+?>