diff options
author | Patrick Totzke <patricktotzke@gmail.com> | 2012-03-11 13:24:03 +0000 |
---|---|---|
committer | Patrick Totzke <patricktotzke@gmail.com> | 2012-03-11 13:24:03 +0000 |
commit | 785aae6f41f240c149e8f3dffac6796635455124 (patch) | |
tree | 7a3e86893ea635e3e4b8e8c6d829a557804900a7 | |
parent | c01e925af1b9d960d77f9c053cc43d15da5e4d84 (diff) |
introduce a `mail_container` validation check
This introduces a new custoim validation check
`mail_container` for the uri-like syntax we use for specifying
sent/draft boxes in accounts
-rw-r--r-- | alot/checks.py | 21 | ||||
-rw-r--r-- | alot/settings.py | 3 |
2 files changed, 23 insertions, 1 deletions
diff --git a/alot/checks.py b/alot/checks.py new file mode 100644 index 00000000..693d3044 --- /dev/null +++ b/alot/checks.py @@ -0,0 +1,21 @@ +import mailbox +import re +from urlparse import urlparse + +def mail_container(value): + 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 diff --git a/alot/settings.py b/alot/settings.py index 2a9b159e..7fcea787 100644 --- a/alot/settings.py +++ b/alot/settings.py @@ -11,6 +11,7 @@ from account import SendmailAccount, MatchSdtoutAddressbook, AbookAddressBook from alot.errors import ConfigError from alot.helper import read_config +from checks import mail_container DEFAULTSPATH = os.path.join(os.path.dirname(__file__), 'defaults') @@ -109,7 +110,7 @@ class SettingsManager(object): def read_config(self, path): """parse alot's config file from path""" spec = os.path.join(DEFAULTSPATH, 'alot.rc.spec') - newconfig = read_config(path, spec) + newconfig = read_config(path, spec, checks={'mail_container': mail_container}) self._config.merge(newconfig) hooks_path = os.path.expanduser(self._config.get('hooksfile')) |