VirtualMailManager/Config.py
branchv0.6.x
changeset 287 1e77dd639fa3
parent 286 e2046d47688b
child 290 e2785e04f92e
--- a/VirtualMailManager/Config.py	Mon May 03 20:38:36 2010 +0000
+++ b/VirtualMailManager/Config.py	Tue May 04 00:01:35 2010 +0000
@@ -17,7 +17,8 @@
 
 from VirtualMailManager.common import exec_ok, get_unicode, is_dir, version_hex
 from VirtualMailManager.constants.ERROR import CONF_ERROR
-from VirtualMailManager.errors import ConfigError
+from VirtualMailManager.errors import ConfigError, VMMError
+from VirtualMailManager.password import verify_scheme as _verify_scheme
 
 
 _ = lambda msg: msg
@@ -349,7 +350,7 @@
                 'dovecot_version': LCO(str, None, self.hexversion,
                                        check_version_format),
                 'password_scheme': LCO(str, 'CRAM-MD5', self.get,
-                                       self.known_scheme),
+                                       verify_scheme),
                 'transport': LCO(str, 'dovecot:', self.get),
             },
         }
@@ -396,22 +397,9 @@
         value to an int."""
         return version_hex(self.get(section, option))
 
-    def known_scheme(self, scheme):
-        """Converts `scheme` to upper case and checks if is known by
-        Dovecot (listed in VirtualMailManager.SCHEMES).
-
-        Throws a `ConfigValueError` if the scheme is not listed in
-        VirtualMailManager.SCHEMES.
-
-        """
-        scheme = scheme.upper()
-        # TODO: VMM.SCHEMES
-
     def unicode(self, section, option):
         """Returns the value of the `option` from `section`, converted
-        to Unicode.
-
-        """
+        to Unicode."""
         return get_unicode(self.get(section, option))
 
     def __chk_cfg(self):
@@ -445,4 +433,17 @@
                                get_unicode(version_string))
     return version_string
 
+
+def verify_scheme(scheme):
+    """Checks if the password scheme *scheme* can be accepted and returns
+    the verified scheme.
+    """
+    try:
+        scheme, encoding = _verify_scheme(scheme)
+    except VMMError, err:  # 'cast' it
+        raise ConfigValueError(err.msg)
+    if not encoding:
+        return scheme
+    return '%s.%s' % (scheme, encoding)
+
 del _