Documentation.
[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 *
10 * $Id$
3aa9dc23 11 *
12 * @author Marc Groot Koerkamp
13 *
2b646597 14 * @package squirrelmail
5b8fd093 15 */
e1ee60fe 16
0f85ddf9 17require_once(SM_PATH . 'class/deliver/Deliver.class.php');
e1ee60fe 18
3aa9dc23 19
e1ee60fe 20class Deliver_SendMail extends Deliver {
21
3aa9dc23 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 */
11a01a02 33 function preWriteToStream(&$s) {
34 if ($s) {
4d3b30dc 35 $s = str_replace("\r\n", "\n", $s);
11a01a02 36 }
37 }
3aa9dc23 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 */
11a01a02 49 function initStream($message, $sendmail_path) {
50 $rfc822_header = $message->rfc822_header;
51 $from = $rfc822_header->from[0];
44cdf261 52 $envelopefrom = trim($from->mailbox.'@'.$from->host);
3aa9dc23 53 $envelopefrom = str_replace(array("\0","\n"),array('',''),$envelopefrom);
11a01a02 54 if (strstr($sendmail_path, "qmail-inject")) {
4d3b30dc 55 $stream = popen (escapeshellcmd("$sendmail_path -i -f$envelopefrom"), "w");
11a01a02 56 } else {
4d3b30dc 57 $stream = popen (escapeshellcmd("$sendmail_path -i -t -f$envelopefrom"), "w");
11a01a02 58 }
fb762331 59 return $stream;
11a01a02 60 }
3aa9dc23 61
62 /**
63 * function finalizeStream
64 *
65 * Close the stream.
66 *
67 * @param resource $stream
68 * @return boolean
69 * @access public
70 */
11a01a02 71 function finalizeStream($stream) {
72 pclose($stream);
d9f49968 73 return true;
11a01a02 74 }
3aa9dc23 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 */
93bbf72b 84 function getBcc() {
85 return true;
86 }
3aa9dc23 87
88e471ad 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
3aa9dc23 94 * Implemented to fix sendmail->postfix rejection of messages with
95 * attachments because of stray LF's
88e471ad 96 *
97 * @param string $s string to strip of CR's
3aa9dc23 98 * @return integer length of string including a CR for each LF
99 * @access private
88e471ad 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 }
93bbf72b 107
3aa9dc23 108
e1ee60fe 109}
110?>