XOOPS RMCommon Utilities  2.1.8.91RC
 All Classes Namespaces Files Functions Variables
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 
11 //@require 'Swift/Transport/EsmtpTransport.php';
12 //@require 'Swift/Transport/IoBuffer.php';
13 //@require 'Swift/Transport/Log.php';
14 //@require 'Swift/Events/EventDispatcher.php';
15 
29 {
30 
36  private $_params = array(
37  'timeout' => 30,
38  'blocking' => 1,
39  'command' => '/usr/sbin/sendmail -bs',
41  );
42 
48  public function __construct(Swift_Transport_IoBuffer $buf,
49  Swift_Events_EventDispatcher $dispatcher)
50  {
51  parent::__construct($buf, $dispatcher);
52  }
53 
57  public function start()
58  {
59  if (false !== strpos($this->getCommand(), ' -bs'))
60  {
61  parent::start();
62  }
63  }
64 
74  public function setCommand($command)
75  {
76  $this->_params['command'] = $command;
77  return $this;
78  }
79 
84  public function getCommand()
85  {
86  return $this->_params['command'];
87  }
88 
99  public function send(Swift_Mime_Message $message, &$failedRecipients = null)
100  {
101  $failedRecipients = (array) $failedRecipients;
102  $command = $this->getCommand();
103  $buffer = $this->getBuffer();
104 
105  if (false !== strpos($command, ' -t'))
106  {
107  if ($evt = $this->_eventDispatcher->createSendEvent($this, $message))
108  {
109  $this->_eventDispatcher->dispatchEvent($evt, 'beforeSendPerformed');
110  if ($evt->bubbleCancelled())
111  {
112  return 0;
113  }
114  }
115 
116  if (false === strpos($command, ' -f'))
117  {
118  $command .= ' -f' . $this->_getReversePath($message);
119  }
120 
121  $buffer->initialize(array_merge($this->_params, array('command' => $command)));
122 
123  if (false === strpos($command, ' -i') && false === strpos($command, ' -oi'))
124  {
125  $buffer->setWriteTranslations(array("\r\n" => "\n", "\n." => "\n.."));
126  }
127  else
128  {
129  $buffer->setWriteTranslations(array("\r\n"=>"\n"));
130  }
131 
132  $count = count((array) $message->getTo())
133  + count((array) $message->getCc())
134  + count((array) $message->getBcc())
135  ;
136  $message->toByteStream($buffer);
137  $buffer->flushBuffers();
138  $buffer->setWriteTranslations(array());
139  $buffer->terminate();
140 
141  if ($evt)
142  {
144  $evt->setFailedRecipients($failedRecipients);
145  $this->_eventDispatcher->dispatchEvent($evt, 'sendPerformed');
146  }
147 
148  $message->generateId();
149  }
150  elseif (false !== strpos($command, ' -bs'))
151  {
152  $count = parent::send($message, $failedRecipients);
153  }
154  else
155  {
157  'Unsupported sendmail command flags [' . $command . ']. ' .
158  'Must be one of "-bs" or "-t" but can include additional flags.'
159  ));
160  }
161 
162  return $count;
163  }
164 
165  // -- Protected methods
166 
168  protected function _getBufferParams()
169  {
170  return $this->_params;
171  }
172 
173 }