TYPO3  7.6
Transport/SendmailTransport.php
Go to the documentation of this file.
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 
21 {
27  private $_params = array(
28  'timeout' => 30,
29  'blocking' => 1,
30  'command' => '/usr/sbin/sendmail -bs',
32  );
33 
41  {
42  parent::__construct($buf, $dispatcher);
43  }
44 
48  public function start()
49  {
50  if (false !== strpos($this->getCommand(), ' -bs')) {
51  parent::start();
52  }
53  }
54 
69  public function setCommand($command)
70  {
71  $this->_params['command'] = $command;
72 
73  return $this;
74  }
75 
81  public function getCommand()
82  {
83  return $this->_params['command'];
84  }
85 
100  public function send(Swift_Mime_Message $message, &$failedRecipients = null)
101  {
102  $failedRecipients = (array) $failedRecipients;
103  $command = $this->getCommand();
104  $buffer = $this->getBuffer();
105 
106  if (false !== strpos($command, ' -t')) {
107  if ($evt = $this->_eventDispatcher->createSendEvent($this, $message)) {
108  $this->_eventDispatcher->dispatchEvent($evt, 'beforeSendPerformed');
109  if ($evt->bubbleCancelled()) {
110  return 0;
111  }
112  }
113 
114  if (false === strpos($command, ' -f')) {
115  $command .= ' -f'.escapeshellarg($this->_getReversePath($message));
116  }
117 
118  $buffer->initialize(array_merge($this->_params, array('command' => $command)));
119 
120  if (false === strpos($command, ' -i') && false === strpos($command, ' -oi')) {
121  $buffer->setWriteTranslations(array("\r\n" => "\n", "\n." => "\n.."));
122  } else {
123  $buffer->setWriteTranslations(array("\r\n" => "\n"));
124  }
125 
126  $count = count((array) $message->getTo())
127  + count((array) $message->getCc())
128  + count((array) $message->getBcc())
129  ;
130  $message->toByteStream($buffer);
131  $buffer->flushBuffers();
132  $buffer->setWriteTranslations(array());
133  $buffer->terminate();
134 
135  if ($evt) {
137  $evt->setFailedRecipients($failedRecipients);
138  $this->_eventDispatcher->dispatchEvent($evt, 'sendPerformed');
139  }
140 
141  $message->generateId();
142  } elseif (false !== strpos($command, ' -bs')) {
143  $count = parent::send($message, $failedRecipients);
144  } else {
146  'Unsupported sendmail command flags ['.$command.']. '.
147  'Must be one of "-bs" or "-t" but can include additional flags.'
148  ));
149  }
150 
151  return $count;
152  }
153 
155  protected function _getBufferParams()
156  {
157  return $this->_params;
158  }
159 }