X-Git-Url: https://vcs.fsf.org/?p=squirrelmail.git;a=blobdiff_plain;f=class%2Fdeliver%2FDeliver_SendMail.class.php;h=06747541a0c7e3c45fbc9e8eccf539e532273a46;hp=109a5d30b9a5828535bd7801ecba0c6ab18fe0f8;hb=caf0ab1de11a5cafc878e424ef0d55dbc0350dd1;hpb=b9e5b87917de3103070aab7f0dedb7ffd4574c33 diff --git a/class/deliver/Deliver_SendMail.class.php b/class/deliver/Deliver_SendMail.class.php index 109a5d30..06747541 100644 --- a/class/deliver/Deliver_SendMail.class.php +++ b/class/deliver/Deliver_SendMail.class.php @@ -1,41 +1,92 @@ sendmail_args = $params['sendmail_args']; + } + } + } + + /** + * Constructor (PHP4 style, kept for compatibility reasons) + * @param array configuration options. array key = option name, + * array value = option value. + * @return void + * @since 1.5.1 + */ + function Deliver_SendMail($params=array()) { + self::__construct($params); + } /** * function preWriteToStream * * Sendmail needs LF's as line endings instead of CRLF. * This function translates the line endings to LF and should be called - * before each line is written to the stream. - * + * before each line is written to the stream. + * * @param string $s Line to process * @return void * @access private - */ + */ function preWriteToStream(&$s) { if ($s) { - $s = str_replace("\r\n", "\n", $s); + $s = str_replace("\r\n", "\n", $s); } } @@ -43,63 +94,70 @@ class Deliver_SendMail extends Deliver { * function initStream * * Initialise the sendmail connection. - * + * * @param Message $message Message object containing the from address * @param string $sendmail_path Location of sendmail binary - * @return void - * @access public - */ - function initStream($message, $sendmail_path) { + * @param mixed $ignore_x Eight extra arguments that the parent class + * requires which are not used here + * @return resource + * @access public + */ + function initStream($message, $sendmail_path, $ignore_1=0, $ignore_2='', $ignore_3='', $ignore_4='', $ignore_5='', $ignore_6=false, $ignore_7='', $ignore_8=array()) { $rfc822_header = $message->rfc822_header; - $from = $rfc822_header->from[0]; - $envelopefrom = trim($from->mailbox.'@'.$from->host); - $envelopefrom = str_replace(array("\0","\n"),array('',''),$envelopefrom); - if (strstr($sendmail_path, "qmail-inject")) { - $stream = popen (escapeshellcmd("$sendmail_path -f$envelopefrom"), "w"); - } else { - $stream = popen (escapeshellcmd("$sendmail_path -i -t -f$envelopefrom"), "w"); - } - return $stream; + $from = $rfc822_header->from[0]; + $envelopefrom = trim($from->mailbox.'@'.$from->host); + // save executed command for future reference + $this->sendmail_command = escapeshellcmd("$sendmail_path $this->sendmail_args -f") . escapeshellarg($envelopefrom); + // open process handle for writing + $stream = popen($this->sendmail_command, "w"); + return $stream; } /** - * function finalizeStream + * Closes process handle. * - * Close the stream. - * * @param resource $stream * @return boolean * @access public - */ + */ function finalizeStream($stream) { - pclose($stream); - return true; + $ret = true; + $status = pclose($stream); + // check pclose() status. + if ($status!=0) { + $ret = false; + $this->dlv_msg=_("Email delivery error"); + $this->dlv_ret_nr=$status; + // we can get better error messsage only if we switch to php 4.3+ and proc_open(). + $this->dlv_server_msg=sprintf(_("Can't execute command '%s'."),$this->sendmail_command); + } + return $ret; } /** * function getBcc * * In case of sendmail, the rfc822header must contain the bcc header. - * + * * @return boolean true if rfc822header should include the bcc header. * @access private */ function getBcc() { return true; } - + /** * function clean_crlf * * Cleans each line to only end in a LF - * Returns the length of the line including a CR, + * Returns the length of the line including a CR, * so that length is correct when the message is saved to imap - * Implemented to fix sendmail->postfix rejection of messages with + * Implemented to fix sendmail->postfix rejection of messages with * attachments because of stray LF's * - * @param string $s string to strip of CR's + * @param string $s string to strip of CR's * @return integer length of string including a CR for each LF - * @access private + * @access private */ function clean_crlf(&$s) { $s = str_replace("\r\n", "\n", $s); @@ -107,7 +165,6 @@ class Deliver_SendMail extends Deliver { $s2 = str_replace("\n", "\r\n", $s); return strlen($s2); } - + } -?>