VMM/Config: Added function check_mailbox_format(). v0.6.x
authorPascal Volk <neverseen@users.sourceforge.net>
Wed, 21 Jul 2010 21:53:39 +0000
branchv0.6.x
changeset 301 e1d3f027dd64
parent 300 efa001edc349
child 302 32b4a39b5640
VMM/Config: Added function check_mailbox_format().
VirtualMailManager/Config.py
--- a/VirtualMailManager/Config.py	Tue Jul 20 18:40:16 2010 +0000
+++ b/VirtualMailManager/Config.py	Wed Jul 21 21:53:39 2010 +0000
@@ -4,6 +4,7 @@
 
 """
     VirtualMailManager.Config
+    ~~~~~~~~~~~~~~~~~~~~~~~~~
 
     VMM's configuration module for simplified configuration access.
 """
@@ -18,6 +19,7 @@
 from VirtualMailManager.common import exec_ok, get_unicode, is_dir, version_hex
 from VirtualMailManager.constants.ERROR import CONF_ERROR
 from VirtualMailManager.errors import ConfigError, VMMError
+from VirtualMailManager.maillocation import known_format
 from VirtualMailManager.password import verify_scheme as _verify_scheme
 
 
@@ -340,7 +342,7 @@
             },
             'mailbox': {
                 'folders': LCO(str, 'Drafts:Sent:Templates:Trash', self.get),
-                'format': LCO(str, 'maildir', self.get),
+                'format': LCO(str, 'maildir', self.get, check_mailbox_format),
                 'root': LCO(str, 'Maildir', self.get),
             },
             'misc': {
@@ -423,6 +425,19 @@
         return not errors
 
 
+def check_mailbox_format(format):
+    """
+    Check if the mailbox format *format* is supported.  When the *format*
+    is supported it will be returned, otherwise a `ConfigValueError` will
+    be raised.
+    """
+    format = format.lower()
+    if known_format(format):
+        return format
+    raise ConfigValueError(_(u"Unsupported mailbox format: '%s'") %
+                           get_unicode(format))
+
+
 def check_version_format(version_string):
     """Check if the *version_string* has the proper format, e.g.: '1.2.3'.
     Returns the validated version string if it has the expected format.