phpgroupware-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Phpgroupware-cvs] felamimail/inc class.phpmailer.inc.php


From: Sigurd Nes
Subject: [Phpgroupware-cvs] felamimail/inc class.phpmailer.inc.php
Date: Wed, 21 Feb 2007 13:05:02 +0000

CVSROOT:        /sources/phpgroupware
Module name:    felamimail
Changes by:     Sigurd Nes <sigurdne>   07/02/21 13:05:02

Modified files:
        inc            : class.phpmailer.inc.php 

Log message:
        update from upstream

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/felamimail/inc/class.phpmailer.inc.php?cvsroot=phpgroupware&r1=1.4&r2=1.5

Patches:
Index: class.phpmailer.inc.php
===================================================================
RCS file: /sources/phpgroupware/felamimail/inc/class.phpmailer.inc.php,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- class.phpmailer.inc.php     21 Feb 2007 12:24:21 -0000      1.4
+++ class.phpmailer.inc.php     21 Feb 2007 13:05:02 -0000      1.5
@@ -1,21 +1,21 @@
 <?php
 ////////////////////////////////////////////////////
-// phpmailer - PHP email class
-//
-// Version 1.65, Created 08/09/2002
+// PHPMailer - PHP email class
 //
 // Class for sending email using either
 // sendmail, PHP mail(), or SMTP.  Methods are
 // based upon the standard AspEmail(tm) classes.
 //
