a9f44a8d2358e376dece257fe591db809268b0ec
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
17 require_once(SM_PATH
. 'class/deliver/Deliver.class.php');
20 class Deliver_SendMail
extends Deliver
{
23 * function preWriteToStream
25 * Sendmail needs LF's as line endings instead of CRLF.
26 * This function translates the line endings to LF and should be called
27 * before each line is written to the stream.
29 * @param string $s Line to process
33 function preWriteToStream(&$s) {
35 $s = str_replace("\r\n", "\n", $s);
42 * Initialise the sendmail connection.
44 * @param Message $message Message object containing the from address
45 * @param string $sendmail_path Location of sendmail binary
49 function initStream($message, $sendmail_path) {
50 $rfc822_header = $message->rfc822_header
;
51 $from = $rfc822_header->from
[0];
52 $envelopefrom = trim($from->mailbox
.'@'.$from->host
);
53 $envelopefrom = str_replace(array("\0","\n"),array('',''),$envelopefrom);
54 if (strstr($sendmail_path, "qmail-inject")) {
55 $stream = popen (escapeshellcmd("$sendmail_path -i -f$envelopefrom"), "w");
57 $stream = popen (escapeshellcmd("$sendmail_path -i -t -f$envelopefrom"), "w");
63 * function finalizeStream
67 * @param resource $stream
71 function finalizeStream($stream) {
79 * In case of sendmail, the rfc822header must contain the bcc header.
81 * @return boolean true if rfc822header should include the bcc header.
91 * Cleans each line to only end in a LF
92 * Returns the length of the line including a CR,
93 * so that length is correct when the message is saved to imap
94 * Implemented to fix sendmail->postfix rejection of messages with
95 * attachments because of stray LF's
97 * @param string $s string to strip of CR's
98 * @return integer length of string including a CR for each LF
101 function clean_crlf(&$s) {
102 $s = str_replace("\r\n", "\n", $s);
103 $s = str_replace("\r", "\n", $s);
104 $s2 = str_replace("\n", "\r\n", $s);