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/defaults/alot.rc.spec | 4 ++-- alot/utils/configobj.py | 25 ++++++++++++------------- docs/source/configuration/accounts.rst | 3 ++- docs/source/configuration/accounts_table | 4 ++-- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/alot/defaults/alot.rc.spec b/alot/defaults/alot.rc.spec index a2edcb37..31a7876f 100644 --- a/alot/defaults/alot.rc.spec +++ b/alot/defaults/alot.rc.spec @@ -312,14 +312,14 @@ thread_focus_linewise = boolean(default=True) # sendmail command. This is the shell command used to send out mails via the sendmail protocol sendmail_command = string(default='sendmail -t') - # where to store outgoing mails, e.g. `maildir:///home/you/mail/Sent`. + # where to store outgoing mails, e.g. `maildir:///home/you/mail/Sent` or `maildir://~/mail/Sent`. # You can use mbox, maildir, mh, babyl and mmdf in the protocol part of the URL. # # .. note:: If you want to add outgoing mails automatically to the notmuch index # you must use maildir in a path within your notmuch database path. sent_box = mail_container(default=None) - # where to store draft mails, e.g. `maildir:///home/you/mail/Drafts`. + # where to store draft mails, e.g. `maildir:///home/you/mail/Drafts` or `maildir://~/mail/Drafts`. # You can use mbox, maildir, mh, babyl and mmdf in the protocol part of the URL. # # .. note:: You will most likely want drafts indexed by notmuch to be able to 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): diff --git a/docs/source/configuration/accounts.rst b/docs/source/configuration/accounts.rst index f925b7a9..81f45b35 100644 --- a/docs/source/configuration/accounts.rst +++ b/docs/source/configuration/accounts.rst @@ -17,7 +17,8 @@ Here is an example configuration gpg_key = D7D6C5AA sendmail_command = msmtp --account=wayne -t sent_box = maildir:///home/bruce/mail/work/Sent - draft_box = maildir:///home/bruce/mail/work/Drafts + # ~ expansion also works + draft_box = maildir://~/mail/work/Drafts [[secret]] realname = Batman diff --git a/docs/source/configuration/accounts_table b/docs/source/configuration/accounts_table index db727898..7d1c12dc 100644 --- a/docs/source/configuration/accounts_table +++ b/docs/source/configuration/accounts_table @@ -52,7 +52,7 @@ .. describe:: draft_box - where to store draft mails, e.g. `maildir:///home/you/mail/Drafts`. + where to store draft mails, e.g. `maildir:///home/you/mail/Drafts` or `maildir://~/mail/Drafts`. You can use mbox, maildir, mh, babyl and mmdf in the protocol part of the URL. .. note:: You will most likely want drafts indexed by notmuch to be able to @@ -166,7 +166,7 @@ .. describe:: sent_box - where to store outgoing mails, e.g. `maildir:///home/you/mail/Sent`. + where to store outgoing mails, e.g. `maildir:///home/you/mail/Sent` or `maildir://~/mail/Sent`. You can use mbox, maildir, mh, babyl and mmdf in the protocol part of the URL. .. note:: If you want to add outgoing mails automatically to the notmuch index -- cgit v1.2.3