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