-
-
Notifications
You must be signed in to change notification settings - Fork 110
Port folder-related CFFI tests to JSON-RPC #7424
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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)) | ||
|
|
||
| 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() | ||
|
|
@@ -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 | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| # 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: | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.""" | ||
|
|
||
There was a problem hiding this comment.
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
FETCHoperation, it hasmark_seen=Trueand 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