TYPO3 CMS  TYPO3_6-2
MboxTransport.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Core\Mail;
3 
24 class MboxTransport implements \Swift_Transport {
25 
29  private $debugFile;
30 
36  public function __construct($debugFile) {
37  $this->debugFile = $debugFile;
38  }
39 
43  public function isStarted() {
44  return FALSE;
45  }
46 
50  public function start() {
51 
52  }
53 
57  public function stop() {
58 
59  }
60 
69  public function send(\Swift_Mime_Message $message, &$failedRecipients = NULL) {
70  $message->generateId();
71  // Create a mbox-like header
72  $mboxFrom = $this->getReversePath($message);
73  $mboxDate = strftime('%c', $message->getDate());
74  $messageStr = sprintf('From %s %s', $mboxFrom, $mboxDate) . LF;
75  // Add the complete mail inclusive headers
76  $messageStr .= $message->toString();
77  $messageStr .= LF . LF;
78  $lockObject = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Locking\\Locker', $this->debugFile);
80  $lockObject->acquireExclusiveLock();
81  // Write the mbox file
82  $file = @fopen($this->debugFile, 'a');
83  if (!$file) {
84  $lockObject->release();
85  throw new \RuntimeException(sprintf('Could not write to file "%s" when sending an email to debug transport', $this->debugFile), 1291064151);
86  }
87  @fwrite($file, $messageStr);
88  @fclose($file);
90  $lockObject->release();
91  // Return every receipient as "delivered"
92  $count = count((array) $message->getTo()) + count((array) $message->getCc()) + count((array) $message->getBcc());
93  return $count;
94  }
95 
102  private function getReversePath(\Swift_Mime_Message $message) {
103  $return = $message->getReturnPath();
104  $sender = $message->getSender();
105  $from = $message->getFrom();
106  $path = NULL;
107  if (!empty($return)) {
108  $path = $return;
109  } elseif (!empty($sender)) {
110  $keys = array_keys($sender);
111  $path = array_shift($keys);
112  } elseif (!empty($from)) {
113  $keys = array_keys($from);
114  $path = array_shift($keys);
115  }
116  return $path;
117  }
118 
125  public function registerPlugin(\Swift_Events_EventListener $plugin) {
126  return TRUE;
127  }
128 
129 }
registerPlugin(\Swift_Events_EventListener $plugin)
static fixPermissions($path, $recursive=FALSE)
getReversePath(\Swift_Mime_Message $message)