Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions deltachat-rpc-client/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ def delete(self, uid_list: str, expunge=True):

def get_all_messages(self) -> list[MailMessage]:
assert not self._idling
return list(self.conn.fetch())
return list(self.conn.fetch(mark_seen=False))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imap-tools have a weird default for the FETCH operation, it has mark_seen=True and marks all messages that we fetch with \Seen flag. This is directly in the readme: https://pypi.org/project/imap-tools/
Don't think anyone wants this even outside of tests, it is just a bad API: ikvk/imap_tools#179


def get_unread_messages(self) -> list[str]:
assert not self._idling
return [msg.uid for msg in self.conn.fetch(AND(seen=False))]
return [msg.uid for msg in self.conn.fetch(AND(seen=False), mark_seen=False)]

def mark_all_read(self):
messages = self.get_unread_messages()
Expand Down Expand Up @@ -173,33 +173,27 @@ def get_uid_by_message_id(self, message_id) -> str:
class IdleManager:
def __init__(self, direct_imap) -> None:
self.direct_imap = direct_imap
self.log = direct_imap.account.log
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

account does not have log, this code got copy-pasted from CFFI bindings. I have removed log references that failed, previously this code was not working at all as nobody used IDLE on direct IMAP with JSON-RPC.

# fetch latest messages before starting idle so that it only
# returns messages that arrive anew
self.direct_imap.conn.fetch("1:*")
self.direct_imap.conn.idle.start()

def check(self, timeout=None) -> list[bytes]:
"""(blocking) wait for next idle message from server."""
self.log("imap-direct: calling idle_check")
res = self.direct_imap.conn.idle.poll(timeout=timeout)
self.log(f"imap-direct: idle_check returned {res!r}")
return res
return self.direct_imap.conn.idle.poll(timeout=timeout)

def wait_for_new_message(self, timeout=None) -> bytes:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't use timeouts anyway, arbitrary timeouts hardcoded in the tests are annoying as they fail when CI runner is paused. We have pytest timout for the whole test in case it gets stuck. Again, this was copy-pasted from CFFI and nobody used it.

def wait_for_new_message(self) -> bytes:
while True:
for item in self.check(timeout=timeout):
for item in self.check():
if b"EXISTS" in item or b"RECENT" in item:
return item

def wait_for_seen(self, timeout=None) -> int:
"""Return first message with SEEN flag from a running idle-stream."""
while True:
for item in self.check(timeout=timeout):
if FETCH in item:
self.log(str(item))
if FLAGS in item and rb"\Seen" in item:
return int(item.split(b" ")[1])
if FETCH in item and FLAGS in item and rb"\Seen" in item:
return int(item.split(b" ")[1])

def done(self):
"""send idle-done to server if we are currently in idle mode."""
Expand Down
Loading