VirtualMailManager/common.py
changeset 614 1ec3497a6733
parent 611 8e9b0046bc8f
child 643 df1e3b67882a
child 675 d24f094d1cb5
equal deleted inserted replaced
613:7b3494f1a2ef 614:1ec3497a6733
    12 import os
    12 import os
    13 import re
    13 import re
    14 import stat
    14 import stat
    15 
    15 
    16 from VirtualMailManager import ENCODING
    16 from VirtualMailManager import ENCODING
    17 from VirtualMailManager.constants import NOT_EXECUTABLE, NO_SUCH_BINARY, \
    17 from VirtualMailManager.constants import INVALID_MAIL_LOCATION, \
    18      TYPE_ACCOUNT, TYPE_ALIAS, TYPE_RELOCATED
    18      NOT_EXECUTABLE, NO_SUCH_BINARY, TYPE_ACCOUNT, TYPE_ALIAS, TYPE_RELOCATED
    19 from VirtualMailManager.errors import VMMError
    19 from VirtualMailManager.errors import VMMError
    20 
    20 
    21 VERSION_RE = re.compile(r'^(\d+)\.(\d+)\.(?:(\d+)|(alpha|beta|rc)(\d+))$')
    21 VERSION_RE = re.compile(r'^(\d+)\.(\d+)\.(?:(\d+)|(alpha|beta|rc)(\d+))$')
    22 
    22 
    23 _version_level = dict(alpha=0xA, beta=0xB, rc=0xC)
    23 _version_level = dict(alpha=0xA, beta=0xB, rc=0xC)
   117         try:
   117         try:
   118             num = int(size)
   118             num = int(size)
   119         except ValueError:
   119         except ValueError:
   120             raise ValueError('Not a valid size value: %r' % size)
   120             raise ValueError('Not a valid size value: %r' % size)
   121         return num
   121         return num
       
   122 
       
   123 
       
   124 def validate_transport(transport, maillocation):
       
   125     """Checks if the `transport` is usable for the given `maillocation`.
       
   126 
       
   127     Throws a `VMMError` if the chosen `transport` is unable to write
       
   128     messages in the `maillocation`'s mailbox format.
       
   129 
       
   130     Arguments:
       
   131 
       
   132     `transport` : VirtualMailManager.transport.Transport
       
   133       a Transport object
       
   134     `maillocation` : VirtualMailManager.maillocation.MailLocation
       
   135       a MailLocation object
       
   136     """
       
   137     if transport.transport in ('virtual', 'virtual:') and \
       
   138       not maillocation.postfix:
       
   139         raise VMMError(_(u"Invalid transport '%(transport)s' for mailbox "
       
   140                          u"format '%(mbfmt)s'.") %
       
   141                        {'transport': transport.transport,
       
   142                         'mbfmt': maillocation.mbformat}, INVALID_MAIL_LOCATION)
   122 
   143 
   123 
   144 
   124 def version_hex(version_string):
   145 def version_hex(version_string):
   125     """Converts a Dovecot version, e.g.: '1.2.3' or '2.0.beta4', to an int.
   146     """Converts a Dovecot version, e.g.: '1.2.3' or '2.0.beta4', to an int.
   126     Raises a `ValueError` if the *version_string* has the wrong™ format.
   147     Raises a `ValueError` if the *version_string* has the wrong™ format.