From 2ed824c91e05bfafca60b84d008d3054b57c61a2 Mon Sep 17 00:00:00 2001 From: Alex Puiu <=> Date: Thu, 19 May 2022 11:16:03 +0300 Subject: [PATCH] Solve bug when emails were marked for deletion but not added to deck --- index.php | 6 +++++- lib/MailClass.php | 13 ++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/index.php b/index.php index 45b7e65..7e407cb 100644 --- a/index.php +++ b/index.php @@ -10,7 +10,11 @@ use Mail2Deck\ConvertToMD; $inbox = new MailClass(); $emails = $inbox->getNewMessages(); -if(!$emails) return; // nothing to do +if(!$emails) { + // delete all messages marked for deletion and return + $inbox->expunge(); + return; +} for ($j = 0; $j < count($emails) && $j < 5; $j++) { $structure = $inbox->fetchMessageStructure($emails[$j]); diff --git a/lib/MailClass.php b/lib/MailClass.php index b2be570..ae816fc 100644 --- a/lib/MailClass.php +++ b/lib/MailClass.php @@ -80,15 +80,22 @@ class MailClass { } /** - * Deletes a mail + * Mark emails for deletion * - * @param $email email id that you want to delete + * @param $email email number that you want to delete * * @return void */ public function delete(int $email) { - imap_delete($this->inbox, $email); + imap_delete($this->inbox, imap_uid($this->inbox, $email), FT_UID); + } + + /** + * Delete all messages marked for deletion + */ + public function expunge() + { imap_expunge($this->inbox); } }