VirtualMailManager/account.py
branchv0.6.x
changeset 417 8209da83e256
parent 404 0c52094447b0
child 442 abcd73f5e980
equal deleted inserted replaced
416:f32b323fd347 417:8209da83e256
    54         self._domain = Domain(self._dbh, self._addr.domainname)
    54         self._domain = Domain(self._dbh, self._addr.domainname)
    55         if not self._domain.gid:
    55         if not self._domain.gid:
    56             # TP: Hm, what “quotation marks” should be used?
    56             # TP: Hm, what “quotation marks” should be used?
    57             # If you are unsure have a look at:
    57             # If you are unsure have a look at:
    58             # http://en.wikipedia.org/wiki/Quotation_mark,_non-English_usage
    58             # http://en.wikipedia.org/wiki/Quotation_mark,_non-English_usage
    59             raise AErr(_(u"The domain '%s' doesn't exist.") %
    59             raise AErr(_(u"The domain '%s' does not exist.") %
    60                        self._addr.domainname, NO_SUCH_DOMAIN)
    60                        self._addr.domainname, NO_SUCH_DOMAIN)
    61         self._uid = 0
    61         self._uid = 0
    62         self._mail = None
    62         self._mail = None
    63         self._qlimit = self._domain.quotalimit
    63         self._qlimit = self._domain.quotalimit
    64         self._transport = self._domain.transport
    64         self._transport = self._domain.transport
    99         """Check and set different attributes - before we store the
    99         """Check and set different attributes - before we store the
   100         information in the database.
   100         information in the database.
   101         """
   101         """
   102         if maillocation.dovecot_version > cfg_dget('misc.dovecot_version'):
   102         if maillocation.dovecot_version > cfg_dget('misc.dovecot_version'):
   103             raise AErr(_(u"The mailbox format '%(mbfmt)s' requires Dovecot "
   103             raise AErr(_(u"The mailbox format '%(mbfmt)s' requires Dovecot "
   104                          u">= v%(version)s") % {'mbfmt': maillocation.mbformat,
   104                          u">= v%(version)s.") % {
       
   105                        'mbfmt': maillocation.mbformat,
   105                        'version': version_str(maillocation.dovecot_version)},
   106                        'version': version_str(maillocation.dovecot_version)},
   106                        INVALID_MAIL_LOCATION)
   107                        INVALID_MAIL_LOCATION)
   107         if not maillocation.postfix and \
   108         if not maillocation.postfix and \
   108           self._transport.transport.lower() in ('virtual:', 'virtual'):
   109           self._transport.transport.lower() in ('virtual:', 'virtual'):
   109             raise AErr(_(u"Invalid transport '%(transport)s' for mailbox "
   110             raise AErr(_(u"Invalid transport '%(transport)s' for mailbox "
   110                          u"format '%(mbfmt)s'") %
   111                          u"format '%(mbfmt)s'.") %
   111                        {'transport': self._transport,
   112                        {'transport': self._transport,
   112                         'mbfmt': maillocation.mbformat}, INVALID_MAIL_LOCATION)
   113                         'mbfmt': maillocation.mbformat}, INVALID_MAIL_LOCATION)
   113         self._mail = maillocation
   114         self._mail = maillocation
   114         self._set_uid()
   115         self._set_uid()
   115 
   116 
   177 
   178 
   178     def _chk_state(self):
   179     def _chk_state(self):
   179         """Raise an AccountError if the Account is new - not yet saved in the
   180         """Raise an AccountError if the Account is new - not yet saved in the
   180         database."""
   181         database."""
   181         if self._new:
   182         if self._new:
   182             raise AErr(_(u"The account '%s' doesn't exist.") % self._addr,
   183             raise AErr(_(u"The account '%s' does not exist.") % self._addr,
   183                        NO_SUCH_ACCOUNT)
   184                        NO_SUCH_ACCOUNT)
   184 
   185 
   185     @property
   186     @property
   186     def address(self):
   187     def address(self):
   187         """The Account's EmailAddress instance."""
   188         """The Account's EmailAddress instance."""
   261         """Save the new Account in the database."""
   262         """Save the new Account in the database."""
   262         if not self._new:
   263         if not self._new:
   263             raise AErr(_(u"The account '%s' already exists.") % self._addr,
   264             raise AErr(_(u"The account '%s' already exists.") % self._addr,
   264                        ACCOUNT_EXISTS)
   265                        ACCOUNT_EXISTS)
   265         if not self._passwd:
   266         if not self._passwd:
   266             raise AErr(_(u"No password set for '%s'.") % self._addr,
   267             raise AErr(_(u"No password set for account: '%s'") % self._addr,
   267                        ACCOUNT_MISSING_PASSWORD)
   268                        ACCOUNT_MISSING_PASSWORD)
   268         if cfg_dget('misc.dovecot_version') >= 0x10200b02:
   269         if cfg_dget('misc.dovecot_version') >= 0x10200b02:
   269             sieve_col = 'sieve'
   270             sieve_col = 'sieve'
   270         else:
   271         else:
   271             sieve_col = 'managesieve'
   272             sieve_col = 'managesieve'
   319         `quotalimit` : VirtualMailManager.quotalimit.QuotaLimit
   320         `quotalimit` : VirtualMailManager.quotalimit.QuotaLimit
   320           the new quota limit of the domain.
   321           the new quota limit of the domain.
   321         """
   322         """
   322         if cfg_dget('misc.dovecot_version') < 0x10102f00:
   323         if cfg_dget('misc.dovecot_version') < 0x10102f00:
   323             raise VMMError(_(u'PostgreSQL-based dictionary quota requires '
   324             raise VMMError(_(u'PostgreSQL-based dictionary quota requires '
   324                              u'Dovecot >= v1.1.2'), VMM_ERROR)
   325                              u'Dovecot >= v1.1.2.'), VMM_ERROR)
   325         self._chk_state()
   326         self._chk_state()
   326         assert isinstance(quotalimit, QuotaLimit)
   327         assert isinstance(quotalimit, QuotaLimit)
   327         if quotalimit == self._qlimit:
   328         if quotalimit == self._qlimit:
   328             return
   329             return
   329         self._update_tables('qid', quotalimit.qid)
   330         self._update_tables('qid', quotalimit.qid)
   342         if transport == self._transport:
   343         if transport == self._transport:
   343             return
   344             return
   344         if transport.transport.lower() in ('virtual', 'virtual:') and \
   345         if transport.transport.lower() in ('virtual', 'virtual:') and \
   345            not self._mail.postfix:
   346            not self._mail.postfix:
   346             raise AErr(_(u"Invalid transport '%(transport)s' for mailbox "
   347             raise AErr(_(u"Invalid transport '%(transport)s' for mailbox "
   347                          u"format '%(mbfmt)s'") %
   348                          u"format '%(mbfmt)s'.") %
   348                        {'transport': transport, 'mbfmt': self._mail.mbformat},
   349                        {'transport': transport, 'mbfmt': self._mail.mbformat},
   349                        INVALID_MAIL_LOCATION)
   350                        INVALID_MAIL_LOCATION)
   350         self._update_tables('tid', transport.tid)
   351         self._update_tables('tid', transport.tid)
   351         self._transport = transport
   352         self._transport = transport
   352 
   353 
   473                 "(domain_name.gid = users.gid AND is_primary) WHERE uid = %s",
   474                 "(domain_name.gid = users.gid AND is_primary) WHERE uid = %s",
   474                 (uid,))
   475                 (uid,))
   475     info = dbc.fetchone()
   476     info = dbc.fetchone()
   476     dbc.close()
   477     dbc.close()
   477     if not info:
   478     if not info:
   478         raise AErr(_(u"There is no account with the UID '%d'.") % uid,
   479         raise AErr(_(u"There is no account with the UID: '%d'") % uid,
   479                    NO_SUCH_ACCOUNT)
   480                    NO_SUCH_ACCOUNT)
   480     info = dict(zip(('address', 'uid', 'gid'), info))
   481     info = dict(zip(('address', 'uid', 'gid'), info))
   481     return info
   482     return info
   482 
   483 
   483 del _, cfg_dget
   484 del _, cfg_dget