summaryrefslogtreecommitdiff
path: root/alot
diff options
context:
space:
mode:
authorPatrick Totzke <patricktotzke@gmail.com>2012-05-16 10:42:44 +0100
committerPatrick Totzke <patricktotzke@gmail.com>2012-05-16 10:42:44 +0100
commitc248891f23f1422f6fed0752aad37d1267d00d25 (patch)
tree149f50b7f6d5ac75d225349fad371389293aa46d /alot
parent11263d67d6ac7607d5eaacf7a5770e5bf1ef443a (diff)
parent67fb7f38d30635beed9afdadc9c93d5645e6b630 (diff)
Merge branch '0.3-fix-stringlists' into staging
Diffstat (limited to 'alot')
-rw-r--r--alot/defaults/alot.rc.spec12
-rw-r--r--alot/settings/__init__.py5
-rw-r--r--alot/settings/checks.py32
3 files changed, 41 insertions, 8 deletions
diff --git a/alot/defaults/alot.rc.spec b/alot/defaults/alot.rc.spec
index c5b4b6fa..7d6715d9 100644
--- a/alot/defaults/alot.rc.spec
+++ b/alot/defaults/alot.rc.spec
@@ -27,10 +27,10 @@ theme = string(default=None)
display_content_in_threadline = boolean(default=False)
# headers that get displayed by default
-displayed_headers = string_list(default=list(From,To,Cc,Bcc,Subject))
+displayed_headers = force_list(default=list(From,To,Cc,Bcc,Subject))
# headers that are hidden in envelope buffers by default
-envelope_headers_blacklist = string_list(default=list(In-Reply-To,References))
+envelope_headers_blacklist = force_list(default=list(In-Reply-To,References))
# Replace own email addresses with "me" in author lists
# Uses own addresses and aliases in all configured accounts.
@@ -62,10 +62,10 @@ editor_in_thread = boolean(default=False)
# Which header fields should be editable in your editor
# used are those that match the whitelist and don't match the blacklist.
# in both cases '*' may be used to indicate all fields.
-edit_headers_whitelist = string_list(default=list(*,))
+edit_headers_whitelist = force_list(default=list(*,))
# see :ref:`edit_headers_whitelist <edit-headers-whitelist>`
-edit_headers_blacklist = string_list(default=list(Content-Type,MIME-Version,References,In-Reply-To))
+edit_headers_blacklist = force_list(default=list(Content-Type,MIME-Version,References,In-Reply-To))
# timeout in seconds after a failed attempt to writeout the database is repeated
flush_retry_timeout = integer(default=5)
@@ -146,7 +146,7 @@ prompt_suffix = string(default=':')
realname = string
# used to clear your addresses/ match account when formatting replies
- aliases = string_list(default=list())
+ aliases = force_list(default=list())
# sendmail command. This is the shell command used to send out mails via the sendmail protocol
sendmail_command = string(default='sendmail -t')
@@ -167,7 +167,7 @@ prompt_suffix = string(default=':')
draft_box = mail_container(default=None)
# list of tags to automatically add to outgoing messages
- sent_tags = string_list(default=list('sent'))
+ sent_tags = force_list(default=list('sent'))
# path to signature file that gets attached to all outgoing mails from this account, optionally
# renamed to ref:`signature_filename <signature-filename>`.
diff --git a/alot/settings/__init__.py b/alot/settings/__init__.py
index b405dfc5..e0cd24f5 100644
--- a/alot/settings/__init__.py
+++ b/alot/settings/__init__.py
@@ -15,7 +15,7 @@ from alot.helper import pretty_datetime, string_decode
from errors import ConfigError
from utils import read_config
-from checks import mail_container
+from checks import mail_container, force_list
from theme import Theme
@@ -55,7 +55,8 @@ class SettingsManager(object):
"""parse alot's config file from path"""
spec = os.path.join(DEFAULTSPATH, 'alot.rc.spec')
newconfig = read_config(path, spec,
- checks={'mail_container': mail_container})
+ checks={'mail_container': mail_container,
+ 'force_list': force_list})
self._config.merge(newconfig)
hooks_path = os.path.expanduser(self._config.get('hooksfile'))
diff --git a/alot/settings/checks.py b/alot/settings/checks.py
index 4943daa3..4b56a284 100644
--- a/alot/settings/checks.py
+++ b/alot/settings/checks.py
@@ -2,9 +2,15 @@ import mailbox
import re
from urlparse import urlparse
from validate import VdtTypeError
+from validate import is_list
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`.
+ The value is cast to a :class:`mailbox.Mailbox` object.
+ """
if not re.match(r'.*://.*', value):
raise VdtTypeError(value)
mburl = urlparse(value)
@@ -21,3 +27,29 @@ def mail_container(value):
else:
raise VdtTypeError(value)
return box
+
+
+def force_list(value, min=None, max=None):
+ """
+ Check that a value is a list, coercing strings into
+ a list with one member.
+
+ You can optionally specify the minimum and maximum number of members.
+ A minumum of greater than one will fail if the user only supplies a
+ string.
+
+ The difference to :func:`validate.force_list` is that this test
+ will return an empty list instead of `['']` if the config value
+ matches `r'\s*,?\s*'`.
+
+ >>> vtor.check('force_list', 'hello')
+ ['hello']
+ >>> vtor.check('force_list', '')
+ []
+ """
+ if not isinstance(value, (list, tuple)):
+ value = [value]
+ rlist = is_list(value, min, max)
+ if rlist == ['']:
+ rlist = []
+ return rlist