3 * Deliver_SendMail.class.php
5 * @copyright Copyright (c) 1999-2005 The SquirrelMail Project Team
6 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 * Delivery backend for the Deliver class.
11 * @author Marc Groot Koerkamp
12 * @package squirrelmail
16 /** This of course depends upon Deliver */
17 require_once(SM_PATH
. 'class/deliver/Deliver.class.php');
20 * Delivers messages using the sendmail binary
21 * @package squirrelmail
23 class Deliver_SendMail
extends Deliver
{
26 * function preWriteToStream
28 * Sendmail needs LF's as line endings instead of CRLF.
29 * This function translates the line endings to LF and should be called
30 * before each line is written to the stream.
32 * @param string $s Line to process
36 function preWriteToStream(&$s) {
38 $s = str_replace("\r\n", "\n", $s);
45 * Initialise the sendmail connection.
47 * @param Message $message Message object containing the from address
48 * @param string $sendmail_path Location of sendmail binary
52 function initStream($message, $sendmail_path) {
53 $rfc822_header = $message->rfc822_header
;
54 $from = $rfc822_header->from
[0];
55 $envelopefrom = trim($from->mailbox
.'@'.$from->host
);
56 $envelopefrom = str_replace(array("\0","\n"),array('',''),$envelopefrom);
57 if (strstr($sendmail_path, "qmail-inject")) {
58 $stream = popen (escapeshellcmd("$sendmail_path -f$envelopefrom"), "w");
60 $stream = popen (escapeshellcmd("$sendmail_path -i -t -f$envelopefrom"), "w");
66 * function finalizeStream
70 * @param resource $stream
74 function finalizeStream($stream) {
82 * In case of sendmail, the rfc822header must contain the bcc header.
84 * @return boolean true if rfc822header should include the bcc header.
94 * Cleans each line to only end in a LF
95 * Returns the length of the line including a CR,
96 * so that length is correct when the message is saved to imap
97 * Implemented to fix sendmail->postfix rejection of messages with
98 * attachments because of stray LF's
100 * @param string $s string to strip of CR's
101 * @return integer length of string including a CR for each LF
104 function clean_crlf(&$s) {
105 $s = str_replace("\r\n", "\n", $s);
106 $s = str_replace("\r", "\n", $s);
107 $s2 = str_replace("\n", "\r\n", $s);