Merge pull request #14353 from annando/stats

Increment inbound/outbound on mails per result
This commit is contained in:
Tobias Diekershoff 2024-08-13 07:19:38 +02:00 committed by GitHub
commit 241d056473
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -48,7 +48,6 @@ class Email
return false;
}
Item::incrementInbound(Protocol::MAIL);
$mbox = @imap_open($mailbox, $username, $password);
$errors = imap_errors();
@ -61,6 +60,9 @@ class Email
Logger::notice('IMAP Alerts occurred: ', ['alerts' => $alerts]);
}
if (empty($errors) && empty($alerts)) {
Item::incrementInbound(Protocol::MAIL);
}
return $mbox;
}
@ -76,28 +78,28 @@ class Email
return [];
}
Item::incrementInbound(Protocol::MAIL);
$search1 = @imap_search($mbox, 'UNDELETED FROM "' . $email_addr . '"', SE_UID);
if (!$search1) {
$search1 = [];
} else {
Logger::debug("Found mails from ".$email_addr);
Item::incrementInbound(Protocol::MAIL);
}
Item::incrementInbound(Protocol::MAIL);
$search2 = @imap_search($mbox, 'UNDELETED TO "' . $email_addr . '"', SE_UID);
if (!$search2) {
$search2 = [];
} else {
Logger::debug("Found mails to ".$email_addr);
Item::incrementInbound(Protocol::MAIL);
}
Item::incrementInbound(Protocol::MAIL);
$search3 = @imap_search($mbox, 'UNDELETED CC "' . $email_addr . '"', SE_UID);
if (!$search3) {
$search3 = [];
} else {
Logger::debug("Found mails cc ".$email_addr);
Item::incrementInbound(Protocol::MAIL);
}
$res = array_unique(array_merge($search1, $search2, $search3));
@ -141,7 +143,6 @@ class Email
public static function getMessage($mbox, int $uid, string $reply, array $item): array
{
$ret = $item;
Item::incrementInbound(Protocol::MAIL);
$struc = (($mbox && $uid) ? @imap_fetchstructure($mbox, $uid, FT_UID) : null);
if (!$struc) {
@ -149,6 +150,8 @@ class Email
return $ret;
}
Item::incrementInbound(Protocol::MAIL);
if (empty($struc->parts)) {
$html = trim(self::messageGetPart($mbox, $uid, $struc, 0, 'html'));
@ -408,8 +411,11 @@ class Email
//$message = '<html><body>' . $html . '</body></html>';
//$message = html2plain($html);
Logger::notice('notifier: email delivery to ' . $addr);
Item::incrementOutbound(Protocol::MAIL);
return mail($addr, $subject, $body, $headers);
$success = mail($addr, $subject, $body, $headers);
if ($success) {
Item::incrementOutbound(Protocol::MAIL);
}
return $success;
}
/**