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 1999-2020 The SquirrelMail Project Team
  10.  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  11.  * @version $Id: Deliver_SendMail.class.php 14840 2020-01-07 07:42:38Z pdontthink $
  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 (PHP5 style, required in some future version of PHP)
  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 __construct($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.      * Constructor (PHP4 style, kept for compatibility reasons)
  65.      * @param array configuration options. array key = option name,
  66.      *  array value = option value.
  67.      * @return void 
  68.      * @since 1.5.1 and 1.4.8
  69.      */
  70.     function Deliver_SendMail($params=array()) {
  71.         self::__construct($params);
  72.     }
  73.  
  74.    /**
  75.     * function preWriteToStream
  76.     *
  77.     * Sendmail needs LF's as line endings instead of CRLF.
  78.     * This function translates the line endings to LF and should be called
  79.     * before each line is written to the stream.
  80.     *
  81.     * @param string $s Line to process
  82.     * @return void 
  83.     * @access private
  84.     */
  85.     function preWriteToStream(&$s{
  86.        if ($s{
  87.            $s str_replace("\r\n""\n"$s);
  88.        }
  89.     }
  90.  
  91.    /**
  92.     * function initStream
  93.     *
  94.     * Initialise the sendmail connection.
  95.     *
  96.     * @param Message $message Message object containing the from address
  97.     * @param string $sendmail_path Location of sendmail binary
  98.     * @param mixed $ignore_x Eight extra arguments that the parent class
  99.     *                         requires which are not used here
  100.     * @return void 
  101.     * @access public
  102.     */
  103.     function initStream($message$sendmail_path$ignore_1=0$ignore_2=''$ignore_3=''$ignore_4=''$ignore_5=''$ignore_6=false$ignore_7=''$ignore_8=array()) {
  104.         $rfc822_header $message->rfc822_header;
  105.         $from $rfc822_header->from[0];
  106.         $envelopefrom trim($from->mailbox.'@'.$from->host);
  107.         // save executed command for future reference
  108.         $this->sendmail_command = escapeshellcmd("$sendmail_path $this->sendmail_args -f"escapeshellarg($envelopefrom);
  109.         // open process handle for writing
  110.         $stream popen($this->sendmail_command"w");
  111.         return $stream;
  112.     }
  113.  
  114.    /**
  115.     * function finalizeStream
  116.     *
  117.     * Close the stream.
  118.     *
  119.     * @param resource $stream 
  120.     * @return boolean 
  121.     * @access public
  122.     */
  123.     function finalizeStream($stream{
  124.         $ret true;
  125.         $status pclose($stream);
  126.         // check pclose() status.
  127.         if ($status!=0{
  128.             $ret false;
  129.             $this->dlv_msg=_("Email delivery error");
  130.             $this->dlv_ret_nr=$status;
  131.             // we can get better error messsage only if we switch to php 4.3+ and proc_open().
  132.             $this->dlv_server_msg=sprintf(_("Can't execute command '%s'."),$this->sendmail_command);
  133.         }
  134.         return $ret;
  135.     }
  136.  
  137.    /**
  138.     * function getBcc
  139.     *
  140.     * In case of sendmail, the rfc822header must contain the bcc header.
  141.     *
  142.     * @return boolean true if rfc822header should include the bcc header.
  143.     * @access private
  144.     */
  145.     function getBcc({
  146.         return true;
  147.     }
  148.  
  149.    /**
  150.     * function clean_crlf
  151.     *
  152.     * Cleans each line to only end in a LF
  153.     * Returns the length of the line including a CR,
  154.     * so that length is correct when the message is saved to imap
  155.     * Implemented to fix sendmail->postfix rejection of messages with
  156.     * attachments because of stray LF's
  157.     *
  158.     * @param string $s string to strip of CR's
  159.     * @return integer length of string including a CR for each LF
  160.     * @access private
  161.     */
  162.     function clean_crlf(&$s{
  163.         $s str_replace("\r\n""\n"$s);
  164.         $s str_replace("\r""\n"$s);
  165.         $s2 str_replace("\n""\r\n"$s);
  166.         return strlen($s2);
  167.     }
  168.  
  169.  
  170. }

Documentation generated on Mon, 13 Jan 2020 04:24:31 +0100 by phpDocumentor 1.4.3