From a2ff1142ce2d4c372f34283d1807c766400a1e46 Mon Sep 17 00:00:00 2001 From: brady Date: Sat, 5 Jan 2019 21:51:35 -0600 Subject: ~ expansion for .config/alot/config pep8! Better variable names, new feature into docs. Make sphinx documentation. --- alot/utils/configobj.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'alot/utils') diff --git a/alot/utils/configobj.py b/alot/utils/configobj.py index 73553a0c..caeb4295 100644 --- a/alot/utils/configobj.py +++ b/alot/utils/configobj.py @@ -90,24 +90,23 @@ def mail_container(value): """ Check that the value points to a valid mail container, in URI-style, e.g.: `mbox:///home/username/mail/mail.box`. + `~`-expansion will work, e.g.: `mbox://~/mail/mail.box`. The value is cast to a :class:`mailbox.Mailbox` object. """ if not re.match(r'.*://.*', value): raise VdtTypeError(value) mburl = urlparse(value) - if mburl.scheme == 'mbox': - box = mailbox.mbox(mburl.path) - elif mburl.scheme == 'maildir': - box = mailbox.Maildir(mburl.path) - elif mburl.scheme == 'mh': - box = mailbox.MH(mburl.path) - elif mburl.scheme == 'babyl': - box = mailbox.Babyl(mburl.path) - elif mburl.scheme == 'mmdf': - box = mailbox.MMDF(mburl.path) - else: - raise VdtTypeError(value) - return box + uri_scheme_to_mbclass = { + 'mbox': mailbox.mbox, + 'maildir': mailbox.Maildir, + 'mh': mailbox.MH, + 'babyl': mailbox.Babyl, + 'mmdf': mailbox.MMDF, + } + klass = uri_scheme_to_mbclass.get(mburl.scheme) + if klass: + return klass(mburl.netloc + mburl.path) + raise VdtTypeError(value) def force_list(value, min=None, max=None): -- cgit v1.2.3