home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / groupoffice-com-2.01 / classes / phpmailer / class.phpmailer.php < prev    next >
PHP Script  |  2004-03-08  |  49KB  |  1,588 lines

  1. <?php
  2. ////////////////////////////////////////////////////
  3. // PHPMailer - PHP email class
  4. //
  5. // Class for sending email using either
  6. // sendmail, PHP mail(), or SMTP.  Methods are
  7. // based upon the standard AspEmail(tm) classes.
  8. //
  9. // Copyright (C) 2001 - 2003  Brent R. Matzelle
  10. //
  11. // License: LGPL, see LICENSE
  12. //
  13. // Modified for Group-Office by Merijn Schering 03-03-2004
  14. ////////////////////////////////////////////////////
  15.  
  16. /**
  17.  * PHPMailer - PHP email transport class
  18.  * @package PHPMailer
  19.  * @author Brent R. Matzelle
  20.  * @copyright 2001 - 2003 Brent R. Matzelle
  21.  */
  22. class PHPMailer
  23. {
  24.     /////////////////////////////////////////////////
  25.     // PUBLIC VARIABLES
  26.     /////////////////////////////////////////////////
  27.  
  28.     /**
  29.      * Email priority (1 = High, 3 = Normal, 5 = low).
  30.      * @var int
  31.      */
  32.     var $Priority          = 3;
  33.  
  34.     /**
  35.      * Sets the CharSet of the message.
  36.      * @var string
  37.      */
  38.     var $CharSet           = "iso-8859-1";
  39.  
  40.     /**
  41.      * Sets the Content-type of the message.
  42.      * @var string
  43.      */
  44.     var $ContentType        = "text/plain";
  45.  
  46.     /**
  47.      * Sets the Encoding of the message. Options for this are "8bit",
  48.      * "7bit", "binary", "base64", and "quoted-printable".
  49.      * @var string
  50.      */
  51.     var $Encoding          = "8bit";
  52.  
  53.     /**
  54.      * Holds the most recent mailer error message.
  55.      * @var string
  56.      */
  57.     var $ErrorInfo         = "";
  58.  
  59.     /**
  60.      * Sets the From email address for the message.
  61.      * @var string
  62.      */
  63.     var $From               = "root@localhost";
  64.  
  65.     /**
  66.      * Sets the From name of the message.
  67.      * @var string
  68.      */
  69.     var $FromName           = "Root User";
  70.  
  71.     /**
  72.      * Sets the Sender email (Return-Path) of the message.  If not empty,
  73.      * will be sent via -f to sendmail or as 'MAIL FROM' in smtp mode.
  74.      * @var string
  75.      */
  76.     var $Sender            = "";
  77.  
  78.     /**
  79.      * Sets the Subject of the message.
  80.      * @var string
  81.      */
  82.     var $Subject           = "";
  83.  
  84.     /**
  85.      * Sets the Body of the message.  This can be either an HTML or text body.
  86.      * If HTML then run IsHTML(true).
  87.      * @var string
  88.      */
  89.     var $Body               = "";
  90.  
  91.     /**
  92.      * Sets the text-only body of the message.  This automatically sets the
  93.      * email to multipart/alternative.  This body can be read by mail
  94.      * clients that do not have HTML email capability such as mutt. Clients
  95.      * that can read HTML will view the normal Body.
  96.      * @var string
  97.      */
  98.     var $AltBody           = "";
  99.  
  100.     /**
  101.      * Sets word wrapping on the body of the message to a given number of
  102.      * characters.
  103.      * @var int
  104.      */
  105.     var $WordWrap          = 0;
  106.  
  107.     /**
  108.      * Method to send mail: ("mail", "sendmail", or "smtp").
  109.      * @var string
  110.      */
  111.     var $Mailer            = "mail";
  112.  
  113.     /**
  114.      * Sets the path of the sendmail program.
  115.      * @var string
  116.      */
  117.     var $Sendmail          = "/usr/sbin/sendmail";
  118.  
  119.     /**
  120.      * Path to PHPMailer plugins.  This is now only useful if the SMTP class
  121.      * is in a different directory than the PHP include path.
  122.      * @var string
  123.      */
  124.     var $PluginDir         = "";
  125.  
  126.     /**
  127.      *  Holds PHPMailer version.
  128.      *  @var string
  129.      */
  130.     var $Version           = "1.71";
  131.  
  132.     /**
  133.      * Sets the email address that a reading confirmation will be sent.
  134.      * @var string
  135.      */
  136.     var $ConfirmReadingTo  = "";
  137.  
  138.     /**
  139.      *  Sets the hostname to use in Message-Id and Received headers
  140.      *  and as default HELO string. If empty, the value returned
  141.      *  by SERVER_NAME is used or 'localhost.localdomain'.
  142.      *  @var string
  143.      */
  144.     var $Hostname          = "";
  145.  
  146.  
  147.     /////////////////////////////////////////////////
  148.     // SMTP VARIABLES
  149.     /////////////////////////////////////////////////
  150.  
  151.     /**
  152.      *  Sets the SMTP hosts.  All hosts must be separated by a
  153.      *  semicolon.  You can also specify a different port
  154.      *  for each host by using this format: [hostname:port]
  155.      *  (e.g. "smtp1.example.com:25;smtp2.example.com").
  156.      *  Hosts will be tried in order.
  157.      *  @var string
  158.      */
  159.     var $Host        = "localhost";
  160.  
  161.     /**
  162.      *  Sets the default SMTP server port.
  163.      *  @var int
  164.      */
  165.     var $Port        = 25;
  166.  
  167.     /**
  168.      *  Sets the SMTP HELO of the message (Default is $Hostname).
  169.      *  @var string
  170.      */
  171.     var $Helo        = "";
  172.  
  173.     /**
  174.      *  Sets SMTP authentication. Utilizes the Username and Password variables.
  175.      *  @var bool
  176.      */
  177.     var $SMTPAuth     = false;
  178.  
  179.     /**
  180.      *  Sets SMTP username.
  181.      *  @var string
  182.      */
  183.     var $Username     = "";
  184.  
  185.     /**
  186.      *  Sets SMTP password.
  187.      *  @var string
  188.      */
  189.     var $Password     = "";
  190.  
  191.     /**
  192.      *  Sets the SMTP server timeout in seconds. This function will not
  193.      *  work with the win32 version.
  194.      *  @var int
  195.      */
  196.     var $Timeout      = 10;
  197.  
  198.     /**
  199.      *  Sets SMTP class debugging on or off.
  200.      *  @var bool
  201.      */
  202.     var $SMTPDebug    = false;
  203.  
  204.     /**
  205.      * Prevents the SMTP connection from being closed after each mail
  206.      * sending.  If this is set to true then to close the connection
  207.      * requires an explicit call to SmtpClose().
  208.      * @var bool
  209.      */
  210.     var $SMTPKeepAlive = false;
  211.  
  212.     /**#@+
  213.      * @access private
  214.      */
  215.     var $smtp            = NULL;
  216.     var $to              = array();
  217.     var $cc              = array();
  218.     var $bcc             = array();
  219.     var $ReplyTo         = array();
  220.     var $attachment      = array();
  221.     var $CustomHeader    = array();
  222.     var $message_type    = "";
  223.     var $boundary        = array();
  224.     var $language        = array();
  225.     var $error_count     = 0;
  226.     var $LE              = "\n";
  227.     /**#@-*/
  228.  
  229.  
  230.     /////////////////////////////////////////////////
  231.     // VARIABLE METHODS
  232.     /////////////////////////////////////////////////
  233.  
  234.     /**
  235.      * Sets message type to HTML.
  236.      * @param bool $bool
  237.      * @return void
  238.      */
  239.     function IsHTML($bool) {
  240.         if($bool == true)
  241.             $this->ContentType = "text/html";
  242.         else
  243.             $this->ContentType = "text/plain";
  244.     }
  245.  
  246.     /**
  247.      * Sets Mailer to send message using SMTP.
  248.      * @return void
  249.      */
  250.     function IsSMTP() {
  251.         $this->Mailer = "smtp";
  252.     }
  253.  
  254.     /**
  255.      * Sets Mailer to send message using PHP mail() function.
  256.      * @return void
  257.      */
  258.     function IsMail() {
  259.         $this->Mailer = "mail";
  260.     }
  261.  
  262.     /**
  263.      * Sets Mailer to send message using the $Sendmail program.
  264.      * @return void
  265.      */
  266.     function IsSendmail() {
  267.         $this->Mailer = "sendmail";
  268.     }
  269.  
  270.     /**
  271.      * Sets Mailer to send message using the qmail MTA.
  272.      * @return void
  273.      */
  274.     function IsQmail() {
  275.         $this->Sendmail = "/var/qmail/bin/sendmail";
  276.         $this->Mailer = "sendmail";
  277.     }
  278.  
  279.  
  280.     /////////////////////////////////////////////////
  281.     // RECIPIENT METHODS
  282.     /////////////////////////////////////////////////
  283.  
  284.     /**
  285.      * Adds a "To" address.
  286.      * @param string $address
  287.      * @param string $name
  288.      * @return void
  289.      */
  290.     function AddAddress($address, $name = "") {
  291.         $cur = count($this->to);
  292.         $this->to[$cur][0] = trim($address);
  293.         $this->to[$cur][1] = $name;
  294.     }
  295.  
  296.     /**
  297.      * Adds a "Cc" address. Note: this function works
  298.      * with the SMTP mailer on win32, not with the "mail"
  299.      * mailer.
  300.      * @param string $address
  301.      * @param string $name
  302.      * @return void
  303.     */
  304.     function AddCC($address, $name = "") {
  305.         $cur = count($this->cc);
  306.         $this->cc[$cur][0] = trim($address);
  307.         $this->cc[$cur][1] = $name;
  308.     }
  309.  
  310.     /**
  311.      * Adds a "Bcc" address. Note: this function works
  312.      * with the SMTP mailer on win32, not with the "mail"
  313.      * mailer.
  314.      * @param string $address
  315.      * @param string $name
  316.      * @return void
  317.      */
  318.     function AddBCC($address, $name = "") {
  319.         $cur = count($this->bcc);
  320.         $this->bcc[$cur][0] = trim($address);
  321.         $this->bcc[$cur][1] = $name;
  322.     }
  323.  
  324.     /**
  325.      * Adds a "Reply-to" address.
  326.      * @param string $address
  327.      * @param string $name
  328.      * @return void
  329.      */
  330.     function AddReplyTo($address, $name = "") {
  331.         $cur = count($this->ReplyTo);
  332.         $this->ReplyTo[$cur][0] = trim($address);
  333.         $this->ReplyTo[$cur][1] = $name;
  334.     }
  335.  
  336.  
  337.     /////////////////////////////////////////////////
  338.     // MAIL SENDING METHODS
  339.     /////////////////////////////////////////////////
  340.  
  341.     /**
  342.      * Creates message and assigns Mailer. If the message is
  343.      * not sent successfully then it returns false.  Use the ErrorInfo
  344.      * variable to view description of the error.
  345.      * @return bool
  346.      */
  347.     function Send() {
  348.         $header = "";
  349.         $body = "";
  350.  
  351.         if((count($this->to) + count($this->cc) + count($this->bcc)) < 1)
  352.         {
  353.             $this->SetError($this->Lang("provide_address"));
  354.             return false;
  355.         }
  356.  
  357.         // Set whether the message is multipart/alternative
  358.         if(!empty($this->AltBody))
  359.             $this->ContentType = "multipart/alternative";
  360.  
  361.         $this->SetMessageType();
  362.         $header .= $this->CreateHeader();
  363.         $body = $this->CreateBody();
  364.  
  365.         if($body == "") { return false; }
  366.  
  367.         // Choose the mailer
  368.         if($this->Mailer == "sendmail")
  369.         {
  370.           if(!$this->SendmailSend($header, $body))
  371.               return false;
  372.         }
  373.         elseif($this->Mailer == "mail")
  374.         {
  375.           if(!$this->MailSend($header, $body))
  376.               return false;
  377.         }
  378.         elseif($this->Mailer == "smtp")
  379.         {
  380.           if(!$this->SmtpSend($header, $body))
  381.               return false;
  382.         }
  383.         else
  384.         {
  385.             $this->SetError($this->Mailer . $this->Lang("mailer_not_supported"));
  386.             return false;
  387.         }
  388.         return $header.$body;
  389.     }
  390.  
  391.     /**
  392.      * Creates message and returns mime.
  393.      * @return bool
  394.      */
  395.     function GetMime()
  396.     {
  397.         $header = "";
  398.         $body = "";
  399.  
  400.         // Set whether the message is multipart/alternative
  401.         if(!empty($this->AltBody))
  402.             $this->ContentType = "multipart/alternative";
  403.  
  404.         $this->SetMessageType();
  405.         $header .= $this->CreateHeader();
  406.         $body = $this->CreateBody();
  407.  
  408.         if($body == "") { return false; }
  409.  
  410.         return $header.$body;
  411.     }
  412.  
  413.     /**
  414.      * Sends mail using the $Sendmail program.
  415.      * @access private
  416.      * @return bool
  417.      */
  418.     function SendmailSend($header, $body) {
  419.         if ($this->Sender != "")
  420.             $sendmail = sprintf("%s -oi -f %s -t", $this->Sendmail, $this->Sender);
  421.         else
  422.             $sendmail = sprintf("%s -oi -t", $this->Sendmail);
  423.  
  424.         if(!@$mail = popen($sendmail, "w"))
  425.         {
  426.             $this->SetError($this->Lang("execute") . $this->Sendmail);
  427.             return false;
  428.         }
  429.  
  430.         fputs($mail, $header);
  431.         fputs($mail, $body);
  432.  
  433.         $result = pclose($mail) >> 8 & 0xFF;
  434.         if($result != 0)
  435.         {
  436.             $this->SetError($this->Lang("execute") . $this->Sendmail);
  437.             return false;
  438.         }
  439.  
  440.         return true;
  441.     }
  442.  
  443.     /**
  444.      * Sends mail using the PHP mail() function.
  445.      * @access private
  446.      * @return bool
  447.      */
  448.     function MailSend($header, $body) {
  449.         $to = "";
  450.         for($i = 0; $i < count($this->to); $i++)
  451.         {
  452.             if($i != 0) { $to .= ", "; }
  453.             $to .= $this->to[$i][0];
  454.         }
  455.  
  456.         if ($this->Sender != "" && strlen(ini_get("safe_mode"))< 1)
  457.         {
  458.             $old_from = ini_get("sendmail_from");
  459.             ini_set("sendmail_from", $this->Sender);
  460.             $params = sprintf("-oi -f %s", $this->Sender);
  461.             $rt = @mail($to, $this->EncodeHeader($this->Subject), $body,
  462.                         $header, $params);
  463.         }
  464.         else
  465.             $rt = @mail($to, $this->EncodeHeader($this->Subject), $body, $header);
  466.  
  467.         if (isset($old_from))
  468.             ini_set("sendmail_from", $old_from);
  469.  
  470.         if(!$rt)
  471.         {
  472.             $this->SetError($this->Lang("instantiate"));
  473.             return false;
  474.         }
  475.  
  476.         return true;
  477.     }
  478.  
  479.     /**
  480.      * Sends mail via SMTP using PhpSMTP (Author:
  481.      * Chris Ryan).  Returns bool.  Returns false if there is a
  482.      * bad MAIL FROM, RCPT, or DATA input.
  483.      * @access private
  484.      * @return bool
  485.      */
  486.     function SmtpSend($header, $body) {
  487.         include_once($this->PluginDir . "class.smtp.php");
  488.         $error = "";
  489.         $bad_rcpt = array();
  490.  
  491.         if(!$this->SmtpConnect())
  492.             return false;
  493.  
  494.         $smtp_from = ($this->Sender == "") ? $this->From : $this->Sender;
  495.         if(!$this->smtp->Mail($smtp_from))
  496.         {
  497.             $error = $this->Lang("from_failed") . $smtp_from;
  498.             $this->SetError($error);
  499.             $this->smtp->Reset();
  500.             return false;
  501.         }
  502.  
  503.         // Attempt to send attach all recipients
  504.         for($i = 0; $i < count($this->to); $i++)
  505.         {
  506.             if(!$this->smtp->Recipient($this->to[$i][0]))
  507.                 $bad_rcpt[] = $this->to[$i][0];
  508.         }
  509.         for($i = 0; $i < count($this->cc); $i++)
  510.         {
  511.             if(!$this->smtp->Recipient($this->cc[$i][0]))
  512.                 $bad_rcpt[] = $this->cc[$i][0];
  513.         }
  514.         for($i = 0; $i < count($this->bcc); $i++)
  515.         {
  516.             if(!$this->smtp->Recipient($this->bcc[$i][0]))
  517.                 $bad_rcpt[] = $this->bcc[$i][0];
  518.         }
  519.  
  520.         if(count($bad_rcpt) > 0) // Create error message
  521.         {
  522.             for($i = 0; $i < count($bad_rcpt); $i++)
  523.             {
  524.                 if($i != 0) { $error .= ", "; }
  525.                 $error .= $bad_rcpt[$i];
  526.             }
  527.             $error = $this->Lang("recipients_failed") . $error;
  528.             $this->SetError($error);
  529.             $this->smtp->Reset();
  530.             return false;
  531.         }
  532.  
  533.         if(!$this->smtp->Data($header . $body))
  534.         {
  535.             $this->SetError($this->Lang("data_not_accepted"));
  536.             $this->smtp->Reset();
  537.             return false;
  538.         }
  539.         if($this->SMTPKeepAlive == true)
  540.             $this->smtp->Reset();
  541.         else
  542.             $this->SmtpClose();
  543.  
  544.         return true;
  545.     }
  546.  
  547.     /**
  548.      * Initiates a connection to an SMTP server.  Returns false if the
  549.      * operation failed.
  550.      * @access private
  551.      * @return bool
  552.      */
  553.     function SmtpConnect() {
  554.         if($this->smtp == NULL) { $this->smtp = new SMTP(); }
  555.  
  556.         $this->smtp->do_debug = $this->SMTPDebug;
  557.         $hosts = explode(";", $this->Host);
  558.         $index = 0;
  559.         $connection = ($this->smtp->Connected());
  560.  
  561.         // Retry while there is no connection
  562.         while($index < count($hosts) && $connection == false)
  563.         {
  564.             if(strstr($hosts[$index], ":"))
  565.                 list($host, $port) = explode(":", $hosts[$index]);
  566.             else
  567.             {
  568.                 $host = $hosts[$index];
  569.                 $port = $this->Port;
  570.             }
  571.  
  572.             if($this->smtp->Connect($host, $port, $this->Timeout))
  573.             {
  574.                 if ($this->Helo != '')
  575.                     $this->smtp->Hello($this->Helo);
  576.                 else
  577.                     $this->smtp->Hello($this->ServerHostname());
  578.  
  579.                 if($this->SMTPAuth)
  580.                 {
  581.                     if(!$this->smtp->Authenticate($this->Username,
  582.                                                   $this->Password))
  583.                     {
  584.                         $this->SetError($this->Lang("authenticate"));
  585.                         $this->smtp->Reset();
  586.                         $connection = false;
  587.                     }
  588.                 }
  589.                 $connection = true;
  590.             }
  591.             $index++;
  592.         }
  593.         if(!$connection)
  594.             $this->SetError($this->Lang("connect_host"));
  595.  
  596.         return $connection;
  597.     }
  598.  
  599.     /**
  600.      * Closes the active SMTP session if one exists.
  601.      * @return void
  602.      */
  603.     function SmtpClose() {
  604.         if($this->smtp != NULL)
  605.         {
  606.             if($this->smtp->Connected())
  607.             {
  608.                 $this->smtp->Quit();
  609.                 $this->smtp->Close();
  610.             }
  611.         }
  612.     }
  613.  
  614.     /**
  615.      * Sets the language for all class error messages.  Returns false
  616.      * if it cannot load the language file.  The default language type
  617.      * is English.
  618.      * @param string $lang_type Type of language (e.g. Portuguese: "br")
  619.      * @param string $lang_path Path to the language file directory
  620.      * @access public
  621.      * @return bool
  622.      */
  623.     function SetLanguage($lang_type, $lang_path = "") {
  624.         if(file_exists($lang_path.'phpmailer.lang-'.$lang_type.'.php'))
  625.             include($lang_path.'phpmailer.lang-'.$lang_type.'.php');
  626.         else if(file_exists($lang_path.'phpmailer.lang-en.php'))
  627.             include($lang_path.'phpmailer.lang-en.php');
  628.         else
  629.         {
  630.             $this->SetError("Could not load language file");
  631.             return false;
  632.         }
  633.         $this->language = $PHPMAILER_LANG;
  634.  
  635.         return true;
  636.     }
  637.  
  638.     /////////////////////////////////////////////////
  639.     // MESSAGE CREATION METHODS
  640.     /////////////////////////////////////////////////
  641.  
  642.     /**
  643.      * Creates recipient headers.
  644.      * @access private
  645.      * @return string
  646.      */
  647.     function AddrAppend($type, $addr) {
  648.         $addr_str = $type . ": ";
  649.         $addr_str .= $this->AddrFormat($addr[0]);
  650.         if(count($addr) > 1)
  651.         {
  652.             for($i = 1; $i < count($addr); $i++)
  653.                 $addr_str .= ", " . $this->AddrFormat($addr[$i]);
  654.         }
  655.         $addr_str .= $this->LE;
  656.  
  657.         return $addr_str;
  658.     }
  659.  
  660.     /**
  661.      * Formats an address correctly.
  662.      * @access private
  663.      * @return string
  664.      */
  665.     function AddrFormat($addr) {
  666.         if(empty($addr[1]))
  667.             $formatted = $addr[0];
  668.         else
  669.         {
  670.             $formatted = $this->EncodeHeader($addr[1], 'phrase') . " <" .
  671.                          $addr[0] . ">";
  672.         }
  673.  
  674.         return $formatted;
  675.     }
  676.  
  677.     /**
  678.      * Wraps message for use with mailers that do not
  679.      * automatically perform wrapping and for quoted-printable.
  680.      * Original written by philippe.
  681.      * @access private
  682.      * @return string
  683.      */
  684.     function WrapText($message, $length, $qp_mode = false) {
  685.         $soft_break = ($qp_mode) ? sprintf(" =%s", $this->LE) : $this->LE;
  686.  
  687.         $message = $this->FixEOL($message);
  688.         if (substr($message, -1) == $this->LE)
  689.             $message = substr($message, 0, -1);
  690.  
  691.         $line = explode($this->LE, $message);
  692.         $message = "";
  693.         for ($i=0 ;$i < count($line); $i++)
  694.         {
  695.           $line_part = explode(" ", $line[$i]);
  696.           $buf = "";
  697.           for ($e = 0; $e<count($line_part); $e++)
  698.           {
  699.               $word = $line_part[$e];
  700.               if ($qp_mode and (strlen($word) > $length))
  701.               {
  702.                 $space_left = $length - strlen($buf) - 1;
  703.                 if ($e != 0)
  704.                 {
  705.                     if ($space_left > 20)
  706.                     {
  707.                         $len = $space_left;
  708.                         if (substr($word, $len - 1, 1) == "=")
  709.                           $len--;
  710.                         elseif (substr($word, $len - 2, 1) == "=")
  711.                           $len -= 2;
  712.                         $part = substr($word, 0, $len);
  713.                         $word = substr($word, $len);
  714.                         $buf .= " " . $part;
  715.                         $message .= $buf . sprintf("=%s", $this->LE);
  716.                     }
  717.                     else
  718.                     {
  719.                         $message .= $buf . $soft_break;
  720.                     }
  721.                     $buf = "";
  722.                 }
  723.                 while (strlen($word) > 0)
  724.                 {
  725.                     $len = $length;
  726.                     if (substr($word, $len - 1, 1) == "=")
  727.                         $len--;
  728.                     elseif (substr($word, $len - 2, 1) == "=")
  729.                         $len -= 2;
  730.                     $part = substr($word, 0, $len);
  731.                     $word = substr($word, $len);
  732.  
  733.                     if (strlen($word) > 0)
  734.                         $message .= $part . sprintf("=%s", $this->LE);
  735.                     else
  736.                         $buf = $part;
  737.                 }
  738.               }
  739.               else
  740.               {
  741.                 $buf_o = $buf;
  742.                 $buf .= ($e == 0) ? $word : (" " . $word);
  743.  
  744.                 if (strlen($buf) > $length and $buf_o != "")
  745.                 {
  746.                     $message .= $buf_o . $soft_break;
  747.                     $buf = $word;
  748.                 }
  749.               }
  750.           }
  751.           $message .= $buf . $this->LE;
  752.         }
  753.  
  754.         return $message;
  755.     }
  756.  
  757.     /**
  758.      * Set the body wrapping.
  759.      * @access private
  760.      * @return void
  761.      */
  762.     function SetWordWrap() {
  763.         if($this->WordWrap < 1)
  764.             return;
  765.  
  766.         switch($this->message_type)
  767.         {
  768.            case "alt":
  769.               // fall through
  770.            case "alt_attachment":
  771.               $this->AltBody = $this->WrapText($this->AltBody, $this->WordWrap);
  772.               break;
  773.            default:
  774.               $this->Body = $this->WrapText($this->Body, $this->WordWrap);
  775.               break;
  776.         }
  777.     }
  778.  
  779.     /**
  780.      * Assembles message header.
  781.      * @access private
  782.      * @return string
  783.      */
  784.     function CreateHeader() {
  785.  
  786.         global $GO_CONFIG;
  787.  
  788.         $result = "";
  789.  
  790.         // Set the boundaries
  791.         $uniq_id = md5(uniqid(time()));
  792.         $this->boundary[1] = "b1_" . $uniq_id;
  793.         $this->boundary[2] = "b2_" . $uniq_id;
  794.  
  795.         $result .= $this->Received();
  796.         $result .= $this->HeaderLine("Date", $this->RFCDate());
  797.         if($this->Sender == "")
  798.             $result .= $this->HeaderLine("Return-Path", trim($this->From));
  799.         else
  800.             $result .= $this->HeaderLine("Return-Path", trim($this->Sender));
  801.  
  802.         // To be created automatically by mail()
  803.         if($this->Mailer != "mail")
  804.         {
  805.             if(count($this->to) > 0)
  806.                 $result .= $this->AddrAppend("To", $this->to);
  807.             else if (count($this->cc) == 0)
  808.                 $result .= $this->HeaderLine("To", "undisclosed-recipients:;");
  809.             if(count($this->cc) > 0)
  810.                 $result .= $this->AddrAppend("Cc", $this->cc);
  811.         }
  812.  
  813.         $from = array();
  814.         $from[0][0] = trim($this->From);
  815.         $from[0][1] = $this->FromName;
  816.         $result .= $this->AddrAppend("From", $from);
  817.  
  818.         // sendmail and mail() extract Bcc from the header before sending
  819.         if((($this->Mailer == "sendmail") || ($this->Mailer == "mail")) && (count($this->bcc) > 0))
  820.             $result .= $this->AddrAppend("Bcc", $this->bcc);
  821.  
  822.         if(count($this->ReplyTo) > 0)
  823.             $result .= $this->AddrAppend("Reply-to", $this->ReplyTo);
  824.  
  825.         // mail() sets the subject itself
  826.         if($this->Mailer != "mail")
  827.             $result .= $this->HeaderLine("Subject", $this->EncodeHeader(trim($this->Subject)));
  828.  
  829.         $result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE);
  830.         $result .= $this->HeaderLine("X-Priority", $this->Priority);
  831.         $result .= $this->HeaderLine("X-Mailer", "Group-Office ".$GO_CONFIG->version);
  832.  
  833.         if($this->ConfirmReadingTo != "")
  834.         {
  835.             $result .= $this->HeaderLine("Disposition-Notification-To",
  836.                        "<" . trim($this->ConfirmReadingTo) . ">");
  837.         }
  838.  
  839.         // Add custom headers
  840.         for($index = 0; $index < count($this->CustomHeader); $index++)
  841.         {
  842.             $result .= $this->HeaderLine(trim($this->CustomHeader[$index][0]),
  843.                        $this->EncodeHeader(trim($this->CustomHeader[$index][1])));
  844.         }
  845.         $result .= $this->HeaderLine("MIME-Version", "1.0");
  846.  
  847.         switch($this->message_type)
  848.         {
  849.             case "plain":
  850.                 $result .= $this->HeaderLine("Content-Transfer-Encoding", $this->Encoding);
  851.                 $result .= sprintf("Content-Type: %s; charset=\"%s\"",
  852.                                     $this->ContentType, $this->CharSet);
  853.                 break;
  854.             case "attachments":
  855.                 // fall through
  856.             case "alt_attachments":
  857.                 if($this->InlineImageExists())
  858.                 {
  859.                     $result .= sprintf("Content-Type: %s;%s\ttype=\"text/html\";%s\tboundary=\"%s\"%s",
  860.                                     "multipart/related", $this->LE, $this->LE,
  861.                                     $this->boundary[1], $this->LE);
  862.                 }
  863.                 else
  864.                 {
  865.                     $result .= $this->HeaderLine("Content-Type", "multipart/mixed;");
  866.                     $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
  867.                 }
  868.                 break;
  869.             case "alt":
  870.                 $result .= $this->HeaderLine("Content-Type", "multipart/alternative;");
  871.                 $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
  872.                 break;
  873.         }
  874.  
  875.         if($this->Mailer != "mail")
  876.             $result .= $this->LE.$this->LE;
  877.  
  878.         return $result;
  879.     }
  880.  
  881.     /**
  882.      * Assembles the message body.  Returns an empty string on failure.
  883.      * @access private
  884.      * @return string
  885.      */
  886.     function CreateBody() {
  887.         $result = "";
  888.  
  889.         $this->SetWordWrap();
  890.  
  891.         switch($this->message_type)
  892.         {
  893.             case "alt":
  894.                 $result .= $this->GetBoundary($this->boundary[1], "",
  895.                                               "text/plain", "");
  896.                 $result .= $this->EncodeString($this->AltBody, $this->Encoding);
  897.                 $result .= $this->LE.$this->LE;
  898.                 $result .= $this->GetBoundary($this->boundary[1], "",
  899.                                               "text/html", "");
  900.  
  901.                 $result .= $this->EncodeString($this->Body, $this->Encoding);
  902.                 $result .= $this->LE.$this->LE;
  903.  
  904.                 $result .= $this->EndBoundary($this->boundary[1]);
  905.                 break;
  906.             case "plain":
  907.                 $result .= $this->EncodeString($this->Body, $this->Encoding);
  908.                 break;
  909.             case "attachments":
  910.                 $result .= $this->GetBoundary($this->boundary[1], "", "", "");
  911.                 $result .= $this->EncodeString($this->Body, $this->Encoding);
  912.                 $result .= $this->LE;
  913.  
  914.                 $result .= $this->AttachAll();
  915.                 break;
  916.             case "alt_attachments":
  917.                 $result .= sprintf("--%s%s", $this->boundary[1], $this->LE);
  918.                 $result .= sprintf("Content-Type: %s;%s" .
  919.                                    "\tboundary=\"%s\"%s",
  920.                                    "multipart/alternative", $this->LE,
  921.                                    $this->boundary[2], $this->LE.$this->LE);
  922.  
  923.                 // Create text body
  924.                 $result .= $this->GetBoundary($this->boundary[2], "",
  925.                                               "text/plain", "") . $this->LE;
  926.  
  927.                 $result .= $this->EncodeString($this->AltBody, $this->Encoding);
  928.                 $result .= $this->LE.$this->LE;
  929.  
  930.                 // Create the HTML body
  931.                 $result .= $this->GetBoundary($this->boundary[2], "",
  932.                                               "text/html", "") . $this->LE;
  933.  
  934.                 $result .= $this->EncodeString($this->Body, $this->Encoding);
  935.                 $result .= $this->LE.$this->LE;
  936.  
  937.                 $result .= $this->EndBoundary($this->boundary[2]);
  938.  
  939.                 $result .= $this->AttachAll();
  940.                 break;
  941.         }
  942.         if($this->IsError())
  943.             $result = "";
  944.  
  945.         return $result;
  946.     }
  947.  
  948.     /**
  949.      * Returns the start of a message boundary.
  950.      * @access private
  951.      */
  952.     function GetBoundary($boundary, $charSet, $contentType, $encoding) {
  953.         $result = "";
  954.         if($charSet == "") { $charSet = $this->CharSet; }
  955.         if($contentType == "") { $contentType = $this->ContentType; }
  956.         if($encoding == "") { $encoding = $this->Encoding; }
  957.  
  958.         $result .= $this->TextLine("--" . $boundary);
  959.         $result .= sprintf("Content-Type: %s; charset = \"%s\"",
  960.                             $contentType, $charSet);
  961.         $result .= $this->LE;
  962.         $result .= $this->HeaderLine("Content-Transfer-Encoding", $encoding);
  963.         $result .= $this->LE;
  964.  
  965.         return $result;
  966.     }
  967.  
  968.     /**
  969.      * Returns the end of a message boundary.
  970.      * @access private
  971.      */
  972.     function EndBoundary($boundary) {
  973.         return $this->LE . "--" . $boundary . "--" . $this->LE;
  974.     }
  975.  
  976.     /**
  977.      * Sets the message type.
  978.      * @access private
  979.      * @return void
  980.      */
  981.     function SetMessageType() {
  982.         if(count($this->attachment) < 1 && strlen($this->AltBody) < 1)
  983.             $this->message_type = "plain";
  984.         else
  985.         {
  986.             if(count($this->attachment) > 0)
  987.                 $this->message_type = "attachments";
  988.             if(strlen($this->AltBody) > 0 && count($this->attachment) < 1)
  989.                 $this->message_type = "alt";
  990.             if(strlen($this->AltBody) > 0 && count($this->attachment) > 0)
  991.                 $this->message_type = "alt_attachments";
  992.         }
  993.     }
  994.  
  995.     /**
  996.      * Returns a formatted header line.
  997.      * @access private
  998.      * @return string
  999.      */
  1000.     function HeaderLine($name, $value) {
  1001.         return $name . ": " . $value . $this->LE;
  1002.     }
  1003.  
  1004.     /**
  1005.      * Returns a formatted mail line.
  1006.      * @access private
  1007.      * @return string
  1008.      */
  1009.     function TextLine($value) {
  1010.         return $value . $this->LE;
  1011.     }
  1012.  
  1013.     /////////////////////////////////////////////////
  1014.     // ATTACHMENT METHODS
  1015.     /////////////////////////////////////////////////
  1016.  
  1017.     /**
  1018.      * Adds an attachment from a path on the filesystem.
  1019.      * Returns false if the file could not be found
  1020.      * or accessed.
  1021.      * @param string $path Path to the attachment.
  1022.      * @param string $name Overrides the attachment name.
  1023.      * @param string $encoding File encoding (see $Encoding).
  1024.      * @param string $type File extension (MIME) type.
  1025.      * @return bool
  1026.      */
  1027.     function AddAttachment($path, $name = "", $encoding = "base64",
  1028.                            $type = "application/octet-stream") {
  1029.         if(!@is_file($path))
  1030.         {
  1031.             $this->SetError($this->Lang("file_access") . $path);
  1032.             return false;
  1033.         }
  1034.  
  1035.         $filename = basename($path);
  1036.         if($name == "")
  1037.             $name = $filename;
  1038.  
  1039.         $cur = count($this->attachment);
  1040.         $this->attachment[$cur][0] = $path;
  1041.         $this->attachment[$cur][1] = $filename;
  1042.         $this->attachment[$cur][2] = $name;
  1043.         $this->attachment[$cur][3] = $encoding;
  1044.         $this->attachment[$cur][4] = $type;
  1045.         $this->attachment[$cur][5] = false; // isStringAttachment
  1046.         $this->attachment[$cur][6] = "attachment";
  1047.         $this->attachment[$cur][7] = 0;
  1048.  
  1049.         return true;
  1050.     }
  1051.  
  1052.     /**
  1053.      * Attaches all fs, string, and binary attachments to the message.
  1054.      * Returns an empty string on failure.
  1055.      * @access private
  1056.      * @return string
  1057.      */
  1058.     function AttachAll() {
  1059.         // Return text of body
  1060.         $mime = array();
  1061.  
  1062.         // Add all attachments
  1063.         for($i = 0; $i < count($this->attachment); $i++)
  1064.         {
  1065.             // Check for string attachment
  1066.             $bString = $this->attachment[$i][5];
  1067.             if ($bString)
  1068.                 $string = $this->attachment[$i][0];
  1069.             else
  1070.                 $path = $this->attachment[$i][0];
  1071.  
  1072.             $filename    = $this->attachment[$i][1];
  1073.             $name        = $this->attachment[$i][2];
  1074.             $encoding    = $this->attachment[$i][3];
  1075.             $type        = $this->attachment[$i][4];
  1076.             $disposition = $this->attachment[$i][6];
  1077.             $cid         = $this->attachment[$i][7];
  1078.  
  1079.             $mime[] = sprintf("--%s%s", $this->boundary[1], $this->LE);
  1080.             $mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $name, $this->LE);
  1081.             $mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE);
  1082.  
  1083.             if($disposition == "inline")
  1084.                 $mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE);
  1085.  
  1086.             $mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s",
  1087.                               $disposition, $name, $this->LE.$this->LE);
  1088.  
  1089.             // Encode as string attachment
  1090.             if($bString)
  1091.             {
  1092.                 $mime[] = $this->EncodeString($string, $encoding);
  1093.                 if($this->IsError()) { return ""; }
  1094.                 $mime[] = $this->LE.$this->LE;
  1095.             }
  1096.             else
  1097.             {
  1098.                 $mime[] = $this->EncodeFile($path, $encoding);
  1099.                 if($this->IsError()) { return ""; }
  1100.                 $mime[] = $this->LE.$this->LE;
  1101.             }
  1102.         }
  1103.  
  1104.         $mime[] = sprintf("--%s--%s", $this->boundary[1], $this->LE);
  1105.  
  1106.         return join("", $mime);
  1107.     }
  1108.  
  1109.     /**
  1110.      * Encodes attachment in requested format.  Returns an
  1111.      * empty string on failure.
  1112.      * @access private
  1113.      * @return string
  1114.      */
  1115.     function EncodeFile ($path, $encoding = "base64") {
  1116.         if(!@$fd = fopen($path, "rb"))
  1117.         {
  1118.             $this->SetError($this->Lang("file_open") . $path);
  1119.             return "";
  1120.         }
  1121.         $file_buffer = fread($fd, filesize($path));
  1122.         $file_buffer = $this->EncodeString($file_buffer, $encoding);
  1123.         fclose($fd);
  1124.  
  1125.         return $file_buffer;
  1126.     }
  1127.  
  1128.     /**
  1129.      * Encodes string to requested format. Returns an
  1130.      * empty string on failure.
  1131.      * @access private
  1132.      * @return string
  1133.      */
  1134.     function EncodeString ($str, $encoding = "base64") {
  1135.         $encoded = "";
  1136.         switch(strtolower($encoding)) {
  1137.           case "base64":
  1138.               // chunk_split is found in PHP >= 3.0.6
  1139.               $encoded = chunk_split(base64_encode($str), 76, $this->LE);
  1140.               break;
  1141.           case "7bit":
  1142.           case "8bit":
  1143.               $encoded = $this->FixEOL($str);
  1144.               if (substr($encoded, -(strlen($this->LE))) != $this->LE)
  1145.                 $encoded .= $this->LE;
  1146.               break;
  1147.           case "binary":
  1148.               $encoded = $str;
  1149.               break;
  1150.           case "quoted-printable":
  1151.               $encoded = $this->EncodeQP($str);
  1152.               break;
  1153.           default:
  1154.               $this->SetError($this->Lang("encoding") . $encoding);
  1155.               break;
  1156.         }
  1157.         return $encoded;
  1158.     }
  1159.  
  1160.     /**
  1161.      * Encode a header string to best of Q, B, quoted or none.
  1162.      * @access private
  1163.      * @return string
  1164.      */
  1165.     function EncodeHeader ($str, $position = 'text') {
  1166.       $x = 0;
  1167.  
  1168.       switch (strtolower($position)) {
  1169.         case 'phrase':
  1170.           if (!preg_match('/[\200-\377]/', $str)) {
  1171.             // Can't use addslashes as we don't know what value has magic_quotes_sybase.
  1172.             $encoded = addcslashes($str, "\0..\37\177\\\"");
  1173.  
  1174.             if (($str == $encoded) && !preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str))
  1175.               return ($encoded);
  1176.             else
  1177.               return ("\"$encoded\"");
  1178.           }
  1179.           $x = preg_match_all('/[^\040\041\043-\133\135-\176]/', $str, $matches);
  1180.           break;
  1181.         case 'comment':
  1182.           $x = preg_match_all('/[()"]/', $str, $matches);
  1183.           // Fall-through
  1184.         case 'text':
  1185.         default:
  1186.           $x += preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches);
  1187.           break;
  1188.       }
  1189.  
  1190.       if ($x == 0)
  1191.         return ($str);
  1192.  
  1193.       $maxlen = 75 - 7 - strlen($this->CharSet);
  1194.       // Try to select the encoding which should produce the shortest output
  1195.       if (strlen($str)/3 < $x) {
  1196.         $encoding = 'B';
  1197.         $encoded = base64_encode($str);
  1198.         $maxlen -= $maxlen % 4;
  1199.         $encoded = trim(chunk_split($encoded, $maxlen, "\n"));
  1200.       } else {
  1201.         $encoding = 'Q';
  1202.         $encoded = $this->EncodeQ($str, $position);
  1203.         $encoded = $this->WrapText($encoded, $maxlen, true);
  1204.         $encoded = str_replace("=".$this->LE, "\n", trim($encoded));
  1205.       }
  1206.  
  1207.       $encoded = preg_replace('/^(.*)$/m', " =?".$this->CharSet."?$encoding?\\1?=", $encoded);
  1208.       $encoded = trim(str_replace("\n", $this->LE, $encoded));
  1209.  
  1210.       return $encoded;
  1211.     }
  1212.  
  1213.     /**
  1214.      * Encode string to quoted-printable.
  1215.      * @access private
  1216.      * @return string
  1217.      */
  1218.     function EncodeQP ($str) {
  1219.         $encoded = $this->FixEOL($str);
  1220.         if (substr($encoded, -(strlen($this->LE))) != $this->LE)
  1221.             $encoded .= $this->LE;
  1222.  
  1223.         // Replace every high ascii, control and = characters
  1224.         $encoded = preg_replace('/([\000-\010\013\014\016-\037\075\177-\377])/e',
  1225.                   "'='.sprintf('%02X', ord('\\1'))", $encoded);
  1226.         // Replace every spaces and tabs when it's the last character on a line
  1227.         $encoded = preg_replace("/([\011\040])".$this->LE."/e",
  1228.                   "'='.sprintf('%02X', ord('\\1')).'".$this->LE."'", $encoded);
  1229.  
  1230.         // Maximum line length of 76 characters before CRLF (74 + space + '=')
  1231.         $encoded = $this->WrapText($encoded, 74, true);
  1232.  
  1233.         return $encoded;
  1234.     }
  1235.  
  1236.     /**
  1237.      * Encode string to q encoding.
  1238.      * @access private
  1239.      * @return string
  1240.      */
  1241.     function EncodeQ ($str, $position = "text") {
  1242.         // There should not be any EOL in the string
  1243.         $encoded = preg_replace("[\r\n]", "", $str);
  1244.  
  1245.         switch (strtolower($position)) {
  1246.           case "phrase":
  1247.             $encoded = preg_replace("/([^A-Za-z0-9!*+\/ -])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
  1248.             break;
  1249.           case "comment":
  1250.             $encoded = preg_replace("/([\(\)\"])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
  1251.           case "text":
  1252.           default:
  1253.             // Replace every high ascii, control =, ? and _ characters
  1254.             $encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e',
  1255.                   "'='.sprintf('%02X', ord('\\1'))", $encoded);
  1256.             break;
  1257.         }
  1258.  
  1259.         // Replace every spaces to _ (more readable than =20)
  1260.         $encoded = str_replace(" ", "_", $encoded);
  1261.  
  1262.         return $encoded;
  1263.     }
  1264.  
  1265.     /**
  1266.      * Adds a string or binary attachment (non-filesystem) to the list.
  1267.      * This method can be used to attach ascii or binary data,
  1268.      * such as a BLOB record from a database.
  1269.      * @param string $string String attachment data.
  1270.      * @param string $filename Name of the attachment.
  1271.      * @param string $encoding File encoding (see $Encoding).
  1272.      * @param string $type File extension (MIME) type.
  1273.      * @return void
  1274.      */
  1275.     function AddStringAttachment($string, $filename, $encoding = "base64",
  1276.                                  $type = "application/octet-stream") {
  1277.         // Append to $attachment array
  1278.         $cur = count($this->attachment);
  1279.         $this->attachment[$cur][0] = $string;
  1280.         $this->attachment[$cur][1] = $filename;
  1281.         $this->attachment[$cur][2] = $filename;
  1282.         $this->attachment[$cur][3] = $encoding;
  1283.         $this->attachment[$cur][4] = $type;
  1284.         $this->attachment[$cur][5] = true; // isString
  1285.         $this->attachment[$cur][6] = "attachment";
  1286.         $this->attachment[$cur][7] = 0;
  1287.     }
  1288.  
  1289.     /**
  1290.      * Adds an embedded attachment.  This can include images, sounds, and
  1291.      * just about any other document.  Make sure to set the $type to an
  1292.      * image type.  For JPEG images use "image/jpeg" and for GIF images
  1293.      * use "image/gif".
  1294.      * @param string $path Path to the attachment.
  1295.      * @param string $cid Content ID of the attachment.  Use this to identify
  1296.      *        the Id for accessing the image in an HTML form.
  1297.      * @param string $name Overrides the attachment name.
  1298.      * @param string $encoding File encoding (see $Encoding).
  1299.      * @param string $type File extension (MIME) type.
  1300.      * @return bool
  1301.      */
  1302.     function AddEmbeddedImage($path, $cid, $name = "", $encoding = "base64",
  1303.                               $type = "application/octet-stream") {
  1304.  
  1305.         if(!@is_file($path))
  1306.         {
  1307.             $this->SetError($this->Lang("file_access") . $path);
  1308.             return false;
  1309.         }
  1310.  
  1311.         $filename = basename($path);
  1312.         if($name == "")
  1313.             $name = $filename;
  1314.  
  1315.         // Append to $attachment array
  1316.         $cur = count($this->attachment);
  1317.         $this->attachment[$cur][0] = $path;
  1318.         $this->attachment[$cur][1] = $filename;
  1319.         $this->attachment[$cur][2] = $name;
  1320.         $this->attachment[$cur][3] = $encoding;
  1321.         $this->attachment[$cur][4] = $type;
  1322.         $this->attachment[$cur][5] = false; // isStringAttachment
  1323.         $this->attachment[$cur][6] = "inline";
  1324.         $this->attachment[$cur][7] = $cid;
  1325.  
  1326.         return true;
  1327.     }
  1328.  
  1329.     /**
  1330.      * Adds an embedded attachment.  This can include images, sounds, and
  1331.      * just about any other document.  Make sure to set the $type to an
  1332.      * image type.  For JPEG images use "image/jpeg" and for GIF images
  1333.      * use "image/gif".
  1334.      * @param string $path Path to the attachment.
  1335.      * @param string $cid Content ID of the attachment.  Use this to identify
  1336.      *        the Id for accessing the image in an HTML form.
  1337.      * @param string $name Overrides the attachment name.
  1338.      * @param string $encoding File encoding (see $Encoding).
  1339.      * @param string $type File extension (MIME) type.
  1340.      * @return bool
  1341.      */
  1342.     function AddStringEmbeddedImage($string, $cid, $name = "", $encoding = "base64",
  1343.                               $type = "application/octet-stream") {
  1344.  
  1345.         // Append to $attachment array
  1346.         $cur = count($this->attachment);
  1347.         $this->attachment[$cur][0] = $string;
  1348.         $this->attachment[$cur][1] = $name;
  1349.         $this->attachment[$cur][2] = $name;
  1350.         $this->attachment[$cur][3] = $encoding;
  1351.         $this->attachment[$cur][4] = $type;
  1352.         $this->attachment[$cur][5] = true; // isStringAttachment
  1353.         $this->attachment[$cur][6] = "inline";
  1354.         $this->attachment[$cur][7] = $cid;
  1355.  
  1356.         return true;
  1357.     }
  1358.  
  1359.     /**
  1360.      * Returns true if an inline attachment is present.
  1361.      * @access private
  1362.      * @return bool
  1363.      */
  1364.     function InlineImageExists() {
  1365.         $result = false;
  1366.         for($i = 0; $i < count($this->attachment); $i++)
  1367.         {
  1368.             if($this->attachment[$i][6] == "inline")
  1369.             {
  1370.                 $result = true;
  1371.                 break;
  1372.             }
  1373.         }
  1374.  
  1375.         return $result;
  1376.     }
  1377.  
  1378.     /////////////////////////////////////////////////
  1379.     // MESSAGE RESET METHODS
  1380.     /////////////////////////////////////////////////
  1381.  
  1382.     /**
  1383.      * Clears all recipients assigned in the TO array.  Returns void.
  1384.      * @return void
  1385.      */
  1386.     function ClearAddresses() {
  1387.         $this->to = array();
  1388.     }
  1389.  
  1390.     /**
  1391.      * Clears all recipients assigned in the CC array.  Returns void.
  1392.      * @return void
  1393.      */
  1394.     function ClearCCs() {
  1395.         $this->cc = array();
  1396.     }
  1397.  
  1398.     /**
  1399.      * Clears all recipients assigned in the BCC array.  Returns void.
  1400.      * @return void
  1401.      */
  1402.     function ClearBCCs() {
  1403.         $this->bcc = array();
  1404.     }
  1405.  
  1406.     /**
  1407.      * Clears all recipients assigned in the ReplyTo array.  Returns void.
  1408.      * @return void
  1409.      */
  1410.     function ClearReplyTos() {
  1411.         $this->ReplyTo = array();
  1412.     }
  1413.  
  1414.     /**
  1415.      * Clears all recipients assigned in the TO, CC and BCC
  1416.      * array.  Returns void.
  1417.      * @return void
  1418.      */
  1419.     function ClearAllRecipients() {
  1420.         $this->to = array();
  1421.         $this->cc = array();
  1422.         $this->bcc = array();
  1423.     }
  1424.  
  1425.     /**
  1426.      * Clears all previously set filesystem, string, and binary
  1427.      * attachments.  Returns void.
  1428.      * @return void
  1429.      */
  1430.     function ClearAttachments() {
  1431.         $this->attachment = array();
  1432.     }
  1433.  
  1434.     /**
  1435.      * Clears all custom headers.  Returns void.
  1436.      * @return void
  1437.      */
  1438.     function ClearCustomHeaders() {
  1439.         $this->CustomHeader = array();
  1440.     }
  1441.  
  1442.  
  1443.     /////////////////////////////////////////////////
  1444.     // MISCELLANEOUS METHODS
  1445.     /////////////////////////////////////////////////
  1446.  
  1447.     /**
  1448.      * Adds the error message to the error container.
  1449.      * Returns void.
  1450.      * @access private
  1451.      * @return void
  1452.      */
  1453.     function SetError($msg) {
  1454.         $this->error_count++;
  1455.         $this->ErrorInfo = $msg;
  1456.     }
  1457.  
  1458.     /**
  1459.      * Returns the proper RFC 822 formatted date.
  1460.      * @access private
  1461.      * @return string
  1462.      */
  1463.     function RFCDate() {
  1464.         $tz = date("Z");
  1465.         $tzs = ($tz < 0) ? "-" : "+";
  1466.         $tz = abs($tz);
  1467.         $tz = ($tz/3600)*100 + ($tz%3600)/60;
  1468.         $result = sprintf("%s %s%04d", date("D, j M Y H:i:s"), $tzs, $tz);
  1469.  
  1470.         return $result;
  1471.     }
  1472.  
  1473.     /**
  1474.      * Returns Received header for message tracing.
  1475.      * @access private
  1476.      * @return string
  1477.      */
  1478.     function Received() {
  1479.         if ($this->ServerVar('SERVER_NAME') != '')
  1480.         {
  1481.             $protocol = ($this->ServerVar('HTTPS') == 'on') ? 'HTTPS' : 'HTTP';
  1482.             $remote = $this->ServerVar('REMOTE_HOST');
  1483.             if($remote == "")
  1484.                 $remote = 'Group-Office';
  1485.             $remote .= ' (['.$this->ServerVar('REMOTE_ADDR').'])';
  1486.         }
  1487.         else
  1488.         {
  1489.             $protocol = 'local';
  1490.             $remote = $this->ServerVar('USER');
  1491.             if($remote == '')
  1492.                 $remote = 'Group-Office';
  1493.         }
  1494.  
  1495.         $result = sprintf("Received: from %s %s\tby %s " .
  1496.                           "with %s (Group-Office);%s\t%s%s", $remote, $this->LE,
  1497.                           $this->ServerHostname(), $protocol, $this->LE,
  1498.                           $this->RFCDate(), $this->LE);
  1499.  
  1500.         return $result;
  1501.     }
  1502.  
  1503.     /**
  1504.      * Returns the appropriate server variable.  Should work with both
  1505.      * PHP 4.1.0+ as well as older versions.  Returns an empty string
  1506.      * if nothing is found.
  1507.      * @access private
  1508.      * @return mixed
  1509.      */
  1510.     function ServerVar($varName) {
  1511.         global $HTTP_SERVER_VARS;
  1512.         global $HTTP_ENV_VARS;
  1513.  
  1514.         if(!isset($_SERVER))
  1515.         {
  1516.             $_SERVER = $HTTP_SERVER_VARS;
  1517.             if(!isset($_SERVER["REMOTE_ADDR"]))
  1518.                 $_SERVER = $HTTP_ENV_VARS; // must be Apache
  1519.         }
  1520.  
  1521.         if(isset($_SERVER[$varName]))
  1522.             return $_SERVER[$varName];
  1523.         else
  1524.             return "";
  1525.     }
  1526.  
  1527.     /**
  1528.      * Returns the server hostname or 'localhost.localdomain' if unknown.
  1529.      * @access private
  1530.      * @return string
  1531.      */
  1532.     function ServerHostname() {
  1533.         if ($this->Hostname != "")
  1534.             $result = $this->Hostname;
  1535.         elseif ($this->ServerVar('SERVER_NAME') != "")
  1536.             $result = $this->ServerVar('SERVER_NAME');
  1537.         else
  1538.             $result = "localhost.localdomain";
  1539.  
  1540.         return $result;
  1541.     }
  1542.  
  1543.     /**
  1544.      * Returns a message in the appropriate language.
  1545.      * @access private
  1546.      * @return string
  1547.      */
  1548.     function Lang($key) {
  1549.         if(count($this->language) < 1)
  1550.             $this->SetLanguage("en"); // set the default language
  1551.  
  1552.         if(isset($this->language[$key]))
  1553.             return $this->language[$key];
  1554.         else
  1555.             return "Language string failed to load: " . $key;
  1556.     }
  1557.  
  1558.     /**
  1559.      * Returns true if an error occurred.
  1560.      * @return bool
  1561.      */
  1562.     function IsError() {
  1563.         return ($this->error_count > 0);
  1564.     }
  1565.  
  1566.     /**
  1567.      * Changes every end of line from CR or LF to CRLF.
  1568.      * @access private
  1569.      * @return string
  1570.      */
  1571.     function FixEOL($str) {
  1572.         $str = str_replace("\r\n", "\n", $str);
  1573.         $str = str_replace("\r", "\n", $str);
  1574.         $str = str_replace("\n", $this->LE, $str);
  1575.         return $str;
  1576.     }
  1577.  
  1578.     /**
  1579.      * Adds a custom header.
  1580.      * @return void
  1581.      */
  1582.     function AddCustomHeader($custom_header) {
  1583.         $this->CustomHeader[] = explode(":", $custom_header, 2);
  1584.     }
  1585. }
  1586.  
  1587. ?>
  1588.