‪TYPO3CMS  ‪main
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;
27 
31 class ‪MboxTransport extends AbstractTransport
32 {
38  public function ‪__construct(
39  private readonly string $mboxFile,
40  ?EventDispatcherInterface $dispatcher = null,
41  protected readonly ?LoggerInterface $logger = null,
42  ) {
43  parent::__construct($dispatcher, $logger);
44  $this->setMaxPerSecond(0);
45  }
46 
54  protected function ‪doSend(SentMessage $message): void
55  {
56  // Add the complete mail inclusive headers
57  $lockFactory = GeneralUtility::makeInstance(LockFactory::class);
58  $lockObject = $lockFactory->createLocker('mbox');
59  $lockObject->acquire();
60  // Write the mbox file
61  $file = @fopen($this->mboxFile, 'a');
62  if (!$file) {
63  $lockObject->release();
64  throw new \RuntimeException(sprintf('Could not write to file "%s" when sending an email to debug transport', $this->mboxFile), 1291064151);
65  }
66  @fwrite($file, $message->toString());
67  @fclose($file);
68  ‪GeneralUtility::fixPermissions($this->mboxFile);
69  $lockObject->release();
70  }
71 
72  public function ‪__toString(): string
73  {
74  return $this->mboxFile;
75  }
76 }
‪TYPO3\CMS\Core\Mail\MboxTransport\doSend
‪doSend(SentMessage $message)
Definition: MboxTransport.php:54
‪TYPO3\CMS\Core\Locking\Exception\LockAcquireWouldBlockException
Definition: LockAcquireWouldBlockException.php:21
‪TYPO3\CMS\Core\Mail\MboxTransport
Definition: MboxTransport.php:32
‪TYPO3\CMS\Core\Mail\MboxTransport\__construct
‪__construct(private readonly string $mboxFile, ?EventDispatcherInterface $dispatcher=null, protected readonly ?LoggerInterface $logger=null,)
Definition: MboxTransport.php:38
‪TYPO3\CMS\Core\Locking\Exception\LockAcquireException
Definition: LockAcquireException.php:23
‪TYPO3\CMS\Core\Locking\Exception\LockCreateException
Definition: LockCreateException.php:23
‪TYPO3\CMS\Core\Utility\GeneralUtility\fixPermissions
‪static bool fixPermissions(string $path, bool $recursive=false)
Definition: GeneralUtility.php:1496
‪TYPO3\CMS\Core\Locking\LockFactory
Definition: LockFactory.php:27
‪TYPO3\CMS\Core\Mail\MboxTransport\__toString
‪__toString()
Definition: MboxTransport.php:72
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Core\Mail
Definition: DelayedTransportInterface.php:18