Source for file Deliver_SendMail.class.php

Documentation is available at Deliver_SendMail.class.php

  1. <?php
  2.  
  3. /**
  4.  * Deliver_SendMail.class.php
  5.  *
  6.  * Delivery backend for the Deliver class.
  7.  *
  8.  * @author Marc Groot Koerkamp
  9.  * @copyright &copy; 1999-2006 The SquirrelMail Project Team
  10.  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  11.  * @version $Id: Deliver_SendMail.class.php,v 1.11.2.9 2006/08/01 05:47:32 tokul Exp $
  12.  * @package squirrelmail
  13.  */
  14.  
  15.  
  16. /** This of course depends upon Deliver */
  17. require_once(SM_PATH 'class/deliver/Deliver.class.php');
  18.  
  19. /**
  20.  * Delivers messages using the sendmail binary
  21.  * @package squirrelmail
  22.  */
  23. class Deliver_SendMail extends Deliver {
  24.     /**
  25.      * Extra sendmail arguments
  26.      *
  27.      * Parameter can be set in class constructor function.
  28.      *
  29.      * WARNING: Introduction of this parameter broke backwards compatibility
  30.      * with workarounds specific to qmail-inject.
  31.      *
  32.      * If parameter needs some security modifications, it should be set to
  33.      * private in PHP 5+ in order to prevent uncontrolled access.
  34.      * @var string 
  35.      * @since 1.5.1 and 1.4.8
  36.      */
  37.     var $sendmail_args = '-i -t';
  38.  
  39.     /**
  40.      * Stores used sendmail command
  41.      * Private variable that is used to inform about used sendmail command.
  42.      * @var string 
  43.      * @since 1.5.1 and 1.4.8
  44.      */
  45.     var $sendmail_command = '';
  46.  
  47.     /**
  48.      * Constructor function
  49.      * @param array configuration options. array key = option name,
  50.      *  array value = option value.
  51.      * @return void 
  52.      * @since 1.5.1 and 1.4.8
  53.      */
  54.     function Deliver_SendMail($params=array()) {
  55.         if (!empty($params&& is_array($params)) {
  56.             // set extra sendmail arguments
  57.             if (isset($params['sendmail_args'])) {
  58.                 $this->sendmail_args = $params['sendmail_args'];
  59.             }
  60.         }
  61.     }
  62.  
  63.    /**
  64.     * function preWriteToStream
  65.     *
  66.     * Sendmail needs LF's as line endings instead of CRLF.
  67.     * This function translates the line endings to LF and should be called
  68.     * before each line is written to the stream.
  69.     *
  70.     * @param string $s Line to process
  71.     * @return void 
  72.     * @access private
  73.     */
  74.     function preWriteToStream(&$s{
  75.        if ($s{
  76.            $s str_replace("\r\n""\n"$s);
  77.        }
  78.     }
  79.  
  80.    /**
  81.     * function initStream
  82.     *
  83.     * Initialise the sendmail connection.
  84.     *
  85.     * @param Message $message Message object containing the from address
  86.     * @param string $sendmail_path Location of sendmail binary
  87.     * @return void 
  88.     * @access public
  89.     */
  90.     function initStream($message$sendmail_path{
  91.         $rfc822_header $message->rfc822_header;
  92.         $from $rfc822_header->from[0];
  93.         $envelopefrom trim($from->mailbox.'@'.$from->host);
  94.         $envelopefrom str_replace(array("\0","\n"),array('',''),$envelopefrom);
  95.         // save executed command for future reference
  96.         $this->sendmail_command = "$sendmail_path $this->sendmail_args -f$envelopefrom";
  97.         // open process handle for writing
  98.         $stream popen(escapeshellcmd($this->sendmail_command)"w");
  99.         return $stream;
  100.     }
  101.  
  102.    /**
  103.     * function finalizeStream
  104.     *
  105.     * Close the stream.
  106.     *
  107.     * @param resource $stream 
  108.     * @return boolean 
  109.     * @access public
  110.     */
  111.     function finalizeStream($stream{
  112.         $ret true;
  113.         $status pclose($stream);
  114.         // check pclose() status.
  115.         if ($status!=0{
  116.             $ret false;
  117.             $this->dlv_msg=_("Email delivery error");
  118.             $this->dlv_ret_nr=$status;
  119.             // we can get better error messsage only if we switch to php 4.3+ and proc_open().
  120.             $this->dlv_server_msg=sprintf(_("Can't execute command '%s'."),$this->sendmail_command);
  121.         }
  122.         return $ret;
  123.     }
  124.  
  125.    /**
  126.     * function getBcc
  127.     *
  128.     * In case of sendmail, the rfc822header must contain the bcc header.
  129.     *
  130.     * @return boolean true if rfc822header should include the bcc header.
  131.     * @access private
  132.     */
  133.     function getBcc({
  134.         return true;
  135.     }
  136.  
  137.    /**
  138.     * function clean_crlf
  139.     *
  140.     * Cleans each line to only end in a LF
  141.     * Returns the length of the line including a CR,
  142.     * so that length is correct when the message is saved to imap
  143.     * Implemented to fix sendmail->postfix rejection of messages with
  144.     * attachments because of stray LF's
  145.     *
  146.     * @param string $s string to strip of CR's
  147.     * @return integer length of string including a CR for each LF
  148.     * @access private
  149.     */
  150.     function clean_crlf(&$s{
  151.         $s str_replace("\r\n""\n"$s);
  152.         $s str_replace("\r""\n"$s);
  153.         $s2 str_replace("\n""\r\n"$s);
  154.         return strlen($s2);
  155.     }
  156.  
  157.  
  158. }
  159. ?>

Documentation generated on Sat, 07 Oct 2006 16:30:54 +0300 by phpDocumentor 1.3.0RC6