‪TYPO3CMS  10.4
MboxTransport.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
16 namespace ‪TYPO3\CMS\Core\Mail;
17 
18 use Psr\Log\LoggerInterface;
19 use Symfony\Component\Mailer\SentMessage;
20 use Symfony\Component\Mailer\Transport\AbstractTransport;
21 use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
24 
28 class ‪MboxTransport extends AbstractTransport
29 {
33  private ‪$mboxFile;
34 
40  protected ‪$logger;
41 
49  public function ‪__construct(
50  string ‪$mboxFile,
51  EventDispatcherInterface $dispatcher = null,
52  LoggerInterface ‪$logger = null
53  ) {
54  parent::__construct($dispatcher, ‪$logger);
55 
56  $this->mboxFile = ‪$mboxFile;
57  $this->logger = ‪$logger;
58 
59  $this->setMaxPerSecond(0);
60  }
61 
70  protected function ‪doSend(SentMessage $message): void
71  {
72  // Add the complete mail inclusive headers
73  $lockFactory = GeneralUtility::makeInstance(LockFactory::class);
74  $lockObject = $lockFactory->createLocker('mbox');
75  $lockObject->acquire();
76  // Write the mbox file
77  $file = @fopen($this->mboxFile, 'a');
78  if (!$file) {
79  $lockObject->release();
80  throw new \RuntimeException(sprintf('Could not write to file "%s" when sending an email to debug transport', $this->mboxFile), 1291064151);
81  }
82  @fwrite($file, $message->toString());
83  @fclose($file);
84  ‪GeneralUtility::fixPermissions($this->mboxFile);
85  $lockObject->release();
86  }
87 
88  public function ‪__toString(): string
89  {
90  return ‪$this->mboxFile;
91  }
92 }
‪TYPO3\CMS\Core\Mail\MboxTransport\doSend
‪doSend(SentMessage $message)
Definition: MboxTransport.php:68
‪TYPO3\CMS\Core\Mail\MboxTransport\__construct
‪__construct(string $mboxFile, EventDispatcherInterface $dispatcher=null, LoggerInterface $logger=null)
Definition: MboxTransport.php:47
‪TYPO3\CMS\Core\Mail\MboxTransport
Definition: MboxTransport.php:29
‪TYPO3\CMS\Core\Utility\GeneralUtility\fixPermissions
‪static mixed fixPermissions($path, $recursive=false)
Definition: GeneralUtility.php:1863
‪TYPO3\CMS\Core\Mail\MboxTransport\$logger
‪LoggerInterface $logger
Definition: MboxTransport.php:38
‪TYPO3\CMS\Core\Mail\MboxTransport\$mboxFile
‪string $mboxFile
Definition: MboxTransport.php:32
‪TYPO3\CMS\Core\Locking\LockFactory
Definition: LockFactory.php:25
‪TYPO3\CMS\Core\Mail\MboxTransport\__toString
‪__toString()
Definition: MboxTransport.php:86
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Mail
Definition: DelayedTransportInterface.php:18