Skip to content
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

Created Message class to encapsulate the "messages" generator #129

Merged
merged 4 commits into from
Jul 25, 2018

Conversation

zevaverbach
Copy link
Contributor

@zevaverbach zevaverbach commented Jul 25, 2018

This enables

  • len(Imbox.messages)
  • Imbox.messages[2]
  • Imbox.messages[2:4]

as well as

for uid, m in Imbox.messages:
    print(m.subject)
for uid, m in Imbox.messages:
    print(m.subject)
    # generator is not exhausted, doesn't return None silently

I also did a small amount of cleanup of unnecessary args/verbosity around the project (the first two commits).

Fixes #121.

Moved `fetch_list` to `Messages` and renamed `fetch_email_list`, moving assignment of uid_list to the constructor of `Messages`.

Moved `fetch_by_uid` from `Imbox` to a pure function in `parser` module.

Replaced call to `Imbox.fetch_list` with a call to `Messages` instead.

created `Messages` class, which encapsulates the generator `Messages.fetch_email_list`, while also implementing `__len__` to show how many emails match a given query, and `__iter__` to refresh the `fetch_email_list` generator when it's exhausted.  It also implements `__getitem__` to support indexing of the emails matching a query.  Messages requires the `connection` and `parser_policy` established in `Imbox` and accepts arbitrary keyword arguments, which it uses in the IMAP query as well as in the `__repr__`.
@martinrusev martinrusev merged commit 34149ef into martinrusev:master Jul 25, 2018
@zevaverbach zevaverbach deleted the encapsulate_generator branch July 25, 2018 18:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants