[ Index ] |
MailPress 7.2 |
[ Index ] [ Classes ] [ Functions ] [ Variables ] [ Constants ] [ Statistics ] |
[Summary view] [Print] [Text view]
1 <?php 2 3 /* 4 * This file is part of SwiftMailer. 5 * (c) 2004-2009 Chris Corbyn 6 * 7 * For the full copyright and license information, please view the LICENSE 8 * file that was distributed with this source code. 9 */ 10 11 /** 12 * SendmailTransport for sending mail through a Sendmail/Postfix (etc..) binary. 13 * 14 * Supported modes are -bs and -t, with any additional flags desired. 15 * It is advised to use -bs mode since error reporting with -t mode is not 16 * possible. 17 * 18 * @author Chris Corbyn 19 */ 20 class Swift_Transport_SendmailTransport extends Swift_Transport_AbstractSmtpTransport 21 { 22 /** 23 * Connection buffer parameters. 24 * 25 * @var array 26 */ 27 private $params = [ 28 'timeout' => 30, 29 'blocking' => 1, 30 'command' => '/usr/sbin/sendmail -bs', 31 'type' => Swift_Transport_IoBuffer::TYPE_PROCESS, 32 ]; 33 34 /** 35 * Create a new SendmailTransport with $buf for I/O. 36 * 37 * @param string $localDomain 38 */ 39 public function __construct(Swift_Transport_IoBuffer $buf, Swift_Events_EventDispatcher $dispatcher, $localDomain = '127.0.0.1', Swift_AddressEncoder $addressEncoder = null) 40 { 41 parent::__construct($buf, $dispatcher, $localDomain, $addressEncoder); 42 } 43 44 /** 45 * Start the standalone SMTP session if running in -bs mode. 46 */ 47 public function start() 48 { 49 if (false !== strpos($this->getCommand(), ' -bs')) { 50 parent::start(); 51 } 52 } 53 54 /** 55 * Set the command to invoke. 56 * 57 * If using -t mode you are strongly advised to include -oi or -i in the flags. 58 * For example: /usr/sbin/sendmail -oi -t 59 * Swift will append a -f<sender> flag if one is not present. 60 * 61 * The recommended mode is "-bs" since it is interactive and failure notifications 62 * are hence possible. 63 * 64 * @param string $command 65 * 66 * @return $this 67 */ 68 public function setCommand($command) 69 { 70 $this->params['command'] = $command; 71 72 return $this; 73 } 74 75 /** 76 * Get the sendmail command which will be invoked. 77 * 78 * @return string 79 */ 80 public function getCommand() 81 { 82 return $this->params['command']; 83 } 84 85 /** 86 * Send the given Message. 87 * 88 * Recipient/sender data will be retrieved from the Message API. 89 * 90 * The return value is the number of recipients who were accepted for delivery. 91 * NOTE: If using 'sendmail -t' you will not be aware of any failures until 92 * they bounce (i.e. send() will always return 100% success). 93 * 94 * @param string[] $failedRecipients An array of failures by-reference 95 * 96 * @return int 97 */ 98 public function send(Swift_Mime_SimpleMessage $message, &$failedRecipients = null) 99 { 100 $failedRecipients = (array) $failedRecipients; 101 $command = $this->getCommand(); 102 $buffer = $this->getBuffer(); 103 $count = 0; 104 105 if (false !== strpos($command, ' -t')) { 106 if ($evt = $this->eventDispatcher->createSendEvent($this, $message)) { 107 $this->eventDispatcher->dispatchEvent($evt, 'beforeSendPerformed'); 108 if ($evt->bubbleCancelled()) { 109 return 0; 110 } 111 } 112 113 if (false === strpos($command, ' -f')) { 114 $command .= ' -f'.escapeshellarg($this->getReversePath($message)); 115 } 116 117 $buffer->initialize(array_merge($this->params, ['command' => $command])); 118 119 if (false === strpos($command, ' -i') && false === strpos($command, ' -oi')) { 120 $buffer->setWriteTranslations(["\r\n" => "\n", "\n." => "\n.."]); 121 } else { 122 $buffer->setWriteTranslations(["\r\n" => "\n"]); 123 } 124 125 $count = count((array) $message->getTo()) 126 + count((array) $message->getCc()) 127 + count((array) $message->getBcc()) 128 ; 129 $message->toByteStream($buffer); 130 $buffer->flushBuffers(); 131 $buffer->setWriteTranslations([]); 132 $buffer->terminate(); 133 134 if ($evt) { 135 $evt->setResult(Swift_Events_SendEvent::RESULT_SUCCESS); 136 $evt->setFailedRecipients($failedRecipients); 137 $this->eventDispatcher->dispatchEvent($evt, 'sendPerformed'); 138 } 139 140 $message->generateId(); 141 } elseif (false !== strpos($command, ' -bs')) { 142 $count = parent::send($message, $failedRecipients); 143 } else { 144 $this->throwException(new Swift_TransportException( 145 'Unsupported sendmail command flags ['.$command.']. '. 146 'Must be one of "-bs" or "-t" but can include additional flags.' 147 )); 148 } 149 150 return $count; 151 } 152 153 /** Get the params to initialize the buffer */ 154 protected function getBufferParams() 155 { 156 return $this->params; 157 } 158 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue May 19 15:55:14 2020 | Cross-referenced by PHPXref 0.7.1 |