1: <?php
2:
3: 4: 5: 6: 7: 8: 9:
10:
11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21:
22: class Swift_Transport_SendmailTransport extends Swift_Transport_AbstractSmtpTransport
23: {
24: 25: 26: 27: 28:
29: private $_params = array(
30: 'timeout' => 30,
31: 'blocking' => 1,
32: 'command' => '/usr/sbin/sendmail -bs',
33: 'type' => Swift_Transport_IoBuffer::TYPE_PROCESS
34: );
35:
36: 37: 38: 39: 40:
41: public function __construct(Swift_Transport_IoBuffer $buf, Swift_Events_EventDispatcher $dispatcher)
42: {
43: parent::__construct($buf, $dispatcher);
44: }
45:
46: 47: 48:
49: public function start()
50: {
51: if (false !== strpos($this->getCommand(), ' -bs')) {
52: parent::start();
53: }
54: }
55:
56: 57: 58: 59: 60: 61: 62: 63: 64: 65:
66: public function setCommand($command)
67: {
68: $this->_params['command'] = $command;
69:
70: return $this;
71: }
72:
73: 74: 75: 76:
77: public function getCommand()
78: {
79: return $this->_params['command'];
80: }
81:
82: 83: 84: 85: 86: 87: 88: 89: 90: 91:
92: public function send(Swift_Mime_Message $message, &$failedRecipients = null)
93: {
94: $failedRecipients = (array) $failedRecipients;
95: $command = $this->getCommand();
96: $buffer = $this->getBuffer();
97:
98: if (false !== strpos($command, ' -t')) {
99: if ($evt = $this->_eventDispatcher->createSendEvent($this, $message)) {
100: $this->_eventDispatcher->dispatchEvent($evt, 'beforeSendPerformed');
101: if ($evt->bubbleCancelled()) {
102: return 0;
103: }
104: }
105:
106: if (false === strpos($command, ' -f')) {
107: $command .= ' -f' . $this->_getReversePath($message);
108: }
109:
110: $buffer->initialize(array_merge($this->_params, array('command' => $command)));
111:
112: if (false === strpos($command, ' -i') && false === strpos($command, ' -oi')) {
113: $buffer->setWriteTranslations(array("\r\n" => "\n", "\n." => "\n.."));
114: } else {
115: $buffer->setWriteTranslations(array("\r\n"=>"\n"));
116: }
117:
118: $count = count((array) $message->getTo())
119: + count((array) $message->getCc())
120: + count((array) $message->getBcc())
121: ;
122: $message->toByteStream($buffer);
123: $buffer->flushBuffers();
124: $buffer->setWriteTranslations(array());
125: $buffer->terminate();
126:
127: if ($evt) {
128: $evt->setResult(Swift_Events_SendEvent::RESULT_SUCCESS);
129: $evt->setFailedRecipients($failedRecipients);
130: $this->_eventDispatcher->dispatchEvent($evt, 'sendPerformed');
131: }
132:
133: $message->generateId();
134: } elseif (false !== strpos($command, ' -bs')) {
135: $count = parent::send($message, $failedRecipients);
136: } else {
137: $this->_throwException(new Swift_TransportException(
138: 'Unsupported sendmail command flags [' . $command . ']. ' .
139: 'Must be one of "-bs" or "-t" but can include additional flags.'
140: ));
141: }
142:
143: return $count;
144: }
145:
146:
147:
148:
149: protected function _getBufferParams()
150: {
151: return $this->_params;
152: }
153: }
154: