Platon Technologies
not logged in Login Registration
EnglishSlovak
open source software development celebrating 10 years of open source development! Wednesday, October 14, 2026

Diff for Metafox/lib/Mail/sendmail.php between version 1.4 and 1.5

version 1.4, 2006/03/29 09:23:13 version 1.5, 2011/06/17 13:56:39
Line 24 
Line 24 
  */   */
 class Mail_sendmail extends Mail {  class Mail_sendmail extends Mail {
   
         /**      /**
      * The location of the sendmail or sendmail wrapper binary on the       * The location of the sendmail or sendmail wrapper binary on the
      * filesystem.       * filesystem.
      * @var string       * @var string
      */       */
     var $sendmail_path = '/usr/sbin/sendmail';      var $sendmail_path = '/usr/sbin/sendmail';
   
         /**      /**
      * Any extra command-line parameters to pass to the sendmail or       * Any extra command-line parameters to pass to the sendmail or
      * sendmail wrapper binary.       * sendmail wrapper binary.
      * @var string       * @var string
      */       */
     var $sendmail_args = '';      var $sendmail_args = '-i';
   
         /**      /**
      * Constructor.       * Constructor.
      *       *
      * Instantiates a new Mail_sendmail:: object based on the parameters       * Instantiates a new Mail_sendmail:: object based on the parameters
Line 58  class Mail_sendmail extends Mail {
Line 58  class Mail_sendmail extends Mail {
      */       */
     function Mail_sendmail($params)      function Mail_sendmail($params)
     {      {
         if (isset($params['sendmail_path'])) $this->sendmail_path = $params['sendmail_path'];          if (isset($params['sendmail_path'])) {
         if (isset($params['sendmail_args'])) $this->sendmail_args = $params['sendmail_args'];              $this->sendmail_path = $params['sendmail_path'];
           }
           if (isset($params['sendmail_args'])) {
               $this->sendmail_args = $params['sendmail_args'];
           }
   
         /*          /*
          * Because we need to pass message headers to the sendmail program on           * Because we need to pass message headers to the sendmail program on
          * the commandline, we can't guarantee the use of the standard "\r\n"           * the commandline, we can't guarantee the use of the standard "\r\n"
          * separator.  Instead, we use the system's native line separator.           * separator.  Instead, we use the system's native line separator.
          */           */
         $this->sep = (strpos(PHP_OS, 'WIN') === false) ? "\n" : "\r\n";          if (defined('PHP_EOL')) {
               $this->sep = PHP_EOL;
           } else {
               $this->sep = (strpos(PHP_OS, 'WIN') === false) ? "\n" : "\r\n";
           }
     }      }
   
         /**      /**
      * Implements Mail::send() function using the sendmail       * Implements Mail::send() function using the sendmail
      * command-line binary.       * command-line binary.
      *       *
Line 96  class Mail_sendmail extends Mail {
Line 104  class Mail_sendmail extends Mail {
      */       */
     function send($recipients, $headers, $body)      function send($recipients, $headers, $body)
     {      {
           if (!is_array($headers)) {
               return PEAR::raiseError('$headers must be an array');
           }
   
           $result = $this->_sanitizeHeaders($headers);
           if (is_a($result, 'PEAR_Error')) {
               return $result;
           }
   
         $recipients = $this->parseRecipients($recipients);          $recipients = $this->parseRecipients($recipients);
         if (PEAR::isError($recipients)) {          if (is_a($recipients, 'PEAR_Error')) {
             return $recipients;              return $recipients;
         }          }
         $recipients = escapeShellCmd(implode(' ', $recipients));          $recipients = implode(' ', array_map('escapeshellarg', $recipients));
   
         $headerElements = $this->prepareHeaders($headers);          $headerElements = $this->prepareHeaders($headers);
         if (PEAR::isError($headerElements)) {          if (is_a($headerElements, 'PEAR_Error')) {
             return $headerElements;              return $headerElements;
         }          }
         list($from, $text_headers) = $headerElements;          list($from, $text_headers) = $headerElements;
   
           /* Since few MTAs are going to allow this header to be forged
            * unless it's in the MAIL FROM: exchange, we'll use
            * Return-Path instead of From: if it's set. */
           if (!empty($headers['Return-Path'])) {
               $from = $headers['Return-Path'];
           }
   
         if (!isset($from)) {          if (!isset($from)) {
             return PEAR::raiseError('No from address given.');              return PEAR::raiseError('No from address given.');
         } elseif (strpos($from, ' ') !== false ||          } elseif (strpos($from, ' ') !== false ||
Line 117  class Mail_sendmail extends Mail {
Line 141  class Mail_sendmail extends Mail {
             return PEAR::raiseError('From address specified with dangerous characters.');              return PEAR::raiseError('From address specified with dangerous characters.');
         }          }
   
         $result = 0;          $from = escapeshellarg($from); // Security bug #16200
         if (@is_file($this->sendmail_path)) {  
             $from = escapeShellCmd($from);          $mail = @popen($this->sendmail_path . (!empty($this->sendmail_args) ? ' ' . $this->sendmail_args : '') . " -f$from -- $recipients", 'w');
             $mail = popen($this->sendmail_path . (!empty($this->sendmail_args) ? ' ' . $this->sendmail_args : '') . " -f$from -- $recipients", 'w');          if (!$mail) {
             fputs($mail, $text_headers);              return PEAR::raiseError('Failed to open sendmail [' . $this->sendmail_path . '] for execution.');
             fputs($mail, $this->sep);  // newline to end the headers section          }
             fputs($mail, $body);  
             $result = pclose($mail);          // Write the headers following by two newlines: one to end the headers
             if (version_compare(phpversion(), '4.2.3') == -1) {          // section and a second to separate the headers block from the body.
                 // With older php versions, we need to shift the          fputs($mail, $text_headers . $this->sep . $this->sep);
                 // pclose result to get the exit code.  
                 $result = $result >> 8 & 0xFF;          fputs($mail, $body);
             }          $result = pclose($mail);
         } else {          if (version_compare(phpversion(), '4.2.3') == -1) {
             return PEAR::raiseError('sendmail [' . $this->sendmail_path . '] is not a valid file');              // With older php versions, we need to shift the pclose
               // result to get the exit code.
               $result = $result >> 8 & 0xFF;
         }          }
   
         if ($result != 0) {          if ($result != 0) {

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5

Platon Group <platon@platon.org> http://platon.org/
Copyright © 2002-2006 Platon Group
Site powered by Metafox CMS
Go to Top