From a21f957229f337da6b9dc2b9db85cd87cb300c3b Mon Sep 17 00:00:00 2001 From: Jose Zambudio Date: Wed, 24 Jul 2024 08:17:38 +0200 Subject: [PATCH] [IMP] Add option to read e-mails unseen --- .../models/fetchmail_server_folder.py | 9 ++++++++- fetchmail_attach_from_folder/views/fetchmail_server.xml | 1 + .../wizard/attach_mail_manually.py | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/fetchmail_attach_from_folder/models/fetchmail_server_folder.py b/fetchmail_attach_from_folder/models/fetchmail_server_folder.py index 3e351fb36..8105e0fe4 100644 --- a/fetchmail_attach_from_folder/models/fetchmail_server_folder.py +++ b/fetchmail_attach_from_folder/models/fetchmail_server_folder.py @@ -97,6 +97,10 @@ class FetchmailServerFolder(models.Model): help="Optional custom server action to trigger for each incoming " "mail, on the record that was created or updated by this mail", ) + fetch_unseen_only = fields.Boolean( + help="By default all undeleted emails are searched. Checking this " + "field adds the unread condition.", + ) def button_confirm_folder(self): self.write({"state": "draft"}) @@ -170,10 +174,13 @@ class FetchmailServerFolder(models.Model): % {"folder": self.archive_path, "server": server.name} ) + def get_criteria(self): + return "UNDELETED" if not self.fetch_unseen_only else "UNSEEN UNDELETED" + def retrieve_imap_folder(self, connection): """Retrieve all mails for one IMAP folder.""" self.ensure_one() - msgids = self.get_msgids(connection, "UNDELETED") + msgids = self.get_msgids(connection, self.get_criteria()) for msgid in msgids[0].split(): # We will accept exceptions for single messages try: diff --git a/fetchmail_attach_from_folder/views/fetchmail_server.xml b/fetchmail_attach_from_folder/views/fetchmail_server.xml index cd2baf067..0ae8cb86b 100644 --- a/fetchmail_attach_from_folder/views/fetchmail_server.xml +++ b/fetchmail_attach_from_folder/views/fetchmail_server.xml @@ -103,6 +103,7 @@ + diff --git a/fetchmail_attach_from_folder/wizard/attach_mail_manually.py b/fetchmail_attach_from_folder/wizard/attach_mail_manually.py index bd75b208d..f547e71e6 100644 --- a/fetchmail_attach_from_folder/wizard/attach_mail_manually.py +++ b/fetchmail_attach_from_folder/wizard/attach_mail_manually.py @@ -42,7 +42,7 @@ class AttachMailManually(models.TransientModel): folder = folder_model.browse([folder_id]) connection = folder.server_id.connect() connection.select(folder.path) - criteria = "FLAGGED" if folder.flag_nonmatching else "UNDELETED" + criteria = "FLAGGED" if folder.flag_nonmatching else folder.get_criteria() msgids = folder.get_msgids(connection, criteria) for msgid in msgids[0].split(): mail_message, message_org = folder.fetch_msg(connection, msgid)