# HG changeset patch
# User Pascal Volk <neverseen@users.sourceforge.net>
# Date 1279749219 0
# Node ID e1d3f027dd6444cb1a0b62d75cd98137570370e8
# Parent  efa001edc3490b01f6c93d34f772b03bc2eafe3e
VMM/Config: Added function check_mailbox_format().

diff -r efa001edc349 -r e1d3f027dd64 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.