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

remove imaplib dependency #400

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

akvadrako
Copy link
Contributor

I felt like taking a stab at this. It seems to work, though I've only tested against Dovecot. I added a livetest.sh file to automate this with podman.

Basically, I incorporated all the calls from imaplib that imapclient was using into IMAPClient or a new conn.IMAP4 class for the low-level stuff. I divided _command_and_check into 2 versions:

  1. _uid_command_and_check -> just calls _simple_command, optionally with UID prefix.
  2. _subcommand_and_check -> wraps an old imaplib method. No UID support.

It should be easy to do a bit more refactoring on a command-by-command basis, merging the old _cmd_XXX() call (that's from imaplib) into the imapclient parent method. Most of the work might actually be updating the unit tests.

There are a few more things to note. It seems like ACCEPT=UTF8 support was broken, since imaplib.IMAP4.enable() wasn't be called - that's where the magic happens. So I just removed that stuff for now. Also, there were a few calls imaplib supported that client doesn't - like get/set annotations. I left those in as private methods.

I'm open to any feedback.

@mjs
Copy link
Owner

mjs commented May 29, 2020

Thanks for this. It looks promising.

I've had a crazy week so I haven't been able to look at the changes properly yet but I will soon.

@mjs mjs mentioned this pull request Jun 4, 2020
5 tasks
Copy link
Owner

@mjs mjs left a comment

Choose a reason for hiding this comment

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

Thanks so much for this. There's more that can be cleaned up but this is a big enough first step and I think it's the right approach.

The tests are passing for Python 2 but I'm thinking we should stop supporting Python 2. I've just created #401 to discuss this. We probably want to make those changes before landing this PR.

if bye:
raise exceptions.IMAPClientAbortError(bye[-1].decode(self._encoding, 'replace'))

def check_state(self, *states):
Copy link
Owner

Choose a reason for hiding this comment

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

This should probably have an underscore prefix. It shouldn't really get called externally.

Comment on lines +2138 to +2150
def _subcommand_and_check(self, meth, *args, **kwargs):
"""Call another method and check the result code.

Return the data from the command. If unpack=True, return data[0].
"""
unpack = pop_with_default(kwargs, 'unpack', False)
assert not kwargs, "unexpected keyword args: " + ', '.join(kwargs)

typ, data = meth(*args)
self._checkok(meth.__func__.__name__.upper(), typ, data)
if unpack:
return data[0]
return data
Copy link
Owner

Choose a reason for hiding this comment

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

It seems to me that this is somewhat unnecessary. The methods passed to _subcommand_and_check all seem to use _simple_command so if _simple_command was extended to do the OK checking and optional unpacking we wouldn't need _subcommand_and_check at all.

I'm ok with this being a stepping stone and being removed in a later PR if you prefer.

"""
self.check_state('AUTH')

name = 'PROXYAUTH'
Copy link
Owner

Choose a reason for hiding this comment

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

I don't think this is doing anything

Comment on lines +1 to +16
#!/bin/bash

podman run --name=dovecot --rm -d -p 14301:143 dovecot/dovecot

cat >/tmp/livetest.ini <<EOF
[DEFAULT]
host = localhost
username = user
password = pass
port = 14301
ssl = false
EOF

python livetest.py /tmp/livetest.ini

podman rm -f dovecot
Copy link
Owner

Choose a reason for hiding this comment

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

This is great. I hadn't seen podman before.



class IMAP4WithTimeout(imaplib.IMAP4):
class IMAP4WithTimeout(conn.IMAP4):
Copy link
Owner

Choose a reason for hiding this comment

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

With this PR, there's no reason for this to exist any more. The timeout functionality should just be rolled into classes in conn.py.

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