VMM/Account: Adjusted to changes in maillocation.MailLocation.
VMM/maillocation: Class MailLocation added missing property `mid`.
Added new error to VMM/constants/ERROR and doc/source/vmm_constants_error
# -*- coding: UTF-8 -*-# Copyright (c) 2008 - 2010, Pascal Volk# See COPYING for distribution information.""" VirtualMailManager.maillocation Virtual Mail Manager's maillocation module to handle Dovecot's mail_location setting for accounts."""fromVirtualMailManager.pycompatimportany__all__=('MailLocation','MAILDIR_ID','MBOX_ID','MDBOX_ID','SDBOX_ID','MAILDIR_NAME','MBOX_NAME','MDBOX_NAME','SDBOX_NAME')MAILDIR_ID=0x1MBOX_ID=0x2MDBOX_ID=0x3SDBOX_ID=0x4MAILDIR_NAME='Maildir'MBOX_NAME='mail'MDBOX_NAME='mdbox'SDBOX_NAME='dbox'_storage={MAILDIR_ID:dict(dovecot_version=10,postfix=True,prefix='maildir:',directory=MAILDIR_NAME),MBOX_ID:dict(dovecot_version=10,postfix=True,prefix='mbox:',directory=MBOX_NAME),MDBOX_ID:dict(dovecot_version=20,postfix=False,prefix='mdbox:',directory=MDBOX_NAME),SDBOX_ID:dict(dovecot_version=12,postfix=False,prefix='dbox:',directory=SDBOX_NAME),}_type_id={'maildir':MAILDIR_ID,MBOX_NAME:MBOX_ID,MDBOX_NAME:MDBOX_ID,SDBOX_NAME:SDBOX_ID,}classMailLocation(object):"""A small class for mail_location relevant information."""__slots__=('_info')def__init__(self,mid=None,type_=None):"""Creates a new MailLocation instance. Either mid or type_ must be specified. Keyword arguments: mid -- the id of a mail_location (int) one of the maillocation constants: `MAILDIR_ID`, `MBOX_ID`, `MDBOX_ID` and `SDBOX_ID` type_ -- the type/mailbox format of the mail_location (str) one of the maillocation constants: `MAILDIR_NAME`, `MBOX_NAME`, `MDBOX_NAME` and `SDBOX_NAME` """assertany((mid,type_))ifmid:assertisinstance(mid,(int,long))andmidin_storageself._info=_storage[mid]else:assertisinstance(type_,basestring)andtype_.lower()in_type_idself._info=_storage[_type_id[type_.lower()]]def__str__(self):return'%(prefix)s~/%(directory)s'%self._info@propertydefdirectory(self):"""The mail_location's directory name."""returnself._info['directory']@propertydefdovecot_version(self):"""The required Dovecot version (concatenated major and minor parts) for this mailbox format."""returnself._info['dovecot_version']@propertydefpostfix(self):"""`True` if Postfix supports this mailbox format, else `False`."""returnself._info['postfix']@propertydefprefix(self):"""The prefix of the mail_location."""returnself._info['prefix']@propertydefmail_location(self):"""The mail_location, e.g. ``maildir:~/Maildir``"""returnself.__str__()@propertydefmid(self):"""The mail_location's unique ID."""return_type_id[self._info['directory'].lower()]