diff --git a/email_forwarder/email_forwarder.py b/email_forwarder/email_forwarder.py index d7d0625..59bdfc5 100644 --- a/email_forwarder/email_forwarder.py +++ b/email_forwarder/email_forwarder.py @@ -106,8 +106,10 @@ class DestImap(ImapClient): """Check if Message-ID exists in current folder.""" try: results = self._search(f'HEADER Message-ID "{msg_id}"') + logging.debug(f"Check duplicate for {msg_id}: found {len(results)} matches") return len(results) > 0 - except: + except Exception as e: + logging.error(f"Error checking duplicate for {msg_id}: {e}") return False def _create_folder(self, folder: str): @@ -205,6 +207,11 @@ class EmailForwarder: continue if msg_id in self.processed_ids: continue + self.dest.ensure_folder_exists(folder) + if self.dest.check_duplicate(msg_id): + continue + if msg_id in self.processed_ids: + continue if self.dest.check_duplicate(msg_id): continue