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

create vendors module to support idiosyncratic IMAP providers #131

Closed
zevaverbach opened this issue Jul 25, 2018 · 4 comments
Closed

create vendors module to support idiosyncratic IMAP providers #131

zevaverbach opened this issue Jul 25, 2018 · 4 comments

Comments

@zevaverbach
Copy link
Contributor

zevaverbach commented Jul 25, 2018

This was alluded to in #123. Here are a few things such a module could support:

  • map flag names to standardized folder names, and vice versa. For example, in Gmail the archived messages correspond with "[Gmail]/All Mail" (including the double quotes!), whereas in Yahoo Mail it's Archive
  • when there's an authentication error when instantiating Imbox, helpful error messages might be displayed. For example, with Yahoo: Have you clicked "Allow apps that use less secure sign in" here?: https://login.yahoo.com/account/security.
  • support IMAP extensions, which at least Gmail uses. (also alluded to in support Gmail's IMAP extensions #123)

Would you accept a PR that accomplishes this, at least for a few large IMAP providers?

@martinrusev
Copy link
Owner

@zevaverbach a vendors module would be an awesome addition. I would gladly accept a PR.

@zevaverbach
Copy link
Contributor Author

zevaverbach commented Jul 26, 2018

Will do! Would it be acceptable to employ such a module “magically“ in the constructor of Imbox? In addition to being able to do so manually .

@martinrusev
Copy link
Owner

martinrusev commented Jul 26, 2018

@zevaverbach What I think would work well:

# vendors/gmail
GmailMessages(Messages):
   ..... gmail specific logic

# vendors/__init__.py
__all__ = [GmailMessages]

with Imbox('imap.gmail.com',
        username='username',
        password='password', 
vendor="gmail"):

(or) the magic option

with Imbox('imap.gmail.com) -> parse the hostname, domain is `gmail`, switch to vendor `gmail` automatically 

https://github.com/martinrusev/imbox/blob/master/imbox/__init__.py#L68

from imbox.vendors import GmailMessages

# Set the default
messages_class = Messages
if vendor == "gmail":
  messages_class = GmailMessages

return messages_class(connection=self.connection,
                        parser_policy=self.parser_policy,
                        **kwargs)

@zevaverbach
Copy link
Contributor Author

@martinrusev super elegant, thank you. Will submit a PR soon.

zevaverbach added a commit to zevaverbach/imbox that referenced this issue Jul 27, 2018
…lMessages class. 'vendor' is now a kwarg for Imbox, but there's also a lookup dict created in vendors/__init__.py for 'magic' determination of the vendor from the hostname.

added `authentication_error_message` as a class attribute to `Imbox`.  If `Imbox.vendor` is not None, look for a custom authentication error string, and raise it if there's a problem logging in.  The default error value is raised if there is no custom string.

created `name_authentication_string_dict` from all subclasses of `Messages` in `vendors/__init__.py`, for the lookup mentioned above.

Implement architecture discussed in martinrusev#131, deciding whether to use `Messages` or a subclass of it in `Imbox.messages` based on the `Imbox.vendor` value.  Use the `folder_lookup` dict, present on `Messages` but only filled in on its subclasses, to select the right folder based on a lowercased "standard" name given as the value of `folder`.

created a blank `folder_lookup` on `Messages`.

filled in the first vendor that subclasses `Messages`, `GmailMessages`.  It contains class attributes `authentication_error_message`, `hostname`, `name`, used for purposes described above, as well as `folder_lookup` which is a dict containing aliases, sometimes several, for Gmail's unique folder naming scheme.  These aliases are meant to be "human-friendly" for intuitive `folder` selection in calls to `Imbox.messages`.

fixes martinrusev#131.

prevent too much bookkeeping in vendors/__init__.py by adding each vendor.__name__ to __all__ from the vendors list.
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

No branches or pull requests

2 participants