From a2e5c60683ed2fb1add2454c338b76ea9bff5864 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Fri, 29 Apr 2022 09:42:05 +0200 Subject: [PATCH] - remove one unncessary usage of imap idle - simplify SEEN bytes/unicode flag issue - fix a lint issue and a docstring --- python/src/deltachat/direct_imap.py | 10 +++------- python/tests/test_account.py | 9 +++------ 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/python/src/deltachat/direct_imap.py b/python/src/deltachat/direct_imap.py index de5227d4f..c862eb990 100644 --- a/python/src/deltachat/direct_imap.py +++ b/python/src/deltachat/direct_imap.py @@ -12,8 +12,6 @@ import deltachat from deltachat import const, Account -SEEN = MailMessageFlags.SEEN -DELETED = MailMessageFlags.DELETED FLAGS = b'FLAGS' FETCH = b'FETCH' ALL = "1:*" @@ -146,7 +144,7 @@ class DirectImap: def mark_all_read(self): messages = self.get_unread_messages() if messages: - res = self.conn.flag(messages, SEEN, True) + res = self.conn.flag(messages, MailMessageFlags.SEEN, True) print("marked seen:", messages, res) def get_unread_cnt(self) -> int: @@ -171,7 +169,6 @@ class DirectImap: log("---------", imapfolder, len(messages), "messages ---------") # get message content without auto-marking it as seen # fetching 'RFC822' would mark it as seen. - requested = [b'BODY.PEEK[]', FLAGS] for msg in self.conn.fetch(mark_seen=False): body = getattr(msg.obj, "text", None) if not body: @@ -218,14 +215,13 @@ class DirectImap: return item def idle_wait_for_seen(self, terminate=False, timeout=60) -> int: - """ Return first message with SEEN flag - from a running idle-stream REtiurn. + """ Return first message with SEEN flag from a running idle-stream. """ while 1: for item in self.idle_check(timeout=timeout): if FETCH in item: self.account.log(str(item)) - if FLAGS in item and bytes(SEEN, encoding='ascii') in item: + if FLAGS in item and rb'\Seen' in item: if terminate: self.idle_done() return int(item.split(b' ')[1]) diff --git a/python/tests/test_account.py b/python/tests/test_account.py index 345216a40..a8d797bd4 100644 --- a/python/tests/test_account.py +++ b/python/tests/test_account.py @@ -2548,12 +2548,9 @@ class TestOnlineAccount: ac2._evtracker.get_info_contains("close/expunge succeeded") - lp.sec("imap2: test that only one message is left") - imap2 = ac2.direct_imap - imap2.idle_start() - imap2.idle_wait_for_new_message(timeout=600) - imap2.idle_done() - assert len(imap2.get_all_messages()) == 1 + lp.sec("ac2: test that only one message is left") + ac2.direct_imap.select_config_folder("inbox") + assert len(ac2.direct_imap.get_all_messages()) == 1 def test_configure_error_msgs(self, acfactory): ac1, configdict = acfactory.get_online_config()