if we can't open stream. we make up server's error message
[squirrelmail.git] / class / deliver / Deliver_SendMail.class.php
CommitLineData
e1ee60fe 1<?php
4b4abf93 2
5b8fd093 3/**
4 * Deliver_SendMail.class.php
5 *
5b8fd093 6 * Delivery backend for the Deliver class.
7 *
3aa9dc23 8 * @author Marc Groot Koerkamp
4b4abf93 9 * @copyright &copy; 1999-2005 The SquirrelMail Project Team
10 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
11 * @version $Id$
2b646597 12 * @package squirrelmail
5b8fd093 13 */
e1ee60fe 14
e1ee60fe 15
e7be6ad7 16/** This of course depends upon Deliver */
17require_once(SM_PATH . 'class/deliver/Deliver.class.php');
91e0dccc 18
e7be6ad7 19/**
80f3e5c0 20 * Delivers messages using the sendmail binary
21 * @package squirrelmail
e7be6ad7 22 */
e1ee60fe 23class Deliver_SendMail extends Deliver {
24
3aa9dc23 25 /**
26 * function preWriteToStream
27 *
28 * Sendmail needs LF's as line endings instead of CRLF.
29 * This function translates the line endings to LF and should be called
91e0dccc 30 * before each line is written to the stream.
31 *
3aa9dc23 32 * @param string $s Line to process
33 * @return void
34 * @access private
91e0dccc 35 */
11a01a02 36 function preWriteToStream(&$s) {
37 if ($s) {
91e0dccc 38 $s = str_replace("\r\n", "\n", $s);
11a01a02 39 }
40 }
3aa9dc23 41
42 /**
43 * function initStream
44 *
45 * Initialise the sendmail connection.
91e0dccc 46 *
3aa9dc23 47 * @param Message $message Message object containing the from address
48 * @param string $sendmail_path Location of sendmail binary
49 * @return void
91e0dccc 50 * @access public
51 */
11a01a02 52 function initStream($message, $sendmail_path) {
53 $rfc822_header = $message->rfc822_header;
91e0dccc 54 $from = $rfc822_header->from[0];
55 $envelopefrom = trim($from->mailbox.'@'.$from->host);
3aa9dc23 56 $envelopefrom = str_replace(array("\0","\n"),array('',''),$envelopefrom);
91e0dccc 57 if (strstr($sendmail_path, "qmail-inject")) {
58 $stream = popen (escapeshellcmd("$sendmail_path -f$envelopefrom"), "w");
59 } else {
60 $stream = popen (escapeshellcmd("$sendmail_path -i -t -f$envelopefrom"), "w");
61 }
62 return $stream;
11a01a02 63 }
3aa9dc23 64
65 /**
66 * function finalizeStream
67 *
68 * Close the stream.
91e0dccc 69 *
3aa9dc23 70 * @param resource $stream
71 * @return boolean
72 * @access public
91e0dccc 73 */
11a01a02 74 function finalizeStream($stream) {
91e0dccc 75 pclose($stream);
76 return true;
11a01a02 77 }
3aa9dc23 78
79 /**
80 * function getBcc
81 *
82 * In case of sendmail, the rfc822header must contain the bcc header.
91e0dccc 83 *
3aa9dc23 84 * @return boolean true if rfc822header should include the bcc header.
85 * @access private
86 */
93bbf72b 87 function getBcc() {
88 return true;
89 }
91e0dccc 90
88e471ad 91 /**
92 * function clean_crlf
93 *
94 * Cleans each line to only end in a LF
91e0dccc 95 * Returns the length of the line including a CR,
88e471ad 96 * so that length is correct when the message is saved to imap
91e0dccc 97 * Implemented to fix sendmail->postfix rejection of messages with
3aa9dc23 98 * attachments because of stray LF's
88e471ad 99 *
91e0dccc 100 * @param string $s string to strip of CR's
3aa9dc23 101 * @return integer length of string including a CR for each LF
91e0dccc 102 * @access private
88e471ad 103 */
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);
108 return strlen($s2);
109 }
91e0dccc 110
3aa9dc23 111
e1ee60fe 112}
91e0dccc 113?>