adding address book block
[squirrelmail.git] / class / deliver / Deliver_SendMail.class.php
CommitLineData
e1ee60fe 1<?php
5b8fd093 2/**
3 * Deliver_SendMail.class.php
4 *
3aa9dc23 5 * @copyright Copyright (c) 1999-2004 The SquirrelMail Project Team
5b8fd093 6 * Licensed under the GNU GPL. For full terms see the file COPYING.
7 *
8 * Delivery backend for the Deliver class.
9 *
883d9cd3 10 * @version $Id$
3aa9dc23 11 * @author Marc Groot Koerkamp
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');
18
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
30 * before each line is written to the stream.
31 *
32 * @param string $s Line to process
33 * @return void
34 * @access private
35 */
11a01a02 36 function preWriteToStream(&$s) {
37 if ($s) {
4d3b30dc 38 $s = str_replace("\r\n", "\n", $s);
11a01a02 39 }
40 }
3aa9dc23 41
42 /**
43 * function initStream
44 *
45 * Initialise the sendmail connection.
46 *
47 * @param Message $message Message object containing the from address
48 * @param string $sendmail_path Location of sendmail binary
49 * @return void
50 * @access public
51 */
11a01a02 52 function initStream($message, $sendmail_path) {
53 $rfc822_header = $message->rfc822_header;
54 $from = $rfc822_header->from[0];
44cdf261 55 $envelopefrom = trim($from->mailbox.'@'.$from->host);
3aa9dc23 56 $envelopefrom = str_replace(array("\0","\n"),array('',''),$envelopefrom);
11a01a02 57 if (strstr($sendmail_path, "qmail-inject")) {
b9e5b879 58 $stream = popen (escapeshellcmd("$sendmail_path -f$envelopefrom"), "w");
11a01a02 59 } else {
4d3b30dc 60 $stream = popen (escapeshellcmd("$sendmail_path -i -t -f$envelopefrom"), "w");
11a01a02 61 }
fb762331 62 return $stream;
11a01a02 63 }
3aa9dc23 64
65 /**
66 * function finalizeStream
67 *
68 * Close the stream.
69 *
70 * @param resource $stream
71 * @return boolean
72 * @access public
73 */
11a01a02 74 function finalizeStream($stream) {
75 pclose($stream);
d9f49968 76 return true;
11a01a02 77 }
3aa9dc23 78
79 /**
80 * function getBcc
81 *
82 * In case of sendmail, the rfc822header must contain the bcc header.
83 *
84 * @return boolean true if rfc822header should include the bcc header.
85 * @access private
86 */
93bbf72b 87 function getBcc() {
88 return true;
89 }
3aa9dc23 90
88e471ad 91 /**
92 * function clean_crlf
93 *
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
3aa9dc23 97 * Implemented to fix sendmail->postfix rejection of messages with
98 * attachments because of stray LF's
88e471ad 99 *
100 * @param string $s string to strip of CR's
3aa9dc23 101 * @return integer length of string including a CR for each LF
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 }
93bbf72b 110
3aa9dc23 111
e1ee60fe 112}
113?>