common functions are documented only in one backend
[squirrelmail.git] / class / deliver / Deliver_SendMail.class.php
... / ...
CommitLineData
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
18/** This of course depends upon Deliver */
19require_once(SM_PATH . 'class/deliver/Deliver.class.php');
20
21/**
22 * Delivers messages using the sendmail binary
23 */
24
25class Deliver_SendMail extends Deliver {
26
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 */
38 function preWriteToStream(&$s) {
39 if ($s) {
40 $s = str_replace("\r\n", "\n", $s);
41 }
42 }
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 */
54 function initStream($message, $sendmail_path) {
55 $rfc822_header = $message->rfc822_header;
56 $from = $rfc822_header->from[0];
57 $envelopefrom = trim($from->mailbox.'@'.$from->host);
58 $envelopefrom = str_replace(array("\0","\n"),array('',''),$envelopefrom);
59 if (strstr($sendmail_path, "qmail-inject")) {
60 $stream = popen (escapeshellcmd("$sendmail_path -i -f$envelopefrom"), "w");
61 } else {
62 $stream = popen (escapeshellcmd("$sendmail_path -i -t -f$envelopefrom"), "w");
63 }
64 return $stream;
65 }
66
67 /**
68 * function finalizeStream
69 *
70 * Close the stream.
71 *
72 * @param resource $stream
73 * @return boolean
74 * @access public
75 */
76 function finalizeStream($stream) {
77 pclose($stream);
78 return true;
79 }
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 */
89 function getBcc() {
90 return true;
91 }
92
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
99 * Implemented to fix sendmail->postfix rejection of messages with
100 * attachments because of stray LF's
101 *
102 * @param string $s string to strip of CR's
103 * @return integer length of string including a CR for each LF
104 * @access private
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 }
112
113
114}
115?>