diff options
author | Patrick Totzke <patricktotzke@gmail.com> | 2012-03-11 13:55:47 +0000 |
---|---|---|
committer | Patrick Totzke <patricktotzke@gmail.com> | 2012-03-11 13:55:47 +0000 |
commit | 1b1f7465b5c8a3d8a295247559d77c2e9a591dd8 (patch) | |
tree | 2ddec4045ed8346aa557d14babfed7d87a277f88 /alot | |
parent | 9b8c0dd28b4bfa755ddf1470b698b863969edca8 (diff) | |
parent | cc0a67526088df5626be6e6567e3fb5788ec84b4 (diff) |
Merge branch 'mbox-check-404' into testing
Diffstat (limited to 'alot')
-rw-r--r-- | alot/account.py | 34 | ||||
-rw-r--r-- | alot/checks.py | 21 | ||||
-rw-r--r-- | alot/defaults/alot.rc.spec | 8 | ||||
-rw-r--r-- | alot/helper.py | 6 | ||||
-rw-r--r-- | alot/settings.py | 3 |
5 files changed, 36 insertions, 36 deletions
diff --git a/alot/account.py b/alot/account.py index 88d2ce10..0e590953 100644 --- a/alot/account.py +++ b/alot/account.py @@ -6,7 +6,6 @@ import email import os import glob import shlex -from urlparse import urlparse import helper @@ -50,44 +49,17 @@ class Account(object): sent_tags=['sent'], draft_box=None, draft_tags=['draft'], abook=None, **rest): self.address = address - self.abook = abook - self.aliases = [] self.aliases = aliases self.realname = realname self.gpg_key = gpg_key self.signature = signature self.signature_filename = signature_filename self.signature_as_attachment = signature_as_attachment - - self.sent_box = None - if sent_box: - mburl = urlparse(sent_box) - if mburl.scheme == 'mbox': - self.sent_box = mailbox.mbox(mburl.path) - elif mburl.scheme == 'maildir': - self.sent_box = mailbox.Maildir(mburl.path) - elif mburl.scheme == 'mh': - self.sent_box = mailbox.MH(mburl.path) - elif mburl.scheme == 'babyl': - self.sent_box = mailbox.Babyl(mburl.path) - elif mburl.scheme == 'mmdf': - self.sent_box = mailbox.MMDF(mburl.path) + self.sent_box = sent_box self.sent_tags = sent_tags - - self.draft_box = None - if draft_box: - mburl = urlparse(draft_box) - if mburl.scheme == 'mbox': - self.draft_box = mailbox.mbox(mburl.path) - elif mburl.scheme == 'maildir': - self.draft_box = mailbox.Maildir(mburl.path) - elif mburl.scheme == 'mh': - self.draft_box = mailbox.MH(mburl.path) - elif mburl.scheme == 'babyl': - self.draft_box = mailbox.Babyl(mburl.path) - elif mburl.scheme == 'mmdf': - self.draft_box = mailbox.MMDF(mburl.path) + self.draft_box = draft_box self.draft_tags = draft_tags + self.abook = abook def get_addresses(self): """return all email addresses connected to this account, in order of 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/defaults/alot.rc.spec b/alot/defaults/alot.rc.spec index cb98c530..1470393d 100644 --- a/alot/defaults/alot.rc.spec +++ b/alot/defaults/alot.rc.spec @@ -150,10 +150,12 @@ prompt_suffix = string(default=':') # sendmail command. This is the shell command used to send out mails via the sendmail protocol sendmail_command = string(default='sendmail') - # specifies the mailbox where you want outgoing mails to be stored after successfully sending them, e.g. - # where to store outgoing mail, e.g. `maildir:///home/you/mail//Sent` + # where to store outgoing mails, e.g. `maildir:///home/you/mail//Sent` # You can use mbox, maildir, mh, babyl and mmdf in the protocol part of the URL. - sent_box = string(default=None) + sent_box = mail_container(default=None) + + # where to store draft mails, see :ref:`sent_box <sent-box>` for the format + draft_box = mail_container(default=None) # list of tags to automatically add to outgoing messages sent_tags = string_list(default=list('sent')) diff --git a/alot/helper.py b/alot/helper.py index 56250c71..7588e5aa 100644 --- a/alot/helper.py +++ b/alot/helper.py @@ -401,7 +401,7 @@ def humanize_size(size): return format_string % (size / factor) -def read_config(configpath=None, specpath=None): +def read_config(configpath=None, specpath=None, checks={}): """ get a (validated) config object for given config file path. @@ -409,6 +409,9 @@ def read_config(configpath=None, specpath=None): :type configpath: str :param specpath: path to spec-file :type specpath: str + :param checks: custom checks to use for validator. + see `validate docs <http://www.voidspace.org.uk/python/validate.html>`_ + :type checks: dict str->callable, :rtype: `configobj.ConfigObj` """ try: @@ -419,6 +422,7 @@ def read_config(configpath=None, specpath=None): if specpath: validator = Validator() + validator.functions.update(checks) results = config.validate(validator) if results != True: 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')) |