From 5d8313ecec2213593dcb04ee92fbed4120691dc4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Mon, 15 Feb 2021 14:21:27 +0100 Subject: [PATCH] Add EmailLogListPage --- com.woltlab.wcf/acpMenu.xml | 5 + .../files/acp/templates/emailLogList.tpl | 103 ++++++++++++++++++ .../lib/acp/page/EmailLogListPage.class.php | 66 +++++++++++ .../email/log/entry/EmailLogEntry.class.php | 47 ++++++++ wcfsetup/install/lang/de.xml | 10 ++ wcfsetup/install/lang/en.xml | 10 ++ 6 files changed, 241 insertions(+) create mode 100644 wcfsetup/install/files/acp/templates/emailLogList.tpl create mode 100644 wcfsetup/install/files/lib/acp/page/EmailLogListPage.class.php diff --git a/com.woltlab.wcf/acpMenu.xml b/com.woltlab.wcf/acpMenu.xml index 1781702140..79bccab427 100644 --- a/com.woltlab.wcf/acpMenu.xml +++ b/com.woltlab.wcf/acpMenu.xml @@ -759,6 +759,11 @@ wcf.acp.menu.link.log admin.management.canManageCronjob + + wcf\acp\page\EmailLogListPage + wcf.acp.menu.link.log + admin.management.canViewLog + wcf\acp\page\ExceptionLogViewPage wcf.acp.menu.link.log diff --git a/wcfsetup/install/files/acp/templates/emailLogList.tpl b/wcfsetup/install/files/acp/templates/emailLogList.tpl new file mode 100644 index 0000000000..51cc014cac --- /dev/null +++ b/wcfsetup/install/files/acp/templates/emailLogList.tpl @@ -0,0 +1,103 @@ +{include file='header' pageTitle='wcf.acp.email.log'} + +
+
+

{lang}wcf.acp.email.log{/lang}{if $items} {#$items}{/if}

+
+ + {hascontent} + + {/hascontent} +
+ +{hascontent} +
+ {content}{pages print=true assign=pagesLinks controller="EmailLogList" link="pageNo=%d&sortField=$sortField&sortOrder=$sortOrder"}{/content} +
+{/hascontent} + +{if $objects|count} +
+ + + + + + + + + + {event name='columnHeads'} + + + + + {foreach from=$objects item=entry} + + + + + + + + + {event name='columns'} + + {/foreach} + +
{lang}wcf.global.objectID{/lang}{lang}wcf.acp.email.log.messageID{/lang}{lang}wcf.user.email{/lang}{lang}wcf.acp.email.log.time{/lang}{lang}wcf.acp.email.log.status{/lang}
{@$entry->entryID} + {$entry->getFormattedMessageId()|truncate:50} + + {if $__wcf->session->getPermission('admin.user.canEditMailAddress')} + {$entry->recipient} + {else} + {$entry->getRedactedRecipientAddress()} + {/if} + {if $entry->getRecipient()} + ({$entry->getRecipient()->getTitle()}) + {/if} + {@$entry->time|time} + message} data-dialog-id="statusMessage{$entry->entryID}"{/if}>{lang}wcf.acp.email.log.status.{$entry->status}{/lang} + {if $entry->message} + + {/if} +
+
+ +
+ {hascontent} +
+ {content}{@$pagesLinks}{/content} +
+ {/hascontent} + + {hascontent} + + {/hascontent} +
+{else} +

{lang}wcf.global.noItems{/lang}

+{/if} + +{include file='footer'} diff --git a/wcfsetup/install/files/lib/acp/page/EmailLogListPage.class.php b/wcfsetup/install/files/lib/acp/page/EmailLogListPage.class.php new file mode 100644 index 0000000000..0f710c2f40 --- /dev/null +++ b/wcfsetup/install/files/lib/acp/page/EmailLogListPage.class.php @@ -0,0 +1,66 @@ + + * @package WoltLabSuite\Core\Acp\Page + * + * @property EmailLogEntryList $objectList + */ +class EmailLogListPage extends SortablePage +{ + /** + * @inheritDoc + */ + public $activeMenuItem = 'wcf.acp.menu.link.log.email'; + + /** + * @inheritDoc + */ + public $neededPermissions = ['admin.management.canViewLog']; + + /** + * @inheritDoc + */ + public $itemsPerPage = 100; + + /** + * @inheritDoc + */ + public $defaultSortField = 'time'; + + /** + * @inheritDoc + */ + public $defaultSortOrder = 'DESC'; + + /** + * @inheritDoc + */ + public $validSortFields = ['entryID', 'time', 'status']; + + /** + * @inheritDoc + */ + public $objectListClassName = EmailLogEntryList::class; + + /** + * @inheritDoc + */ + public function readData() + { + parent::readData(); + + $userIDs = \array_filter(\array_column($this->objectList->getObjects(), 'recipientID')); + UserRuntimeCache::getInstance()->cacheObjectIDs($userIDs); + } +} diff --git a/wcfsetup/install/files/lib/data/email/log/entry/EmailLogEntry.class.php b/wcfsetup/install/files/lib/data/email/log/entry/EmailLogEntry.class.php index e723646f0e..6d37ee37d0 100644 --- a/wcfsetup/install/files/lib/data/email/log/entry/EmailLogEntry.class.php +++ b/wcfsetup/install/files/lib/data/email/log/entry/EmailLogEntry.class.php @@ -3,6 +3,9 @@ namespace wcf\data\email\log\entry; use wcf\data\DatabaseObject; +use wcf\data\user\User; +use wcf\system\cache\runtime\UserRuntimeCache; +use wcf\system\email\Email; /** * Represents an email log entry. @@ -30,4 +33,48 @@ class EmailLogEntry extends DatabaseObject public const STATUS_TRANSIENT_FAILURE = 'transient_failure'; public const STATUS_PERMANENT_FAILURE = 'permanent_failure'; + + /** + * Returns the formatted 'Message-ID', stripping useless information. + */ + public function getFormattedMessageId(): string + { + return \preg_replace_callback( + '/^\<((.*)@(.*))\>$/', + static function ($matches) { + if ($matches[3] === Email::getHost()) { + return $matches[2] . '@'; + } else { + return $matches[1]; + } + }, + $this->messageID + ); + } + + /** + * Returns the recipient. + * + * @see EmailLogEntry::$recipient + */ + public function getRecipient(): ?User + { + if (!$this->recipientID) { + return null; + } + + return UserRuntimeCache::getInstance()->getObject($this->recipientID); + } + + /** + * Returns the redacted recipient address. + */ + public function getRedactedRecipientAddress(): string + { + $atSign = \strrpos($this->recipient, '@'); + $localpart = \substr($this->recipient, 0, $atSign); + $domain = \substr($this->recipient, $atSign + 1); + + return \substr($localpart, 0, 1) . "\u{2022}\u{2022}\u{2022}\u{2022}@{$domain}"; + } } diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index 97736d4b0d..6d3fb2a99b 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -629,6 +629,15 @@ + + + + + + + + + @@ -1212,6 +1221,7 @@ ACHTUNG: Die oben genannten Meldungen sind stark gekürzt. Sie können Details z + diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index a0b4ab333d..ae9b8b19be 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -605,6 +605,15 @@ + + + + + + + + + @@ -1189,6 +1198,7 @@ ATTENTION: The messages listed above are greatly shortened. You can view details + -- 2.20.1