Phpdocumentor update - sed is your friend for these kinds of things ;)
[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
e1ee60fe 17
e7be6ad7 18/** This of course depends upon Deliver */
19require_once(SM_PATH . 'class/deliver/Deliver.class.php');
20
21/**
80f3e5c0 22 * Delivers messages using the sendmail binary
23 * @package squirrelmail
e7be6ad7 24 */
e1ee60fe 25class Deliver_SendMail extends Deliver {
26
3aa9dc23 27 /**
28 * function preWriteToStream
29 *
30 * Sendmail needs LF's as line endings instead of CRLF.
31 * This function translates the line endings to LF and should be called
32 * before each line is written to the stream.
33 *
34 * @param string $s Line to process
35 * @return void
36 * @access private
37 */
11a01a02 38 function preWriteToStream(&$s) {
39 if ($s) {
4d3b30dc 40 $s = str_replace("\r\n", "\n", $s);
11a01a02 41 }
42 }
3aa9dc23 43
44 /**
45 * function initStream
46 *
47 * Initialise the sendmail connection.
48 *
49 * @param Message $message Message object containing the from address
50 * @param string $sendmail_path Location of sendmail binary
51 * @return void
52 * @access public
53 */
11a01a02 54 function initStream($message, $sendmail_path) {
55 $rfc822_header = $message->rfc822_header;
56 $from = $rfc822_header->from[0];
44cdf261 57 $envelopefrom = trim($from->mailbox.'@'.$from->host);
3aa9dc23 58 $envelopefrom = str_replace(array("\0","\n"),array('',''),$envelopefrom);
11a01a02 59 if (strstr($sendmail_path, "qmail-inject")) {
4d3b30dc 60 $stream = popen (escapeshellcmd("$sendmail_path -i -f$envelopefrom"), "w");
11a01a02 61 } else {
4d3b30dc 62 $stream = popen (escapeshellcmd("$sendmail_path -i -t -f$envelopefrom"), "w");
11a01a02 63 }
fb762331 64 return $stream;
11a01a02 65 }
3aa9dc23 66
67 /**
68 * function finalizeStream
69 *
70 * Close the stream.
71 *
72 * @param resource $stream
73 * @return boolean
74 * @access public
75 */
11a01a02 76 function finalizeStream($stream) {
77 pclose($stream);
d9f49968 78 return true;
11a01a02 79 }
3aa9dc23 80
81 /**
82 * function getBcc
83 *
84 * In case of sendmail, the rfc822header must contain the bcc header.
85 *
86 * @return boolean true if rfc822header should include the bcc header.
87 * @access private
88 */
93bbf72b 89 function getBcc() {
90 return true;
91 }
3aa9dc23 92
88e471ad 93 /**
94 * function clean_crlf
95 *
96 * Cleans each line to only end in a LF
97 * Returns the length of the line including a CR,
98 * so that length is correct when the message is saved to imap
3aa9dc23 99 * Implemented to fix sendmail->postfix rejection of messages with
100 * attachments because of stray LF's
88e471ad 101 *
102 * @param string $s string to strip of CR's
3aa9dc23 103 * @return integer length of string including a CR for each LF
104 * @access private
88e471ad 105 */
106 function clean_crlf(&$s) {
107 $s = str_replace("\r\n", "\n", $s);
108 $s = str_replace("\r", "\n", $s);
109 $s2 = str_replace("\n", "\r\n", $s);
110 return strlen($s2);
111 }
93bbf72b 112
3aa9dc23 113
e1ee60fe 114}
115?>