[BUGFIX] Fix several typos in php comments
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Mail / MboxTransport.php
1 <?php
2 namespace TYPO3\CMS\Core\Mail;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use Symfony\Component\Mailer\SentMessage;
18 use Symfony\Component\Mailer\Transport\AbstractTransport;
19 use TYPO3\CMS\Core\Locking\LockFactory;
20 use TYPO3\CMS\Core\Utility\GeneralUtility;
21
22 /**
23 * Additional Mbox Transport option
24 */
25 class MboxTransport extends AbstractTransport
26 {
27 /**
28 * @var string The file to write our mails into
29 */
30 private $mboxFile;
31
32 /**
33 * Create a new MailTransport
34 *
35 * @param string $mboxFile
36 */
37 public function __construct($mboxFile)
38 {
39 parent::__construct();
40 $this->mboxFile = $mboxFile;
41 $this->setMaxPerSecond(0);
42 }
43
44 /**
45 * Outputs the mail to a text file according to RFC 4155.
46 *
47 * @param SentMessage $message
48 * @throws \TYPO3\CMS\Core\Locking\Exception\LockAcquireException
49 * @throws \TYPO3\CMS\Core\Locking\Exception\LockAcquireWouldBlockException
50 * @throws \TYPO3\CMS\Core\Locking\Exception\LockCreateException
51 */
52 protected function doSend(SentMessage $message): void
53 {
54 // Add the complete mail inclusive headers
55 $lockFactory = GeneralUtility::makeInstance(LockFactory::class);
56 $lockObject = $lockFactory->createLocker('mbox');
57 $lockObject->acquire();
58 // Write the mbox file
59 $file = @fopen($this->mboxFile, 'a');
60 if (!$file) {
61 $lockObject->release();
62 throw new \RuntimeException(sprintf('Could not write to file "%s" when sending an email to debug transport', $this->mboxFile), 1291064151);
63 }
64 @fwrite($file, $message->toString());
65 @fclose($file);
66 GeneralUtility::fixPermissions($this->mboxFile);
67 $lockObject->release();
68 }
69 }