2 # Copyright (c) 2007 - 2010, Pascal Volk |
2 # Copyright (c) 2007 - 2010, Pascal Volk |
3 # See COPYING for distribution information. |
3 # See COPYING for distribution information. |
4 |
4 |
5 """ |
5 """ |
6 VirtualMailManager.Config |
6 VirtualMailManager.Config |
|
7 ~~~~~~~~~~~~~~~~~~~~~~~~~ |
7 |
8 |
8 VMM's configuration module for simplified configuration access. |
9 VMM's configuration module for simplified configuration access. |
9 """ |
10 """ |
10 |
11 |
11 import re |
12 import re |
16 from cStringIO import StringIO# TODO: move interactive stff to cli |
17 from cStringIO import StringIO# TODO: move interactive stff to cli |
17 |
18 |
18 from VirtualMailManager.common import exec_ok, get_unicode, is_dir, version_hex |
19 from VirtualMailManager.common import exec_ok, get_unicode, is_dir, version_hex |
19 from VirtualMailManager.constants.ERROR import CONF_ERROR |
20 from VirtualMailManager.constants.ERROR import CONF_ERROR |
20 from VirtualMailManager.errors import ConfigError, VMMError |
21 from VirtualMailManager.errors import ConfigError, VMMError |
|
22 from VirtualMailManager.maillocation import known_format |
21 from VirtualMailManager.password import verify_scheme as _verify_scheme |
23 from VirtualMailManager.password import verify_scheme as _verify_scheme |
22 |
24 |
23 |
25 |
24 _ = lambda msg: msg |
26 _ = lambda msg: msg |
25 |
27 |
338 'directory_mode': LCO(int, 504, self.getint), |
340 'directory_mode': LCO(int, 504, self.getint), |
339 'force_deletion': LCO(bool_t, False, self.getboolean), |
341 'force_deletion': LCO(bool_t, False, self.getboolean), |
340 }, |
342 }, |
341 'mailbox': { |
343 'mailbox': { |
342 'folders': LCO(str, 'Drafts:Sent:Templates:Trash', self.get), |
344 'folders': LCO(str, 'Drafts:Sent:Templates:Trash', self.get), |
343 'format': LCO(str, 'maildir', self.get), |
345 'format': LCO(str, 'maildir', self.get, check_mailbox_format), |
344 'root': LCO(str, 'Maildir', self.get), |
346 'root': LCO(str, 'Maildir', self.get), |
345 }, |
347 }, |
346 'misc': { |
348 'misc': { |
347 'base_directory': LCO(str, '/srv/mail', self.get, is_dir), |
349 'base_directory': LCO(str, '/srv/mail', self.get, is_dir), |
348 'crypt_blowfish_rounds': LCO(int, 5, self.getint), |
350 'crypt_blowfish_rounds': LCO(int, 5, self.getint), |
421 if missing: |
423 if missing: |
422 self.__missing[section] = missing |
424 self.__missing[section] = missing |
423 return not errors |
425 return not errors |
424 |
426 |
425 |
427 |
|
428 def check_mailbox_format(format): |
|
429 """ |
|
430 Check if the mailbox format *format* is supported. When the *format* |
|
431 is supported it will be returned, otherwise a `ConfigValueError` will |
|
432 be raised. |
|
433 """ |
|
434 format = format.lower() |
|
435 if known_format(format): |
|
436 return format |
|
437 raise ConfigValueError(_(u"Unsupported mailbox format: '%s'") % |
|
438 get_unicode(format)) |
|
439 |
|
440 |
426 def check_version_format(version_string): |
441 def check_version_format(version_string): |
427 """Check if the *version_string* has the proper format, e.g.: '1.2.3'. |
442 """Check if the *version_string* has the proper format, e.g.: '1.2.3'. |
428 Returns the validated version string if it has the expected format. |
443 Returns the validated version string if it has the expected format. |
429 Otherwise a `ConfigValueError` will be raised. |
444 Otherwise a `ConfigValueError` will be raised. |
430 """ |
445 """ |