-// Author: Brent R. Matzelle <address@hidden>
+// Copyright (C) 2001 - 2003  Brent R. Matzelle
 //
 // License: LGPL, see LICENSE
 ////////////////////////////////////////////////////
 
 /**
- * phpmailer - PHP email transport class
+ * PHPMailer - PHP email transport class
+ * @package PHPMailer
  * @author Brent R. Matzelle
+ * @copyright 2001 - 2003 Brent R. Matzelle
  */
 class phpmailer
 {
@@ -25,21 +25,18 @@
 
     /**
      * Email priority (1 = High, 3 = Normal, 5 = low).
-     * @access public
      * @var int
      */
     var $Priority          = 3;
 
     /**
      * Sets the CharSet of the message.
-     * @access public
      * @var string
      */
-    var $CharSet           = "utf-8";
+    var $CharSet           = "iso-8859-1";
 
     /**
      * Sets the Content-type of the message.
-     * @access public
      * @var string
      */
     var $ContentType        = "text/plain";
@@ -47,43 +44,37 @@
     /**
      * Sets the Encoding of the message. Options for this are "8bit",
      * "7bit", "binary", "base64", and "quoted-printable".
-     * @access public
      * @var string
      */
     var $Encoding          = "8bit";
 
     /**
      * Holds the most recent mailer error message.
-     * @access public
      * @var string
      */
     var $ErrorInfo         = "";
 
     /**
      * Sets the From email address for the message.
-     * @access public
      * @var string
      */
     var $From               = "address@hidden";
 
     /**
      * Sets the From name of the message.
-     * @access public
      * @var string
      */
     var $FromName           = "Root User";
 
     /**
-     * Sets the Sender email of the message. If not empty, will be sent via -f 
to sendmail
-     * or as 'MAIL FROM' in smtp mode.
-     * @access public
+     * Sets the Sender email (Return-Path) of the message.  If not empty,
+     * will be sent via -f to sendmail or as 'MAIL FROM' in smtp mode.
      * @var string
      */
     var $Sender            = "";
 
     /**
      * Sets the Subject of the message.
-     * @access public
      * @var string
      */
     var $Subject           = "";
@@ -91,7 +82,6 @@
     /**
      * Sets the Body of the message.  This can be either an HTML or text body.
      * If HTML then run IsHTML(true).
-     * @access public
      * @var string
      */
     var $Body               = "";
@@ -101,7 +91,6 @@
      * email to multipart/alternative.  This body can be read by mail
      * clients that do not have HTML email capability such as mutt. Clients
      * that can read HTML will view the normal Body.
-     * @access public
      * @var string
      */
     var $AltBody           = "";
@@ -109,72 +98,49 @@
     /**
      * Sets word wrapping on the body of the message to a given number of 
      * characters.
-     * @access public
      * @var int
      */
     var $WordWrap          = 0;
 
     /**
      * Method to send mail: ("mail", "sendmail", or "smtp").
-     * @access public
      * @var string
      */
     var $Mailer            = "mail";
 
     /**
      * Sets the path of the sendmail program.
-     * @access public
      * @var string
      */
     var $Sendmail          = "/usr/sbin/sendmail";
 
     /**
-     *  Turns Microsoft mail client headers on and off.  Useful mostly
-     *  for older clients.
-     *  @access public
-     *  @var bool
-     */
-    var $UseMSMailHeaders = false;
-    
-    /**
-     * Path to phpmailer plugins.  This is now only useful if the SMTP class 
+     * Path to PHPMailer plugins.  This is now only useful if the SMTP class 
      * is in a different directory than the PHP include path.  
-     * @access public
      * @var string
      */
     var $PluginDir         = "";
 
     /**
-     *  Holds phpmailer version.
-     *  @access public
+     *  Holds PHPMailer version.
      *  @var string
      */
-    var $Version           = "1.65";
+    var $Version           = "1.73";
 
     /**
      * Sets the email address that a reading confirmation will be sent.
-     * @access public
      * @var string
      */
     var $ConfirmReadingTo  = "";
 
     /**
-     *  Sets the line endings of the message.
-     *  @access public
-     *  @var string
-     */
-    var $LE           = "\n";
-
-    /**
      *  Sets the hostname to use in Message-Id and Received headers
      *  and as default HELO string. If empty, the value returned
      *  by SERVER_NAME is used or 'localhost.localdomain'.
-     *  @access public
      *  @var string
      */
     var $Hostname          = "";
 
-
     /////////////////////////////////////////////////
     // SMTP VARIABLES
     /////////////////////////////////////////////////
@@ -185,42 +151,36 @@
      *  for each host by using this format: [hostname:port]
      *  (e.g. "smtp1.example.com:25;smtp2.example.com").
      *  Hosts will be tried in order.
-     *  @access public
      *  @var string
      */
     var $Host        = "localhost";
 
     /**
      *  Sets the default SMTP server port.
-     *  @access public
      *  @var int
      */
     var $Port        = 25;
 
     /**
      *  Sets the SMTP HELO of the message (Default is $Hostname).
-     *  @access public
      *  @var string
      */
     var $Helo        = "";
 
     /**
      *  Sets SMTP authentication. Utilizes the Username and Password variables.
-     *  @access public
      *  @var bool
      */
     var $SMTPAuth     = false;
 
     /**
      *  Sets SMTP username.
-     *  @access public
      *  @var string
      */
     var $Username     = "";
 
     /**
      *  Sets SMTP password.
-     *  @access public
      *  @var string
      */
     var $Password     = "";
@@ -228,83 +188,50 @@
     /**
      *  Sets the SMTP server timeout in seconds. This function will not 
      *  work with the win32 version.
-     *  @access public
      *  @var int
      */
     var $Timeout      = 10;
 
     /**
      *  Sets SMTP class debugging on or off.
-     *  @access public
      *  @var bool
      */
     var $SMTPDebug    = false;
 
-
-    /////////////////////////////////////////////////
-    // PRIVATE VARIABLES
-    /////////////////////////////////////////////////
-
     /**
-     *  Holds all "To" addresses.
-     *  @access private
-     *  @var array
+     * Prevents the SMTP connection from being closed after each mail 
+     * sending.  If this is set to true then to close the connection 
+     * requires an explicit call to SmtpClose(). 
+     * @var bool
      */
-    var $to              = array();
+    var $SMTPKeepAlive = false;
 
-    /**
-     *  Holds all "CC" addresses.
+    /address@hidden
      *  @access private
-     *  @var array
      */
+    var $smtp            = NULL;
+    var $to              = array();
     var $cc              = array();
-
-    /**
-     *  Holds all "BCC" addresses.
-     *  @access private
-     *  @var array
-     */
     var $bcc             = array();
-
-    /**
-     *  Holds all "Reply-To" addresses.
-     *  @var array
-     */
     var $ReplyTo         = array();
-
-    /**
-     *  Holds all string and binary attachments.
-     *  @access private
-     *  @var array
-     */
     var $attachment      = array();
-
-    /**
-     *  Holds all custom headers.
-     *  @var array
-     */
     var $CustomHeader    = array();
-
-    /**
-     *  Holds the type of the message.
-     *  @var string
-     */
     var $message_type    = "";
-
-    /**
-     *  Holds the message boundaries.
-     *  @access private
-     *  @var string array
-     */
     var $boundary        = array();
+    var $language        = array();
+    var $error_count     = 0;
+    var $LE              = "\n";
+    var $sentBody      = '';
+    var $sentHeader    = '';
+    /address@hidden/
 
     /////////////////////////////////////////////////
     // VARIABLE METHODS
     /////////////////////////////////////////////////
 
     /**
-     * Sets message type to HTML.  Returns void.
-     * @access public
+     * Sets message type to HTML.  
+     * @param bool $bool
      * @return void
      */
     function IsHTML($bool) {
@@ -316,8 +243,6 @@
 
     /**
      * Sets Mailer to send message using SMTP.
-     * Returns void.
-     * @access public
      * @return void
      */
     function IsSMTP() {
@@ -326,8 +251,6 @@
 
     /**
      * Sets Mailer to send message using PHP mail() function.
-     * Returns void.
-     * @access public
      * @return void
      */
     function IsMail() {
@@ -336,8 +259,6 @@
 
     /**
      * Sets Mailer to send message using the $Sendmail program.
-     * Returns void.
-     * @access public
      * @return void
      */
     function IsSendmail() {
@@ -345,12 +266,10 @@
     }
 
     /**
-     * Sets Mailer to send message using the qmail MTA.  Returns void.
-     * @access public
+     * Sets Mailer to send message using the qmail MTA. 
      * @return void
      */
     function IsQmail() {
-        //$this->Sendmail = "/var/qmail/bin/qmail-inject";
         $this->Sendmail = "/var/qmail/bin/sendmail";
         $this->Mailer = "sendmail";
     }
@@ -361,8 +280,9 @@
     /////////////////////////////////////////////////
 
     /**
-     * Adds a "To" address.  Returns void.
-     * @access public
+     * Adds a "To" address.  
+     * @param string $address
+     * @param string $name
      * @return void
      */
     function AddAddress($address, $name = "") {
@@ -374,10 +294,9 @@
     /**
      * Adds a "Cc" address. Note: this function works
      * with the SMTP mailer on win32, not with the "mail"
-     * mailer.  This is a PHP bug that has been submitted
-     * on http://bugs.php.net. The *NIX version of PHP
-     * functions correctly. Returns void.
-     * @access public
+     * mailer.  
+     * @param string $address
+     * @param string $name
      * @return void
     */
     function AddCC($address, $name = "") {
@@ -389,11 +308,9 @@
     /**
      * Adds a "Bcc" address. Note: this function works
      * with the SMTP mailer on win32, not with the "mail"
-     * mailer.  This is a PHP bug that has been submitted
-     * on http://bugs.php.net. The *NIX version of PHP
-     * functions correctly.
-     * Returns void.
-     * @access public
+     * mailer.  
+     * @param string $address
+     * @param string $name
      * @return void
      */
     function AddBCC($address, $name = "") {
@@ -403,8 +320,9 @@
     }
 
     /**
-     * Adds a "Reply-to" address.  Returns void.
-     * @access public
+     * Adds a "Reply-to" address.  
+     * @param string $address
+     * @param string $name
      * @return void
      */
     function AddReplyTo($address, $name = "") {
@@ -413,7 +331,21 @@
         $this->ReplyTo[$cur][1] = $name;
     }
 
+    /**
+     * Get the headers of the message sent
+     * @return string message headers
+     */
+    function getHeader(){
+        return $this->sentHeader;
+    }
 
+   /**
+    * Get the body of the message sent
+    * @returns string message body
+    */
+   function getBody(){
+       return $this->sentBody;
+   }
     /////////////////////////////////////////////////
     // MAIL SENDING METHODS
     /////////////////////////////////////////////////
@@ -421,17 +353,17 @@
     /**
      * Creates message and assigns Mailer. If the message is
      * not sent successfully then it returns false.  Use the ErrorInfo
-     * variable to view description of the error.  Returns bool.
-     * @access public
+     * variable to view description of the error.  
      * @return bool
      */
     function Send() {
         $header = "";
         $body = "";
+        $result = true;
 
         if((count($this->to) + count($this->cc) + count($this->bcc)) < 1)
         {
-            $this->error_handler("You must provide at least one recipient 
email address");
+            $this->SetError($this->Lang("provide_address"));
             return false;
         }
 
@@ -439,157 +371,42 @@
         if(!empty($this->AltBody))
             $this->ContentType = "multipart/alternative";
 
-        // Attach sender information & date
-        $header = $this->received();
-        $header .= sprintf("Date: %s%s", $this->rfc_date(), $this->LE);
-        $header .= $this->create_header();
-
-        if(!$body = $this->create_body())
-            return false;
+        $this->error_count = 0; // reset errors
+        $this->SetMessageType();
+        $header .= $this->CreateHeader();
+        $body = $this->CreateBody();
 
-        //echo "<pre>".$header . $body . "</pre>"; // debugging
+        if($body == "") { return false; }
 
         // Choose the mailer
-        if($this->Mailer == "sendmail")
-        {
-          if(!$this->sendmail_send($header, $body))
-              return false;
-        }
-        elseif($this->Mailer == "mail")
+        switch($this->Mailer)
         {
-          if(!$this->mail_send($header, $body))
-              return false;
-        }
-        elseif($this->Mailer == "smtp")
-        {
-          if(!$this->smtp_send($header, $body))
-              return false;
-        }
-        else
-        {
-            $this->error_handler(sprintf("%s mailer is not supported", 
$this->Mailer));
-            return false;
+            case "sendmail":
+                $result = $this->SendmailSend($header, $body);
+                break;
+            case "mail":
+                $result = $this->MailSend($header, $body);
+                break;
+            case "smtp":
+                $result = $this->SmtpSend($header, $body);
+                break;
+            default:
+            $this->SetError($this->Mailer . 
$this->Lang("mailer_not_supported"));
+                $result = false;
+                break;
         }
-        
+       //Readded by skwashd
        $this->sentHeader       = $header;
        $this->sentBody         = $body;
-       
-        return true;
-        
+        return $result;
     }
     
     /**
-     * Sends mail message to an assigned queue directory.  Has an optional 
-     * sendTime argument.  This is used when the user wants the 
-     * message to be sent from the queue at a predetermined time. 
-     * The data must be a valid timestamp like that returned from 
-     * the time() or strtotime() functions.  Returns false on failure 
-     * or the message file name if success.
-     * @access public
-     * @return string
-     */
-    function SendToQueue($queue_path, $send_time = 0) {
-        $message = array();
-        $header = "";
-        $body = "";
-        
-        // If invalid or empty just set to the current time
-        if($send_time == 0)
-            $send_time = time();
-        
-        if(!is_dir($queue_path))
-        {
-            $this->error_handler("The supplied queue directory does not 
exist");
-            return false;
-        }
-
-        if((count($this->to) + count($this->cc) + count($this->bcc)) < 1)
-        {
-            $this->error_handler("You must provide at least one recipient 
email address");
-            return false;
-        }
-
-        // Set whether the message is multipart/alternative
-        if(!empty($this->AltBody))
-            $this->ContentType = "multipart/alternative";
-
-        $header = $this->create_header();
-        if(!$body = $this->create_body())
-            return false;
-
-        // Seed randomizer
-        mt_srand(time());
-        $msg_id = md5(uniqid(mt_rand()));
-        
-        $fp = @fopen($queue_path . $msg_id . ".pqm", "wb");
-        if(!$fp)
-        {
-            $this->error_handler(sprintf("Could not write to %s directory", 
$queue_path));
-            return false;
-        }
-       
-        $message[] = sprintf("----START PQM HEADER----%s", $this->LE);
-        $message[] = sprintf("SendTime: %s%s", $send_time, $this->LE);
-        $message[] = sprintf("Mailer: %s%s", $this->Mailer, $this->LE);
-
-        // Choose the mailer
-        if($this->Mailer == "sendmail")
-        {
-            $message[] = sprintf("Sendmail: %s%s", $this->Sendmail, $this->LE);
-            $message[] = sprintf("Sender: %s%s", $this->Sender, $this->LE);
-        }
-        elseif($this->Mailer == "mail")
-        {
-            $message[] = sprintf("Sender: %s%s", $this->Sender, $this->LE);
-            $message[] = sprintf("Subject: %s%s", $this->Subject, $this->LE);
-            $message[] = sprintf("to: %s%s", $this->addr_list($this->to), 
$this->LE);
-        }
-        elseif($this->Mailer == "smtp")
-        {
-            $message[] = sprintf("Host: %s%s", $this->Host, $this->LE);
-            $message[] = sprintf("Port: %d%s", $this->Port, $this->LE);
-            $message[] = sprintf("Helo: %s%s", $this->Helo, $this->LE);
-            $message[] = sprintf("Timeout: %d%s", $this->Timeout, $this->LE);
-            
-            if($this->SMTPAuth)
-                $auth_no = 1;
-            else
-                $auth_no = 0;
-            $message[] = sprintf("SMTPAuth: %d%s", $auth_no, $this->LE);
-            $message[] = sprintf("Username: %s%s", $this->Username, $this->LE);
-            $message[] = sprintf("Password: %s%s", $this->Password, $this->LE);
-            $message[] = sprintf("From: %s%s", $this->From, $this->LE);
-
-            $message[] = sprintf("to: %s%s", $this->addr_list($this->to), 
$this->LE);
-            $message[] = sprintf("cc: %s%s", $this->addr_list($this->cc), 
$this->LE);
-            $message[] = sprintf("bcc: %s%s", $this->addr_list($this->bcc), 
$this->LE);
-        }
-        else
-        {
-            $this->error_handler(sprintf("%s mailer is not supported", 
$this->Mailer));
-            return false;
-        }
-
-        $message[] = sprintf("----END PQM HEADER----%s", $this->LE); // end of 
pqm header        
-        $message[] = $header;
-        $message[] = $body;
-       
-        if(fwrite($fp, join("", $message)) == -1)
-        {
-            $this->error_handler("Write to file failed");
-            return false;
-        }
-        fclose($fp);
-
-        return ($msg_id . ".pqm");
-    }
-
-    /**
-     * Sends mail using the $Sendmail program.  Returns bool.
+     * Sends mail using the $Sendmail program.  
      * @access private
      * @return bool
      */
-    function sendmail_send($header, $body) {
+    function SendmailSend($header, $body) {
         if ($this->Sender != "")
             $sendmail = sprintf("%s -oi -f %s -t", $this->Sendmail, 
$this->Sender);
         else
@@ -597,7 +414,7 @@
 
         if(address@hidden = popen($sendmail, "w"))
         {
-            $this->error_handler(sprintf("Could not execute %s", 
$this->Sendmail));
+            $this->SetError($this->Lang("execute") . $this->Sendmail);
             return false;
         }
 
@@ -607,7 +424,7 @@
         $result = pclose($mail) >> 8 & 0xFF;
         if($result != 0)
         {
-            $this->error_handler(sprintf("Could not execute %s", 
$this->Sendmail));
+            $this->SetError($this->Lang("execute") . $this->Sendmail);
             return false;
         }
 
@@ -615,41 +432,35 @@
     }
 
     /**
-     * Sends mail using the PHP mail() function.  Returns bool.
+     * Sends mail using the PHP mail() function.  
      * @access private
      * @return bool
      */
-    function mail_send($header, $body) {
-        //$to = substr($this->addr_append("To", $this->to), 4, -2);
-
-        // Cannot add Bcc's to the $to
-        $to = $this->to[0][0]; // no extra comma
-        for($i = 1; $i < count($this->to); $i++)
-            $to .= sprintf(",%s", $this->to[$i][0]);
-
-        if ($this->Sender != "" && PHP_VERSION >= "4.0")
+    function MailSend($header, $body) {
+        $to = "";
+        for($i = 0; $i < count($this->to); $i++)
         {
-            $old_from = ini_get("sendmail_from");
-            ini_set("sendmail_from", $this->Sender);
+            if($i != 0) { $to .= ", "; }
+            $to .= $this->to[$i][0];
         }
 
-        if ($this->Sender != "" && PHP_VERSION >= "4.0.5")
+        if ($this->Sender != "" && strlen(ini_get("safe_mode"))< 1)
         {
-            // The fifth parameter to mail is only available in PHP >= 4.0.5
+            $old_from = ini_get("sendmail_from");
+            ini_set("sendmail_from", $this->Sender);
             $params = sprintf("-oi -f %s", $this->Sender);
-            $rt = @mail($to, $this->encode_header($this->Subject), $body, 
$header, $params);
+            $rt = @mail($to, $this->EncodeHeader($this->Subject), $body, 
+                        $header, $params);
         }
         else
-        {
-            $rt = @mail($to, $this->encode_header($this->Subject), $body, 
$header);
-        }
+            $rt = @mail($to, $this->EncodeHeader($this->Subject), $body, 
$header);
 
         if (isset($old_from))
             ini_set("sendmail_from", $old_from);
 
         if(!$rt)
         {
-            $this->error_handler("Could not instantiate mail()");
+            $this->SetError($this->Lang("instantiate"));
             return false;
         }
 
@@ -663,21 +474,80 @@
      * @access private
      * @return bool
      */
-    function smtp_send($header, $body) {
-        // Include SMTP class code, but not twice
+    function SmtpSend($header, $body) {
         include_once($this->PluginDir . "class.smtp.php");
+        $error = "";
+        $bad_rcpt = array();
+
+        if(!$this->SmtpConnect())
+            return false;
+
+        $smtp_from = ($this->Sender == "") ? $this->From : $this->Sender;
+        if(!$this->smtp->Mail($smtp_from))
+        {
+            $error = $this->Lang("from_failed") . $smtp_from;
+            $this->SetError($error);
+            $this->smtp->Reset();
+            return false;
+        }
+
+        // Attempt to send attach all recipients
+        for($i = 0; $i < count($this->to); $i++)
+        {
+            if(!$this->smtp->Recipient($this->to[$i][0]))
+                $bad_rcpt[] = $this->to[$i][0];
+        }
+        for($i = 0; $i < count($this->cc); $i++)
+        {
+            if(!$this->smtp->Recipient($this->cc[$i][0]))
+                $bad_rcpt[] = $this->cc[$i][0];
+        }
+        for($i = 0; $i < count($this->bcc); $i++)
+        {
+            if(!$this->smtp->Recipient($this->bcc[$i][0]))
+                $bad_rcpt[] = $this->bcc[$i][0];
+        }
 
-        $smtp = new SMTP;
+        if(count($bad_rcpt) > 0) // Create error message
+        {
+            for($i = 0; $i < count($bad_rcpt); $i++)
+            {
+                if($i != 0) { $error .= ", "; }
+                $error .= $bad_rcpt[$i];
+            }
+            $error = $this->Lang("recipients_failed") . $error;
+            $this->SetError($error);
+            $this->smtp->Reset();
+            return false;
+        }
 
-        $smtp->do_debug = $this->SMTPDebug;
+        if(!$this->smtp->Data($header . $body))
+        {
+            $this->SetError($this->Lang("data_not_accepted"));
+            $this->smtp->Reset();
+            return false;
+        }
+        if($this->SMTPKeepAlive == true)
+            $this->smtp->Reset();
+        else
+            $this->SmtpClose();
 
-        // Try to connect to all SMTP servers
+        return true;
+    }
+
+    /**
+     * Initiates a connection to an SMTP server.  Returns false if the 
+     * operation failed.
+     * @access private
+     * @return bool
+     */
+    function SmtpConnect() {
+        if($this->smtp == NULL) { $this->smtp = new SMTP(); }
+
+        $this->smtp->do_debug = $this->SMTPDebug;
         $hosts = explode(";", $this->Host);
         $index = 0;
-        $connection = false;
-        $smtp_from = "";
-        $bad_rcpt = array();
-        $e = "";
+        $connection = ($this->smtp->Connected()); 
 
         // Retry while there is no connection
         while($index < count($hosts) && $connection == false)
@@ -690,131 +560,92 @@
                 $port = $this->Port;
             }
 
-            if($smtp->Connect($host, $port, $this->Timeout))
-                $connection = true;
-            //printf("%s host could not connect<br>", $hosts[$index]); //debug 
only
-            $index++;
-        }
-        if(!$connection)
+            if($this->smtp->Connect($host, $port, $this->Timeout))
         {
-            $this->error_handler("SMTP Error: could not connect to SMTP host 
server(s)");
-            return false;
-        }
-
-        // Must perform HELO before authentication
        if ($this->Helo != '')
-        $smtp->Hello($this->Helo);
+                    $this->smtp->Hello($this->Helo);
         else
-            $smtp->Hello($this->get_server_hostname());
+                    $this->smtp->Hello($this->ServerHostname());
 
-        // If user requests SMTP authentication
         if($this->SMTPAuth)
         {
-            if(!$smtp->Authenticate($this->Username, $this->Password))
+                    if(!$this->smtp->Authenticate($this->Username, 
+                                                  $this->Password))
             {
-                $this->error_handler("SMTP Error: Could not authenticate");
-                return false;
-            }
+                        $this->SetError($this->Lang("authenticate"));
+                        $this->smtp->Reset();
+                        $connection = false;
         }
-
-        if ($this->Sender == "")
-            $smtp_from = $this->From;
-        else
-            $smtp_from = $this->Sender;
-
-        if(!$smtp->Mail(sprintf("<%s>", $smtp_from)))
-        {
-            $e = sprintf("SMTP Error: From address [%s] failed", $smtp_from);
-            $this->error_handler($e);
-            return false;
         }
-
-        // Attempt to send attach all recipients
-        for($i = 0; $i < count($this->to); $i++)
-        {
-            if(!$smtp->Recipient(sprintf("<%s>", $this->to[$i][0])))
-                $bad_rcpt[] = $this->to[$i][0];
+                $connection = true;
         }
-        for($i = 0; $i < count($this->cc); $i++)
-        {
-            if(!$smtp->Recipient(sprintf("<%s>", $this->cc[$i][0])))
-                $bad_rcpt[] = $this->cc[$i][0];
+            $index++;
         }
-        for($i = 0; $i < count($this->bcc); $i++)
-        {
-            if(!$smtp->Recipient(sprintf("<%s>", $this->bcc[$i][0])))
-                $bad_rcpt[] = $this->bcc[$i][0];
+        if(!$connection)
+            $this->SetError($this->Lang("connect_host"));
+
+        return $connection;
         }
 
-        // Create error message
-        if(count($bad_rcpt) > 0)
+    /**
+     * Closes the active SMTP session if one exists.
+     * @return void
+     */
+    function SmtpClose() {
+        if($this->smtp != NULL)
         {
-            for($i = 0; $i < count($bad_rcpt); $i++)
+            if($this->smtp->Connected())
             {
-                if($i != 0)
-                    $e .= ", ";
-                $e .= $bad_rcpt[$i];
+                $this->smtp->Quit();
+                $this->smtp->Close();
+            }
             }
-            $e = sprintf("SMTP Error: The following recipients failed [%s]", 
$e);
-            $this->error_handler($e);
-
-            return false;
         }
 
-
-        if(!$smtp->Data(sprintf("%s%s", $header, $body)))
+    /**
+     * Sets the language for all class error messages.  Returns false 
+     * if it cannot load the language file.  The default language type
+     * is English.
+     * @param string $lang_type Type of language (e.g. Portuguese: "br")
+     * @param string $lang_path Path to the language file directory
+     * @access public
+     * @return bool
+     */
+    function SetLanguage($lang_type, $lang_path = "language/") {
+        if(file_exists($lang_path.'phpmailer.lang-'.$lang_type.'.php'))
+            include($lang_path.'phpmailer.lang-'.$lang_type.'.php');
+        else if(file_exists($lang_path.'phpmailer.lang-en.php'))
+            include($lang_path.'phpmailer.lang-en.php');
+        else
         {
-            $this->error_handler("SMTP Error: Data not accepted");
+            $this->SetError("Could not load language file");
             return false;
         }
-        $smtp->Quit();
-        $smtp->Close();
+        $this->language = $PHPMAILER_LANG;
 
         return true;
     }
 
-
     /////////////////////////////////////////////////
     // MESSAGE CREATION METHODS
     /////////////////////////////////////////////////
 
     /**
-     * Creates recipient headers.  Returns string.
+     * Creates recipient headers.  
      * @access private
      * @return string
      */
-    function addr_append($type, $addr) {
+    function AddrAppend($type, $addr) {
         $addr_str = $type . ": ";
-        $addr_str .= $this->addr_format($addr[0]);
+        $addr_str .= $this->AddrFormat($addr[0]);
         if(count($addr) > 1)
         {
             for($i = 1; $i < count($addr); $i++)
-            {
-                $addr_str .= sprintf(", %s", $this->addr_format($addr[$i]));
+                $addr_str .= ", " . $this->AddrFormat($addr[$i]);
             }
             $addr_str .= $this->LE;
-        }
-        else
-            $addr_str .= $this->LE;
 
-        return($addr_str);
-    }
-    
-    /**
-     * Creates a semicolon delimited list for use in pqm files.
-     * @access private
-     * @return string
-     */
-    function addr_list($list_array) {
-        $addr_list = "";
-        for($i = 0; $i < count($list_array); $i++)
-        {
-            if($i > 0)
-                $addr_list .= ";";
-            $addr_list .= $list_array[$i][0];
-        }
-        
-        return $addr_list;
+        return $addr_str;
     }
     
     /**
@@ -822,11 +653,14 @@
      * @access private
      * @return string
      */
-    function addr_format($addr) {
+    function AddrFormat($addr) {
         if(empty($addr[1]))
             $formatted = $addr[0];
         else
-            $formatted = sprintf('%s <%s>', $this->encode_header($addr[1], 
'phrase'), $addr[0]);
+        {
+            $formatted = $this->EncodeHeader($addr[1], 'phrase') . " <" . 
+                         $addr[0] . ">";
+        }
 
         return $formatted;
     }
@@ -834,17 +668,14 @@
     /**
      * Wraps message for use with mailers that do not
      * automatically perform wrapping and for quoted-printable.
-     * Original written by philippe.  Returns string.
+     * Original written by philippe.  
      * @access private
      * @return string
      */
-    function word_wrap($message, $length, $qp_mode = false) {
-        if ($qp_mode)
-        $soft_break = sprintf(" =%s", $this->LE);
-        else
-        $soft_break = $this->LE;
+    function WrapText($message, $length, $qp_mode = false) {
+        $soft_break = ($qp_mode) ? sprintf(" =%s", $this->LE) : $this->LE;
 
-        $message = $this->fix_eol($message);
+        $message = $this->FixEOL($message);
         if (substr($message, -1) == $this->LE)
         $message = substr($message, 0, -1);
 
@@ -899,10 +730,8 @@
               else
               {
                 $buf_o = $buf;
-                if ($e == 0)
-                    $buf .= $word;
-                else
-                    $buf .= " " . $word;
+                $buf .= ($e == 0) ? $word : (" " . $word); 
+
                 if (strlen($buf) > $length and $buf_o != "")
                 {
                     $message .= $buf_o . $soft_break;
@@ -913,7 +742,7 @@
           $message .= $buf . $this->LE;
         }
 
-        return ($message);
+        return $message;
     }
     
     /**
@@ -928,218 +757,245 @@
         switch($this->message_type)
         {
            case "alt":
-           case "alt_attachment":
-              $this->AltBody = $this->word_wrap($this->AltBody, 
$this->WordWrap);
+              // fall through
+           case "alt_attachments":
+              $this->AltBody = $this->WrapText($this->AltBody, 
$this->WordWrap);
               break;
            default:
-              $this->Body = $this->word_wrap($this->Body, $this->WordWrap);
+              $this->Body = $this->WrapText($this->Body, $this->WordWrap);
               break;
         }
     }
 
     /**
-     * Assembles message header.  Returns a string if successful
-     * or false if unsuccessful.
+     * Assembles message header.  
      * @access private
      * @return string
      */
-    function create_header() {
-        $header = array();
+    function CreateHeader() {
+        $result = "";
         
         // Set the boundaries
         $uniq_id = md5(uniqid(time()));
         $this->boundary[1] = "b1_" . $uniq_id;
         $this->boundary[2] = "b2_" . $uniq_id;
 
+        $result .= $this->HeaderLine("Date", $this->RFCDate());
+        if($this->Sender == "")
+            $result .= $this->HeaderLine("Return-Path", trim($this->From));
+        else
+            $result .= $this->HeaderLine("Return-Path", trim($this->Sender));
+        
         // To be created automatically by mail()
         if($this->Mailer != "mail")
         {
             if(count($this->to) > 0)
-            $header[] = $this->addr_append("To", $this->to);
+                $result .= $this->AddrAppend("To", $this->to);
             else if (count($this->cc) == 0)
-                $header[] = "To: undisclosed-recipients:;".$this->LE;
+                $result .= $this->HeaderLine("To", "undisclosed-recipients:;");
+            if(count($this->cc) > 0)
+                $result .= $this->AddrAppend("Cc", $this->cc);
         }
 
         $from = array();
         $from[0][0] = trim($this->From);
         $from[0][1] = $this->FromName;
-        $header[] = $this->addr_append("From", $from); 
-
-        if(count($this->cc) > 0)
-            $header[] = $this->addr_append("Cc", $this->cc);
+        $result .= $this->AddrAppend("From", $from); 
 
         // sendmail and mail() extract Bcc from the header before sending
         if((($this->Mailer == "sendmail") || ($this->Mailer == "mail")) && 
(count($this->bcc) > 0))
-            $header[] = $this->addr_append("Bcc", $this->bcc);
+            $result .= $this->AddrAppend("Bcc", $this->bcc);
 
         if(count($this->ReplyTo) > 0)
-            $header[] = $this->addr_append("Reply-to", $this->ReplyTo);
+            $result .= $this->AddrAppend("Reply-to", $this->ReplyTo);
 
         // mail() sets the subject itself
         if($this->Mailer != "mail")
-            $header[] = sprintf("Subject: %s%s", 
$this->encode_header(trim($this->Subject)), $this->LE);
+            $result .= $this->HeaderLine("Subject", 
$this->EncodeHeader(trim($this->Subject)));
 
-        $header[] = sprintf("Message-ID: <address@hidden>%s", $uniq_id, 
$this->get_server_hostname(), $this->LE);
-        $header[] = sprintf("X-Priority: %d%s", $this->Priority, $this->LE);
-        $header[] = sprintf("X-Mailer: phpmailer [version %s]%s", 
$this->Version, $this->LE);
-        if($this->Sender == "")
-        $header[] = sprintf("Return-Path: %s%s", trim($this->From), $this->LE);
-        else
-            $header[] = sprintf("Return-Path: %s%s", trim($this->Sender), 
$this->LE);
+        $result .= sprintf("Message-ID: <address@hidden>%s", $uniq_id, 
$this->ServerHostname(), $this->LE);
+        $result .= $this->HeaderLine("X-Priority", $this->Priority);
+        $result .= $this->HeaderLine("X-Mailer", "PHPMailer [version " . 
$this->Version . "]");
         
         if($this->ConfirmReadingTo != "")
-            $header[] = sprintf("Disposition-Notification-To: <%s>%s", 
-                            trim($this->ConfirmReadingTo), $this->LE);
+        {
+            $result .= $this->HeaderLine("Disposition-Notification-To", 
+                       "<" . trim($this->ConfirmReadingTo) . ">");
+        }
 
         // Add custom headers
         for($index = 0; $index < count($this->CustomHeader); $index++)
-            $header[] = sprintf("%s: %s%s", 
trim($this->CustomHeader[$index][0]), 
$this->encode_header(trim($this->CustomHeader[$index][1])), $this->LE);
-
-        if($this->UseMSMailHeaders)
-            $header[] = $this->AddMSMailHeaders();
-
-        $header[] = sprintf("MIME-Version: 1.0%s", $this->LE);
-
-        // Determine what type of message this is        
-        if(count($this->attachment) < 1 && strlen($this->AltBody) < 1)
-            $this->message_type = "plain";
-        else
         {
-            if(count($this->attachment) > 0)
-                $this->message_type = "attachments";
-            if(strlen($this->AltBody) > 0 && count($this->attachment) < 1)
-                $this->message_type = "alt";
-            if(strlen($this->AltBody) > 0 && count($this->attachment) > 0)
-                $this->message_type = "alt_attachments";
+            $result .= $this->HeaderLine(trim($this->CustomHeader[$index][0]), 
+                       
$this->EncodeHeader(trim($this->CustomHeader[$index][1])));
         }
+        $result .= $this->HeaderLine("MIME-Version", "1.0");
         
         switch($this->message_type)
         {
             case "plain":
-                $header[] = sprintf("Content-Transfer-Encoding: %s%s", 
-                                    $this->Encoding, $this->LE);
-                $header[] = sprintf("Content-Type: %s; charset=\"%s\"",
+                $result .= $this->HeaderLine("Content-Transfer-Encoding", 
$this->Encoding);
+                $result .= sprintf("Content-Type: %s; charset=\"%s\"",
                                     $this->ContentType, $this->CharSet);
                 break;
             case "attachments":
+                // fall through
             case "alt_attachments":
-                if($this->EmbeddedImageCount() > 0)
+                if($this->InlineImageExists())
                 {
-                    $header[] = sprintf("Content-Type: 
%s;%s\ttype=\"text/html\";%s\tboundary=\"%s\"%s", 
+                    $result .= sprintf("Content-Type: 
%s;%s\ttype=\"text/html\";%s\tboundary=\"%s\"%s", 
                                     "multipart/related", $this->LE, $this->LE, 
                                     $this->boundary[1], $this->LE);
                 }
                 else
                 {
-                    $header[] = sprintf("Content-Type: %s;%s",
-                                    "multipart/mixed", $this->LE);
-                    $header[] = sprintf("\tboundary=\"%s\"%s", 
$this->boundary[1], $this->LE);
+                    $result .= $this->HeaderLine("Content-Type", 
"multipart/mixed;");
+                    $result .= $this->TextLine("\tboundary=\"" . 
$this->boundary[1] . '"');
                 }
                 break;
             case "alt":
-                $header[] = sprintf("Content-Type: %s;%s",
-                                    "multipart/alternative", $this->LE);
-                $header[] = sprintf("\tboundary=\"%s\"%s", $this->boundary[1], 
$this->LE);
+                $result .= $this->HeaderLine("Content-Type", 
"multipart/alternative;");
+                $result .= $this->TextLine("\tboundary=\"" . 
$this->boundary[1] . '"');
                 break;
         }
 
-        // No additional lines when using mail() function
         if($this->Mailer != "mail")
-            $header[] = $this->LE.$this->LE;
+            $result .= $this->LE.$this->LE;
 
-        return(join("", $header));
+        return $result;
     }
 
     /**
-     * Assembles the message body.  Returns a string if successful
-     * or false if unsuccessful.
+     * Assembles the message body.  Returns an empty string on failure.
      * @access private
      * @return string
      */
-    function create_body() {
-        $body = array();
+    function CreateBody() {
+        $result = "";
 
         $this->SetWordWrap();
 
         switch($this->message_type)
         {
             case "alt":
-                // Return text of body
-                $bndry = new Boundary($this->boundary[1]);
-                $bndry->CharSet = $this->CharSet;
-                $bndry->Encoding = $this->Encoding;
-                $body[] = $bndry->GetSource();
-    
-                $body[] = $this->encode_string($this->AltBody, 
$this->Encoding);
-                $body[] = $this->LE.$this->LE;
-    
-                $bndry = new Boundary($this->boundary[1]);
-                $bndry->CharSet = $this->CharSet;
-                $bndry->ContentType = "text/html";
-                $bndry->Encoding = $this->Encoding;
-                $body[] = $bndry->GetSource();
-                
-                $body[] = $this->encode_string($this->Body, $this->Encoding);
-                $body[] = $this->LE.$this->LE;
-    
-                // End the boundary
-                $body[] = sprintf("%s--%s--%s", $this->LE, 
-                                  $this->boundary[1], $this->LE.$this->LE);
+                $result .= $this->GetBoundary($this->boundary[1], "", 
+                                              "text/plain", "");
+                $result .= $this->EncodeString($this->AltBody, 
$this->Encoding);
+                $result .= $this->LE.$this->LE;
+                $result .= $this->GetBoundary($this->boundary[1], "", 
+                                              "text/html", "");
+                
+                $result .= $this->EncodeString($this->Body, $this->Encoding);
+                $result .= $this->LE.$this->LE;
+    
+                $result .= $this->EndBoundary($this->boundary[1]);
                 break;
             case "plain":
-                $body[] = $this->encode_string($this->Body, $this->Encoding);
+                $result .= $this->EncodeString($this->Body, $this->Encoding);
                 break;
             case "attachments":
-                $bndry = new Boundary($this->boundary[1]);
-                $bndry->CharSet = $this->CharSet;
-                $bndry->ContentType = $this->ContentType;
-                $bndry->Encoding = $this->Encoding;
-                $body[] = $bndry->GetSource(false) . $this->LE;
-                $body[] = $this->encode_string($this->Body, $this->Encoding);
-                $body[] = $this->LE;
+                $result .= $this->GetBoundary($this->boundary[1], "", "", "");
+                $result .= $this->EncodeString($this->Body, $this->Encoding);
+                $result .= $this->LE;
      
-                if(!$body[] = $this->attach_all())
-                    return false;
+                $result .= $this->AttachAll();
                 break;
             case "alt_attachments":
-                $body[] = sprintf("--%s%s", $this->boundary[1], $this->LE);
-                $body[] = sprintf("Content-Type: %s;%s" .
+                $result .= sprintf("--%s%s", $this->boundary[1], $this->LE);
+                $result .= sprintf("Content-Type: %s;%s" .
                                   "\tboundary=\"%s\"%s",
                                    "multipart/alternative", $this->LE, 
                                    $this->boundary[2], $this->LE.$this->LE);
     
                 // Create text body
-                $bndry = new Boundary($this->boundary[2]);
-                $bndry->CharSet = $this->CharSet;
-                $bndry->ContentType = "text/plain";
-                $bndry->Encoding = $this->Encoding;
-                $body[] = $bndry->GetSource() . $this->LE;
+                $result .= $this->GetBoundary($this->boundary[2], "", 
+                                              "text/plain", "") . $this->LE;
     
-                $body[] = $this->encode_string($this->AltBody, 
$this->Encoding);
-                $body[] = $this->LE.$this->LE;
+                $result .= $this->EncodeString($this->AltBody, 
$this->Encoding);
+                $result .= $this->LE.$this->LE;
     
                 // Create the HTML body
-                $bndry = new Boundary($this->boundary[2]);
-                $bndry->CharSet = $this->CharSet;
-                $bndry->ContentType = "text/html";
-                $bndry->Encoding = $this->Encoding;
-                $body[] = $bndry->GetSource() . $this->LE;
+                $result .= $this->GetBoundary($this->boundary[2], "", 
+                                              "text/html", "") . $this->LE;
     
-                $body[] = $this->encode_string($this->Body, $this->Encoding);
-                $body[] = $this->LE.$this->LE;
+                $result .= $this->EncodeString($this->Body, $this->Encoding);
+                $result .= $this->LE.$this->LE;
 
-                $body[] = sprintf("%s--%s--%s", $this->LE, 
-                                  $this->boundary[2], $this->LE.$this->LE);
+                $result .= $this->EndBoundary($this->boundary[2]);
                 
-                if(!$body[] = $this->attach_all())
-                    return false;
+                $result .= $this->AttachAll();
                 break;
         }
-        $sBody = join("", $body);
+        if($this->IsError())
+            $result = "";
+
+        return $result;
+    }
+
+    /**
+     * Returns the start of a message boundary.
+     * @access private
+     */
+    function GetBoundary($boundary, $charSet, $contentType, $encoding) {
+        $result = "";
+        if($charSet == "") { $charSet = $this->CharSet; }
+        if($contentType == "") { $contentType = $this->ContentType; }
+        if($encoding == "") { $encoding = $this->Encoding; }
 
-        return $sBody;
+        $result .= $this->TextLine("--" . $boundary);
+        $result .= sprintf("Content-Type: %s; charset = \"%s\"", 
+                            $contentType, $charSet);
+        $result .= $this->LE;
+        $result .= $this->HeaderLine("Content-Transfer-Encoding", $encoding);
+        $result .= $this->LE;
+       
+        return $result;
     }
 
+    /**
+     * Returns the end of a message boundary.
+     * @access private
+     */
+    function EndBoundary($boundary) {
+        return $this->LE . "--" . $boundary . "--" . $this->LE; 
+    }
+    
+    /**
+     * Sets the message type.
+     * @access private
+     * @return void
+     */
+    function SetMessageType() {
+        if(count($this->attachment) < 1 && strlen($this->AltBody) < 1)
+            $this->message_type = "plain";
+        else
+        {
+            if(count($this->attachment) > 0)
+                $this->message_type = "attachments";
+            if(strlen($this->AltBody) > 0 && count($this->attachment) < 1)
+                $this->message_type = "alt";
+            if(strlen($this->AltBody) > 0 && count($this->attachment) > 0)
+                $this->message_type = "alt_attachments";
+        }
+    }
+
+    /**
+     * Returns a formatted header line.
+     * @access private
+     * @return string
+     */
+    function HeaderLine($name, $value) {
+        return $name . ": " . $value . $this->LE;
+    }
+
+    /**
+     * Returns a formatted mail line.
+     * @access private
+     * @return string
+     */
+    function TextLine($value) {
+        return $value . $this->LE;
+    }
 
     /////////////////////////////////////////////////
     // ATTACHMENT METHODS
@@ -1147,17 +1003,19 @@
 
     /**
      * Adds an attachment from a path on the filesystem.
-     * Checks if attachment is valid and then adds
-     * the attachment to the list.
      * Returns false if the file could not be found
      * or accessed.
-     * @access public
+     * @param string $path Path to the attachment.
+     * @param string $name Overrides the attachment name.
+     * @param string $encoding File encoding (see $Encoding).
+     * @param string $type File extension (MIME) type.
      * @return bool
      */
-    function AddAttachment($path, $name = "", $encoding = "base64", $type = 
"application/octet-stream") {
+    function AddAttachment($path, $name = "", $encoding = "base64", 
+                           $type = "application/octet-stream") {
         if(address@hidden($path))
         {
-            $this->error_handler(sprintf("Could not access [%s] file", $path));
+            $this->SetError($this->Lang("file_access") . $path);
             return false;
         }
 
@@ -1165,7 +1023,6 @@
         if($name == "")
             $name = $filename;
 
-        // Append to $attachment array
         $cur = count($this->attachment);
         $this->attachment[$cur][0] = $path;
         $this->attachment[$cur][1] = $filename;
@@ -1181,11 +1038,11 @@
 
     /**
      * Attaches all fs, string, and binary attachments to the message.
-     * Returns a string if successful or false if unsuccessful.
+     * Returns an empty string on failure.
      * @access private
      * @return string
      */
-    function attach_all() {
+    function AttachAll() {
         // Return text of body
         $mime = array();
 
@@ -1195,13 +1052,10 @@
             // Check for string attachment
             $bString = $this->attachment[$i][5];
             if ($bString)
-            {
                 $string = $this->attachment[$i][0];
-            }
             else
-            {
                 $path = $this->attachment[$i][0];
-            }
+
             $filename    = $this->attachment[$i][1];
             $name        = $this->attachment[$i][2];
             $encoding    = $this->attachment[$i][3];
@@ -1222,93 +1076,92 @@
             // Encode as string attachment
             if($bString)
             {
-                if(!$mime[] = $this->encode_string($string, $encoding))        
        
-                    return false;
+                $mime[] = $this->EncodeString($string, $encoding);
+                if($this->IsError()) { return ""; }
                 $mime[] = $this->LE.$this->LE;
             }
             else
             {
-                if(!$mime[] = $this->encode_file($path, $encoding))            
    
-                    return false;
+                $mime[] = $this->EncodeFile($path, $encoding);                
+                if($this->IsError()) { return ""; }
                 $mime[] = $this->LE.$this->LE;
             }
         }
 
         $mime[] = sprintf("--%s--%s", $this->boundary[1], $this->LE);
 
-        return(join("", $mime));
+        return join("", $mime);
     }
     
     /**
-     * Encodes attachment in requested format.  Returns a
-     * string if successful or false if unsuccessful.
+     * Encodes attachment in requested format.  Returns an
+     * empty string on failure.
      * @access private
      * @return string
      */
-    function encode_file ($path, $encoding = "base64") {
+    function EncodeFile ($path, $encoding = "base64") {
         if(address@hidden = fopen($path, "rb"))
         {
-            $this->error_handler(sprintf("File Error: Could not open file %s", 
$path));
-            return false;
+            $this->SetError($this->Lang("file_open") . $path);
+            return "";
         }
+        $magic_quotes = get_magic_quotes_runtime();
+        set_magic_quotes_runtime(0);
         $file_buffer = fread($fd, filesize($path));
-        $file_buffer = $this->encode_string($file_buffer, $encoding);
+        $file_buffer = $this->EncodeString($file_buffer, $encoding);
         fclose($fd);
+        set_magic_quotes_runtime($magic_quotes);
 
         return $file_buffer;
     }
 
     /**
-     * Encodes string to requested format. Returns a
-     * string if successful or false if unsuccessful.
+     * Encodes string to requested format. Returns an
+     * empty string on failure.
      * @access private
      * @return string
      */
-    function encode_string ($str, $encoding = "base64") {
+    function EncodeString ($str, $encoding = "base64") {
+        $encoded = "";
         switch(strtolower($encoding)) {
           case "base64":
               // chunk_split is found in PHP >= 3.0.6
-              $encoded = chunk_split(base64_encode($str));
+              $encoded = chunk_split(base64_encode($str), 76, $this->LE);
               break;
-
           case "7bit":
           case "8bit":
-              $encoded = $this->fix_eol($str);
-              if (substr($encoded, -2) != $this->LE)
+              $encoded = $this->FixEOL($str);
+              if (substr($encoded, -(strlen($this->LE))) != $this->LE)
                 $encoded .= $this->LE;
               break;
-
           case "binary":
               $encoded = $str;
               break;
-
           case "quoted-printable":
-              $encoded = $this->encode_qp($str);
+              $encoded = $this->EncodeQP($str);
               break;
-
           default:
-              $this->error_handler(sprintf("Unknown encoding: %s", $encoding));
-              return false;
+              $this->SetError($this->Lang("encoding") . $encoding);
+              break;
         }
-        return($encoded);
+        return $encoded;
     }
 
     /**
-     * Encode a header string to best of Q, B, quoted or none.  Returns a 
string.
+     * Encode a header string to best of Q, B, quoted or none.  
      * @access private
      * @return string
      */
-    function encode_header ($str, $position = 'text') {
+    function EncodeHeader ($str, $position = 'text') {
       $x = 0;
       
       switch (strtolower($position)) {
         case 'phrase':
-          if (preg_match_all('/[\200-\377]/', $str, $matches) == 0) {
+          if (!preg_match('/[\200-\377]/', $str)) {
             // Can't use addslashes as we don't know what value has 
magic_quotes_sybase.
-            $encoded = addcslashes($str, '\000-\037\177');
-            $encoded = preg_replace('/([\"])/', '\\"', $encoded);
+            $encoded = addcslashes($str, "\0..\37\177\\\"");
 
-            if (($str == $encoded) && 
(preg_match_all('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str, $matches) == 0))
+            if (($str == $encoded) && 
!preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str))
               return ($encoded);
             else
               return ("\"$encoded\"");
@@ -1336,25 +1189,25 @@
         $encoded = trim(chunk_split($encoded, $maxlen, "\n"));
       } else {
         $encoding = 'Q';
-        $encoded = $this->encode_q($str, $position);
-        $encoded = $this->word_wrap($encoded, $maxlen, true);
+        $encoded = $this->EncodeQ($str, $position);
+        $encoded = $this->WrapText($encoded, $maxlen, true);
         $encoded = str_replace("=".$this->LE, "\n", trim($encoded));
       }
 
       $encoded = preg_replace('/^(.*)$/m', " 
=?".$this->CharSet."?$encoding?\\1?=", $encoded);
       $encoded = trim(str_replace("\n", $this->LE, $encoded));
       
-      return($encoded);
+      return $encoded;
     }
     
     /**
-     * Encode string to quoted-printable.  Returns a string.
+     * Encode string to quoted-printable.  
      * @access private
      * @return string
      */
-    function encode_qp ($str) {
-        $encoded = $this->fix_eol($str);
-        if (substr($encoded, -2) != $this->LE)
+    function EncodeQP ($str) {
+        $encoded = $this->FixEOL($str);
+        if (substr($encoded, -(strlen($this->LE))) != $this->LE)
             $encoded .= $this->LE;
 
         // Replace every high ascii, control and = characters
@@ -1365,28 +1218,27 @@
                   "'='.sprintf('%02X', ord('\\1')).'".$this->LE."'", $encoded);
 
         // Maximum line length of 76 characters before CRLF (74 + space + '=')
-        $encoded = $this->word_wrap($encoded, 74, true);
+        $encoded = $this->WrapText($encoded, 74, true);
 
         return $encoded;
     }
 
     /**
-     * Encode string to q encoding.  Returns a string.
+     * Encode string to q encoding.  
      * @access private
      * @return string
      */
-    function encode_q ($str, $position = 'text') {
+    function EncodeQ ($str, $position = "text") {
         // There should not be any EOL in the string
         $encoded = preg_replace("[\r\n]", "", $str);
 
         switch (strtolower($position)) {
-          case 'phrase':
+          case "phrase":
             $encoded = preg_replace("/([^A-Za-z0-9!*+\/ -])/e", 
"'='.sprintf('%02X', ord('\\1'))", $encoded);
             break;
-          case 'comment':
+          case "comment":
             $encoded = preg_replace("/([\(\)\"])/e", "'='.sprintf('%02X', 
ord('\\1'))", $encoded);
-            // Fall-through
-          case 'text':
+          case "text":
           default:
             // Replace every high ascii, control =, ? and _ characters
             $encoded = 
preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e',
@@ -1404,10 +1256,14 @@
      * Adds a string or binary attachment (non-filesystem) to the list.
      * This method can be used to attach ascii or binary data,
      * such as a BLOB record from a database.
-     * @access public
+     * @param string $string String attachment data.
+     * @param string $filename Name of the attachment.
+     * @param string $encoding File encoding (see $Encoding).
+     * @param string $type File extension (MIME) type.
      * @return void
      */
-    function AddStringAttachment($string, $filename, $encoding = "base64", 
$type = "application/octet-stream") {
+    function AddStringAttachment($string, $filename, $encoding = "base64", 
+                                 $type = "application/octet-stream") {
         // Append to $attachment array
         $cur = count($this->attachment);
         $this->attachment[$cur][0] = $string;
@@ -1422,17 +1278,23 @@
     
     /**
      * Adds an embedded attachment.  This can include images, sounds, and 
-     * just about any other document.  
-     * @param cid this is the Content Id of the attachment.  Use this to 
identify
+     * just about any other document.  Make sure to set the $type to an 
+     * image type.  For JPEG images use "image/jpeg" and for GIF images 
+     * use "image/gif".
+     * @param string $path Path to the attachment.
+     * @param string $cid Content ID of the attachment.  Use this to identify 
      *        the Id for accessing the image in an HTML form.
-     * @access public
+     * @param string $name Overrides the attachment name.
+     * @param string $encoding File encoding (see $Encoding).
+     * @param string $type File extension (MIME) type.  
      * @return bool
      */
-    function AddEmbeddedImage($path, $cid, $name = "", $encoding = "base64", 
$type = "application/octet-stream") {
+    function AddEmbeddedImage($path, $cid, $name = "", $encoding = "base64", 
+                              $type = "application/octet-stream") {
     
         if(address@hidden($path))
         {
-            $this->error_handler(sprintf("Could not access [%s] file", $path));
+            $this->SetError($this->Lang("file_access") . $path);
             return false;
         }
 
@@ -1455,19 +1317,22 @@
     }
     
     /**
-     * Returns the number of embedded images in an email.
+     * Returns true if an inline attachment is present.
      * @access private
-     * @return int
+     * @return bool
      */
-    function EmbeddedImageCount() {
-        $ret = 0;
+    function InlineImageExists() {
+        $result = false;
         for($i = 0; $i < count($this->attachment); $i++)
         {
             if($this->attachment[$i][6] == "inline")
-                $ret++;
+            {
+                $result = true;
+                break;
+            }
         }
         
-        return $ret;
+        return $result;
     }
 
     /////////////////////////////////////////////////
@@ -1476,7 +1341,6 @@
 
     /**
      * Clears all recipients assigned in the TO array.  Returns void.
-     * @access public
      * @return void
      */
     function ClearAddresses() {
@@ -1485,7 +1349,6 @@
 
     /**
      * Clears all recipients assigned in the CC array.  Returns void.
-     * @access public
      * @return void
      */
     function ClearCCs() {
@@ -1494,7 +1357,6 @@
 
     /**
      * Clears all recipients assigned in the BCC array.  Returns void.
-     * @access public
      * @return void
      */
     function ClearBCCs() {
@@ -1503,7 +1365,6 @@
 
     /**
      * Clears all recipients assigned in the ReplyTo array.  Returns void.
-     * @access public
      * @return void
      */
     function ClearReplyTos() {
@@ -1513,7 +1374,6 @@
     /**
      * Clears all recipients assigned in the TO, CC and BCC
      * array.  Returns void.
-     * @access public
      * @return void
      */
     function ClearAllRecipients() {
@@ -1525,7 +1385,6 @@
     /**
      * Clears all previously set filesystem, string, and binary
      * attachments.  Returns void.
-     * @access public
      * @return void
      */
     function ClearAttachments() {
@@ -1534,7 +1393,6 @@
 
     /**
      * Clears all custom headers.  Returns void.
-     * @access public
      * @return void
      */
     function ClearCustomHeaders() {
@@ -1552,60 +1410,24 @@
      * @access private
      * @return void
      */
-    function error_handler($msg) {
+    function SetError($msg) {
+        $this->error_count++;
         $this->ErrorInfo = $msg;
     }
 
     /**
-     * Returns the proper RFC 822 formatted date. Returns string.
+     * Returns the proper RFC 822 formatted date. 
      * @access private
      * @return string
      */
-    function rfc_date() {
+    function RFCDate() {
         $tz = date("Z");
         $tzs = ($tz < 0) ? "-" : "+";
         $tz = abs($tz);
         $tz = ($tz/3600)*100 + ($tz%3600)/60;
-        $date = sprintf("%s %s%04d", date("D, j M Y H:i:s"), $tzs, $tz);
-        return $date;
-    }
+        $result = sprintf("%s %s%04d", date("D, j M Y H:i:s"), $tzs, $tz);
 
-    /**
-     * Returns received header for message tracing. Returns string.
-     * @access private
-     * @return string
-     */
-    function received() {
-        // Check for vars because they might not exist.  Possibly
-        // write a small retrieval function (that mailer can use too!)
-
-        if ($this->get_server_var('SERVER_NAME') != '')
-       {
-            $protocol = ($this->get_server_var('HTTPS') == 'on') ? 'HTTPS' : 
'HTTP';
-           $remote = $this->get_server_var('REMOTE_HOST');
-           if ($remote == '')
-               $remote = 'phpmailer';
-           $remote .= ' (['.$this->get_server_var('REMOTE_ADDR').'])';
-       }
-        else
-       {
-            $protocol = 'local';
-           $remote = $this->get_server_var('USER');
-           if ($remote == '')
-               $remote = 'phpmailer';
-       }
-
-        $str = sprintf("Received: from %s %s\tby %s " .
-               "with %s (phpmailer);%s\t%s%s",
-              $remote,
-              $this->LE,
-               $this->get_server_hostname(),
-              $protocol,
-               $this->LE,
-               $this->rfc_date(),
-               $this->LE);
-
-        return $str;
+        return $result;
     }
     
     /**
@@ -1615,7 +1437,7 @@
      * @access private
      * @return mixed
      */
-    function get_server_var($varName) {
+    function ServerVar($varName) {
         global $HTTP_SERVER_VARS;
         global $HTTP_ENV_VARS;
 
@@ -1637,146 +1459,58 @@
      * @access private
      * @return string
      */
-    function get_server_hostname() {
-        if ($this->Hostname != '')
-           return $this->Hostname;
-       elseif ($this->get_server_var('SERVER_NAME') != '')
-           return $this->get_server_var('SERVER_NAME');
+    function ServerHostname() {
+        if ($this->Hostname != "")
+            $result = $this->Hostname;
+        elseif ($this->ServerVar('SERVER_NAME') != "")
+            $result = $this->ServerVar('SERVER_NAME');
        else
-           return 'localhost.localdomain';
+            $result = "localhost.localdomain";
+
+        return $result;
     }
 
     /**
-     * Changes every end of line from CR or LF to CRLF.  Returns string.
+     * Returns a message in the appropriate language.
      * @access private
      * @return string
      */
-    function fix_eol($str) {
-        $str = str_replace("\r\n", "\n", $str);
-        $str = str_replace("\r", "\n", $str);
-        $str = str_replace("\n", $this->LE, $str);
-        return $str;
-    }
+    function Lang($key) {
+        if(count($this->language) < 1)
+            $this->SetLanguage("en"); // set the default language
 
-    /**
-     * Adds a custom header.  Returns void.
-     * @access public
-     * @return void
-     */
-    function AddCustomHeader($custom_header) {
-        // Append to $custom_header array
-        $this->CustomHeader[] = explode(":", $custom_header, 2);
+        if(isset($this->language[$key]))
+            return $this->language[$key];
+        else
+            return "Language string failed to load: " . $key;
     }
 
     /**
-     * Adds all the Microsoft message headers.  Returns string.
-     * @access private
-     * @return string
+     * Returns true if an error occurred.
+     * @return bool
      */
-    function AddMSMailHeaders() {
-        $MSHeader = "";
-        if($this->Priority == 1)
-            $MSPriority = "High";
-        elseif($this->Priority == 5)
-            $MSPriority = "Low";
-        else
-            $MSPriority = "Medium";
-
-        $MSHeader .= sprintf("X-MSMail-Priority: %s%s", $MSPriority, 
$this->LE);
-        $MSHeader .= sprintf("Importance: %s%s", $MSPriority, $this->LE);
-
-        return($MSHeader);
+    function IsError() {
+        return ($this->error_count > 0);
     }
 
-}
-
-
-/**
- * Boundary - MIME message boundary class
- * @author Brent R. Matzelle
- */
-class Boundary
-{
     /**
-     * Sets the boundary ID.
+     * Changes every end of line from CR or LF to CRLF.  
      * @access private
-     * @var string
-     */
-    var $ID = 0;
-
-    /**
-     * Sets the boundary Content Type.
-     * @access public
-     * @var string
-     */
-    var $ContentType = "text/plain";
-
-    /**
-     * Sets the Encoding.
-     * @access public
-     * @var string
-     */
-    var $Encoding = "";
-
-    /**
-     * Sets an attachment disposition.
-     * @access public
-     * @var string
-     */
-    var $Disposition = "";
-
-    /**
-     * Sets an attachment file name.
-     * @access public
-     * @var string
-     */
-    var $FileName = "";
-    
-    /**
-     * Sets the Char set.
-     * @access public
-     * @var string
-     */
-    var $CharSet = "";
-    
-    /**
-     *  Sets the line endings of the message.  Default is "\n";
-     *  @access public
-     *  @var string
-     */
-    var $LE           = "\n";
-    
-    /**
-     * Main constructor.
+     * @return string
      */
-    function Boundary($boundary_id) {
-        $this->ID = $boundary_id;
+    function FixEOL($str) {
+        $str = str_replace("\r\n", "\n", $str);
+        $str = str_replace("\r", "\n", $str);
+        $str = str_replace("\n", $this->LE, $str);
+        return $str;
     }
     
     /**
-     * Returns the source of the boundary.
-     * @access public
-     * @return string
+     * Adds a custom header. 
+     * @return void
      */
-    function GetSource($bLineEnding = true) {
-        $mime = array();
-        $mime[] = sprintf("--%s%s", $this->ID, $this->LE);
-        $mime[] = sprintf("Content-Type: %s; charset = \"%s\"%s", 
-                          $this->ContentType, $this->CharSet, $this->LE);
-        $mime[] = sprintf("Content-Transfer-Encoding: %s%s", $this->Encoding, 
-                          $this->LE);
-        
-        if(strlen($this->Disposition) > 0)
-        {
-            $mime[] = sprintf("Content-Disposition: %s;");
-            if(strlen($this->FileName) > 0)
-                $mime[] = sprinf("filename=\"%s\"", $this->FileName);
-        }
-        
-        if($bLineEnding)
-            $mime[] = $this->LE;
-
-        return join("", $mime);
+    function AddCustomHeader($custom_header) {
+        $this->CustomHeader[] = explode(":", $custom_header, 2);
     }
 }
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]