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