Deliver_SendMail.class.php 2.9 KB

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