-implented function clean_crlf
[squirrelmail.git] / class / deliver / Deliver_SendMail.class.php
CommitLineData
e1ee60fe 1<?php
5b8fd093 2/**
3 * Deliver_SendMail.class.php
4 *
82d304a0 5 * 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$
2b646597 11 * @package squirrelmail
5b8fd093 12 */
e1ee60fe 13
2b646597 14/** This of course depends upon Deliver */
0f85ddf9 15require_once(SM_PATH . 'class/deliver/Deliver.class.php');
e1ee60fe 16
2b646597 17/**
18 * Delivers messages using the sendmail binary
19 * @package squirrelmail
20 */
e1ee60fe 21class Deliver_SendMail extends Deliver {
22
11a01a02 23 function preWriteToStream(&$s) {
24 if ($s) {
4d3b30dc 25 $s = str_replace("\r\n", "\n", $s);
11a01a02 26 }
27 }
28
29 function initStream($message, $sendmail_path) {
30 $rfc822_header = $message->rfc822_header;
31 $from = $rfc822_header->from[0];
44cdf261 32 $envelopefrom = trim($from->mailbox.'@'.$from->host);
1f9c969d 33 $envelopefrom = str_replace(array("\0","\n"),array('',''),$envelopefrom);
11a01a02 34 if (strstr($sendmail_path, "qmail-inject")) {
4d3b30dc 35 $stream = popen (escapeshellcmd("$sendmail_path -i -f$envelopefrom"), "w");
11a01a02 36 } else {
4d3b30dc 37 $stream = popen (escapeshellcmd("$sendmail_path -i -t -f$envelopefrom"), "w");
11a01a02 38 }
fb762331 39 return $stream;
11a01a02 40 }
41
42 function finalizeStream($stream) {
43 pclose($stream);
d9f49968 44 return true;
11a01a02 45 }
93bbf72b 46
47 function getBcc() {
48 return true;
49 }
88e471ad 50
51 /**
52 * function clean_crlf
53 *
54 * Cleans each line to only end in a LF
55 * Returns the length of the line including a CR,
56 * so that length is correct when the message is saved to imap
57 * Implemented to fix sendmail->postfix rejection of messages with attachments because of stray LF's
58 *
59 * @param string $s string to strip of CR's
60 * @return integer length of string including a CR for each LF
61 */
62 function clean_crlf(&$s) {
63 $s = str_replace("\r\n", "\n", $s);
64 $s = str_replace("\r", "\n", $s);
65 $s2 = str_replace("\n", "\r\n", $s);
66 return strlen($s2);
67 }
93bbf72b 68
e1ee60fe 69}
70?>