Add EmailLogListPage
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / data / email / log / entry / EmailLogEntry.class.php
CommitLineData
1483324c
TD
1<?php
2
3namespace wcf\data\email\log\entry;
4
5use wcf\data\DatabaseObject;
5d8313ec
TD
6use wcf\data\user\User;
7use wcf\system\cache\runtime\UserRuntimeCache;
8use wcf\system\email\Email;
1483324c
TD
9
10/**
11 * Represents an email log entry.
12 *
13 * @author Tim Duesterhus
14 * @copyright 2001-2021 WoltLab GmbH
15 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
16 * @package WoltLabSuite\Core\Data\Email\Log\Entry
17 *
18 * @property-read int $entryID unique id of the log entry
19 * @property-read int $time timestamp when the delivery job was created
20 * @property-read string $messageID the email's 'Message-ID'
21 * @property-read string $recipient the recipient ("RCPT TO")
22 * @property-read ?int $recipientID the recipient's userID (if the email is being sent to a registered user)
23 * @property-read string $status one of the `STATUS_*` constants
24 * @property-read string $message a human readable explanation for the status
25 *
26 */
27class EmailLogEntry extends DatabaseObject
28{
29 public const STATUS_NEW = 'new';
30
31 public const STATUS_SUCCESS = 'success';
32
33 public const STATUS_TRANSIENT_FAILURE = 'transient_failure';
34
35 public const STATUS_PERMANENT_FAILURE = 'permanent_failure';
5d8313ec
TD
36
37 /**
38 * Returns the formatted 'Message-ID', stripping useless information.
39 */
40 public function getFormattedMessageId(): string
41 {
42 return \preg_replace_callback(
43 '/^\<((.*)@(.*))\>$/',
44 static function ($matches) {
45 if ($matches[3] === Email::getHost()) {
46 return $matches[2] . '@';
47 } else {
48 return $matches[1];
49 }
50 },
51 $this->messageID
52 );
53 }
54
55 /**
56 * Returns the recipient.
57 *
58 * @see EmailLogEntry::$recipient
59 */
60 public function getRecipient(): ?User
61 {
62 if (!$this->recipientID) {
63 return null;
64 }
65
66 return UserRuntimeCache::getInstance()->getObject($this->recipientID);
67 }
68
69 /**
70 * Returns the redacted recipient address.
71 */
72 public function getRedactedRecipientAddress(): string
73 {
74 $atSign = \strrpos($this->recipient, '@');
75 $localpart = \substr($this->recipient, 0, $atSign);
76 $domain = \substr($this->recipient, $atSign + 1);
77
78 return \substr($localpart, 0, 1) . "\u{2022}\u{2022}\u{2022}\u{2022}@{$domain}";
79 }
1483324c 80}