]> git.mxchange.org Git - friendica.git/commitdiff
Increment inbound/outbound on mails per result
authorMichael <heluecht@pirati.ca>
Mon, 12 Aug 2024 16:55:16 +0000 (16:55 +0000)
committerMichael <heluecht@pirati.ca>
Mon, 12 Aug 2024 16:55:16 +0000 (16:55 +0000)
src/Protocol/Email.php

index d52f159c15b0ad97f4f31894c13d3943aee3e75e..010a610115693ea898ffd679a59d9a2946f825f1 100644 (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;
        }
 
        /**