VMM/Account: Adjusted to changes in maillocation.MailLocation. v0.6.x
authorPascal Volk <neverseen@users.sourceforge.net>
Tue, 02 Mar 2010 19:24:36 +0000
branchv0.6.x
changeset 227 87db9f1f95ea
parent 226 311eee429f67
child 228 a7b000ca4ac9
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
VirtualMailManager/Account.py
VirtualMailManager/constants/ERROR.py
VirtualMailManager/maillocation.py
doc/source/vmm_constants_error.rst
--- a/VirtualMailManager/Account.py	Tue Mar 02 17:40:58 2010 +0000
+++ b/VirtualMailManager/Account.py	Tue Mar 02 19:24:36 2010 +0000
@@ -8,7 +8,8 @@
 from VirtualMailManager.Domain import Domain
 from VirtualMailManager.EmailAddress import EmailAddress
 from VirtualMailManager.errors import AccountError as AccE
-from VirtualMailManager.MailLocation import MailLocation
+from VirtualMailManager.maillocation import MailLocation, MAILDIR_NAME, \
+     MBOX_NAME, MDBOX_NAME, SDBOX_NAME
 from VirtualMailManager.Transport import Transport
 
 
@@ -75,8 +76,12 @@
         dbc.close()
 
     def _prepare(self, maillocation):
+        if not maillocation.lower() in map(lambda x: x.lower(), (MAILDIR_NAME,
+                                           MBOX_NAME, MDBOX_NAME, SDBOX_NAME)):
+            raise AccE(_(u'Unknown mail_location directory name: %r') %
+                       maillocation, ERR.UNKNOWN_MAILLOCATION_NAME)
         self._setID()
-        self._mid = MailLocation(self._dbh, maillocation=maillocation).getID()
+        self._mid = MailLocation(type_=maillocation).mid
 
     def _switchState(self, state, dcvers, service):
         if not isinstance(state, bool):
@@ -192,7 +197,7 @@
             raise AccE(_(u"The account ā€œ%sā€ doesn't exist.") % self._addr,
                     ERR.NO_SUCH_ACCOUNT)
         else:
-            keys = ['name', 'uid', 'gid', 'maildir', 'transport', 'smtp',
+            keys = ['name', 'uid', 'gid', 'mid', 'transport', 'smtp',
                     'pop3', 'imap', sieve_col]
             info = dict(zip(keys, info))
             for service in ('smtp', 'pop3', 'imap', sieve_col):
@@ -203,9 +208,8 @@
                     # TP: A service (pop3/imap) isn't enabled/usable for a user
                     info[service] = _('disabled')
             info['address'] = self._addr
-            info['maildir'] = '%s/%s/%s' % (self._base, info['uid'],
-                    MailLocation(self._dbh,
-                        mid=info['maildir']).getMailLocation())
+            info['home'] = '%s/%s' % (self._base, info['uid'])
+            info['mail_location'] = MailLocation(mid=info['mid']).mail_location
             info['transport'] = Transport(self._dbh,
                                           tid=info['transport']).transport
             return info
--- a/VirtualMailManager/constants/ERROR.py	Tue Mar 02 17:40:58 2010 +0000
+++ b/VirtualMailManager/constants/ERROR.py	Tue Mar 02 19:24:36 2010 +0000
@@ -46,7 +46,8 @@
 RELOCATED_MISSING_DEST = 61
 TRANSPORT_INIT = 62
 UNKNOWN_MAILLOCATION_ID = 63
-UNKNOWN_SERVICE = 64
-UNKNOWN_TRANSPORT_ID = 65
-VMM_ERROR = 66
-VMM_TOO_MANY_FAILURES = 67
+UNKNOWN_MAILLOCATION_NAME = 64
+UNKNOWN_SERVICE = 65
+UNKNOWN_TRANSPORT_ID = 66
+VMM_ERROR = 67
+VMM_TOO_MANY_FAILURES = 68
--- a/VirtualMailManager/maillocation.py	Tue Mar 02 17:40:58 2010 +0000
+++ b/VirtualMailManager/maillocation.py	Tue Mar 02 19:24:36 2010 +0000
@@ -98,3 +98,8 @@
     def mail_location(self):
         """The mail_location, e.g. ``maildir:~/Maildir``"""
         return self.__str__()
+
+    @property
+    def mid(self):
+        """The mail_location's unique ID."""
+        return _type_id[self._info['directory'].lower()]
--- a/doc/source/vmm_constants_error.rst	Tue Mar 02 17:40:58 2010 +0000
+++ b/doc/source/vmm_constants_error.rst	Tue Mar 02 19:24:36 2010 +0000
@@ -214,6 +214,10 @@
 
   There is no Transport entry with the given ID
 
+.. data:: UNKNOWN_MAILLOCATION_NAME
+
+  The given mail_location directory couldn't be accepted
+
 .. data:: VMM_ERROR
 
   Internal error