summaryrefslogtreecommitdiff
path: root/alot/utils
diff options
context:
space:
mode:
authorbrady <brady.mccary@gmail.com>2019-01-05 21:51:35 -0600
committerbmccary <brady.mccary+GITHUB@gmail.com>2019-01-06 11:44:33 -0600
commita2ff1142ce2d4c372f34283d1807c766400a1e46 (patch)
treed3076aaf2033e5229a3e97a1c3959dcfb10c1d35 /alot/utils
parent6bb18fa97c78b3cb1fcb60ce5d850602b55e358f (diff)
~ expansion for .config/alot/config
pep8! Better variable names, new feature into docs. Make sphinx documentation.
Diffstat (limited to 'alot/utils')
-rw-r--r--alot/utils/configobj.py25
1 files changed, 12 insertions, 13 deletions
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):