From 3c4cfc7a9c685d80c6b32c9561cb63b735334f43 Mon Sep 17 00:00:00 2001 From: Matthew Exon Date: Tue, 26 Dec 2023 16:34:57 +0000 Subject: [PATCH] some more robust mailstream stuff --- mailstream/mailstream.php | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/mailstream/mailstream.php b/mailstream/mailstream.php index f0dcf3419..cfc665f07 100644 --- a/mailstream/mailstream.php +++ b/mailstream/mailstream.php @@ -118,9 +118,28 @@ function mailstream_send_hook(array $data) return; } + if ($item['deleted']) { + Logger::debug('mailstream_send_hook skipping deleted item', ['guid' => $item['guid']]); + return; + } + $user = User::getById($item['uid']); if (empty($user)) { - Logger::error('mailstream_send_hook could not fund user', ['uid' => $item['uid']]); + Logger::error('mailstream_send_hook could not find user', ['uid' => $item['uid']]); + return; + } + + $contact = DBA::selectFirst('contact', [], ['id' => $item['contact-id'], 'self' => false]); + if (!DBA::isResult($contact)) { + Logger::error('mailstream_send_hook could not find contact', ['guid' => $item['guid'], 'contact-id' => $item['contact-id']]); + return; + } + if ($contact['blocked']) { + Logger::error('mailstream_send_hook contact is blocked', ['guid' => $item['guid'], 'contact-id' => $item['contact-id']]); + return; + } + if (array_key_exists('ignored', $contact) && $contact['ignored']) { + Logger::error('mailstream_send_hook contact is ignored', ['guid' => $item['guid'], 'contact-id' => $item['contact-id']]); return; } @@ -143,7 +162,6 @@ function mailstream_send_hook(array $data) function mailstream_post_hook(array &$item) { mailstream_check_version(); - Logger::debug('@@@ mailstream_post_hook', ['item-uid' => $item['uid']]); if (!DI::pConfig()->get($item['uid'], 'mailstream', 'enabled')) { Logger::debug('mailstream: not enabled for item ' . $item['id'] . ' uid ' . $item['uid']);