a9f44a8d2358e376dece257fe591db809268b0ec
[squirrelmail.git] / class / deliver / Deliver_SendMail.class.php
1 <?php
2 /**
3 * Deliver_SendMail.class.php
4 *
5 * @copyright Copyright (c) 1999-2004 The SquirrelMail Project Team
6 * Licensed under the GNU GPL. For full terms see the file COPYING.
7 *
8 * Delivery backend for the Deliver class.
9 *
10 * $Id$
11 *
12 * @author Marc Groot Koerkamp
13 *
14 * @package squirrelmail
15 */
16
17 require_once(SM_PATH . 'class/deliver/Deliver.class.php');
18
19
20 class Deliver_SendMail extends Deliver {
21
22 /**
23 * function preWriteToStream
24 *
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.
28 *
29 * @param string $s Line to process
30 * @return void
31 * @access private
32 */
33 function preWriteToStream(&$s) {
34 if ($s) {
35 $s = str_replace("\r\n", "\n", $s);
36 }
37 }
38
39 /**
40 * function initStream
41 *
42 * Initialise the sendmail connection.
43 *
44 * @param Message $message Message object containing the from address
45 * @param string $sendmail_path Location of sendmail binary
46 * @return void
47 * @access public
48 */
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");
56 } else {
57 $stream = popen (escapeshellcmd("$sendmail_path -i -t -f$envelopefrom"), "w");
58 }
59 return $stream;
60 }
61
62 /**
63 * function finalizeStream
64 *
65 * Close the stream.
66 *
67 * @param resource $stream
68 * @return boolean
69 * @access public
70 */
71 function finalizeStream($stream) {
72 pclose($stream);
73 return true;
74 }
75
76 /**
77 * function getBcc
78 *
79 * In case of sendmail, the rfc822header must contain the bcc header.
80 *
81 * @return boolean true if rfc822header should include the bcc header.
82 * @access private
83 */
84 function getBcc() {
85 return true;
86 }
87
88 /**
89 * function clean_crlf
90 *
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
96 *
97 * @param string $s string to strip of CR's
98 * @return integer length of string including a CR for each LF
99 * @access private
100 */
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);
105 return strlen($s2);
106 }
107
108
109 }
110 ?>