VirtualMailManager/mailbox.py
author Pascal Volk <neverseen@users.sourceforge.net>
Mon, 26 Jul 2010 03:08:57 +0000
branchv0.6.x
changeset 313 c17c46d9e440
parent 309 d21423478803
child 316 31d8931dc535
permissions -rw-r--r--
VMM/cli/Config: Write warnings to stderr. Renamed method __saveChanges to __save_changes.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
309
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
     1
# -*- coding: UTF-8 -*-
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
     2
# Copyright (c) 2010, Pascal Volk
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
     3
# See COPYING for distribution information.
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
     4
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
     5
"""
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
     6
    VirtualMailManager.mailbox
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
     7
    ~~~~~~~~~~~~~~~~~~~~~~~~~~
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
     8
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
     9
    VirtualMailManager's mailbox classes for the Maildir, single dbox
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    10
    (sdbox) and multi dbox (mdbox) mailbox formats.
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    11
"""
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    12
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    13
import os
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    14
import re
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    15
from binascii import a2b_base64, b2a_base64
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    16
from subprocess import Popen, PIPE
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    17
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    18
from VirtualMailManager.Account import Account
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    19
from VirtualMailManager.common import is_dir
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    20
from VirtualMailManager.errors import VMMError
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    21
from VirtualMailManager.constants.ERROR import VMM_ERROR
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    22
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    23
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    24
__all__ = ('new', 'Maildir', 'SingleDbox', 'MultiDbox',
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    25
           'utf8_to_mutf7', 'mutf7_to_utf8')
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    26
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    27
cfg_dget = lambda option: None
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    28
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    29
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    30
def _mbase64_encode(inp, dest):
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    31
    if inp:
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    32
        mb64 = b2a_base64(''.join(inp).encode('utf-16be'))
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    33
        dest.append('&%s-' % mb64.rstrip('\n=').replace('/', ','))
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    34
        del inp[:]
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    35
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    36
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    37
def _mbase64_to_unicode(mb64):
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    38
    return unicode(a2b_base64(mb64.replace(',', '/') + '==='), 'utf-16be')
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    39
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    40
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    41
def utf8_to_mutf7(src):
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    42
    """
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    43
    Converts the international mailbox name `src` into a modified
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    44
    version version of the UTF-7 encoding.
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    45
    """
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    46
    ret = []
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    47
    tmp = []
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    48
    for c in src:
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    49
        ordc = ord(c)
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    50
        if 0x20 <= ordc <= 0x25 or 0x27 <= ordc <= 0x7E:
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    51
            _mbase64_encode(tmp, ret)
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    52
            ret.append(c)
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    53
        elif ordc == 0x26:
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    54
            _mbase64_encode(tmp, ret)
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    55
            ret.append('&-')
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    56
        else:
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    57
            tmp.append(c)
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    58
    _mbase64_encode(tmp, ret)
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    59
    return ''.join(ret)
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    60
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    61
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    62
def mutf7_to_utf8(src):
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    63
    """
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    64
    Converts the mailbox name `src` from modified UTF-7 encoding to UTF-8.
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    65
    """
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    66
    ret = []
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    67
    tmp = []
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    68
    for c in src:
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    69
        if c == '&' and not tmp:
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    70
            tmp.append(c)
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    71
        elif c == '-' and tmp:
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    72
            if len(tmp) is 1:
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    73
                ret.append('&')
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    74
            else:
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    75
                ret.append(_mbase64_to_unicode(''.join(tmp[1:])))
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    76
            tmp = []
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    77
        elif tmp:
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    78
            tmp.append(c)
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    79
        else:
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    80
            ret.append(c)
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    81
    if tmp:
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    82
        ret.append(_mbase64_to_unicode(''.join(tmp[1:])))
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    83
    return ''.join(ret)
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    84
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    85
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    86
class Mailbox(object):
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    87
    """Base class of all mailbox classes."""
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    88
    __slots__ = ('_boxes', '_root', '_sep', '_user')
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    89
    FILE_MODE = 0600
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    90
    _ctrl_chr_re = re.compile('[\x00-\x1F\x7F-\x9F]')
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    91
    _box_name_re = re.compile('^[\x20-\x25\x27-\x7E]+$')
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    92
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    93
    def __init__(self, account):
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    94
        """
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    95
        Creates a new mailbox instance.
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    96
        Use one of the `Maildir`, `SingleDbox` or `MultiDbox` classes.
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    97
        """
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    98
        assert isinstance(account, Account)
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    99
        is_dir(account.home)
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   100
        self._user = account
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   101
        self._boxes = []
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   102
        self._root = self._user.mail_location.directory
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   103
        self._sep = '/'
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   104
        os.chdir(self._user.home)
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   105
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   106
    def _add_boxes(self, mailboxes, subscribe):
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   107
        raise NotImplementedError
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   108
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   109
    def _validate_box_name(self, name, good, bad):
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   110
        """
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   111
        Validates the mailboxes name `name`.  When the name is valid, it
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   112
        will be added to the `good` set.  Invalid mailbox names will be
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   113
        appended to the `bad` list.
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   114
        """
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   115
        name = name.strip()
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   116
        if not name:
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   117
            return
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   118
        if self.__class__._ctrl_chr_re.search(name):  # no control chars
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   119
            bad.append(name)
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   120
            return
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   121
        if name[0] in (self._sep, '~'):
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   122
            bad.append(name)
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   123
            return
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   124
        if self._sep == '/':
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   125
            if '//' in name or '/./' in name or '/../' in name or \
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   126
               name.startswith('../'):
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   127
                bad.append(name)
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   128
                return
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   129
        if '/' in name or '..' in name:
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   130
            bad.append(name)
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   131
            return
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   132
        if not self.__class__._box_name_re.match(name):
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   133
            tmp = utf8_to_mutf7(name)
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   134
            if name == mutf7_to_utf8(tmp):
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   135
                if self._user.mail_location.mbformat == 'maildir':
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   136
                    good.add(tmp)
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   137
                else:
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   138
                    good.add(name)
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   139
                return
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   140
            else:
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   141
                bad.append(name)
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   142
                return
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   143
        good.add(name)
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   144
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   145
    def add_boxes(self, mailboxes, subscribe):
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   146
        """
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   147
        Create all mailboxes from the `mailboxes` list in the user's
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   148
        mail directory.  When `subscribe` is ``True`` all created mailboxes
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   149
        will be listed in the subscriptions file.
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   150
        Returns a list of invalid mailbox names, if any.
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   151
        """
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   152
        assert isinstance(mailboxes, list) and isinstance(subscribe, bool)
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   153
        good = set()
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   154
        bad = []
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   155
        for box in mailboxes:
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   156
            self._validate_box_name(box, good, bad)
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   157
        self._add_boxes(good, subscribe)
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   158
        return bad
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   159
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   160
    def create(self):
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   161
        """Create the INBOX in the user's mail directory."""
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   162
        raise NotImplementedError
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   163
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   164
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   165
class Maildir(Mailbox):
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   166
    """Class for Maildir++ mailboxes."""
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   167
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   168
    __slots__ = ('_subdirs')
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   169
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   170
    def __init__(self, account):
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   171
        """
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   172
        Create a new Maildir++ instance.
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   173
        Call the instance's create() method, in order to create the INBOX.
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   174
        For additional mailboxes use the add_boxes() method.
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   175
        """
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   176
        super(self.__class__, self).__init__(account)
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   177
        self._sep = '.'
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   178
        self._subdirs = ('cur', 'new', 'tmp')
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   179
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   180
    def _create_maildirfolder_file(self, path):
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   181
        """Mark the Maildir++ folder as Maildir folder."""
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   182
        maildirfolder_file = os.path.join(self._sep + path, 'maildirfolder')
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   183
        os.close(os.open(maildirfolder_file, os.O_CREAT | os.O_WRONLY,
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   184
                         self.__class__.FILE_MODE))
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   185
        os.chown(maildirfolder_file, self._user.uid, self._user.gid)
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   186
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   187
    def _make_maildir(self, path):
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   188
        """
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   189
        Create Maildir++ folders with the cur, new and tmp subdirectories.
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   190
        """
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   191
        mode = cfg_dget('account.directory_mode')
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   192
        uid = self._user.uid
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   193
        gid = self._user.gid
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   194
        os.mkdir(path, mode)
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   195
        os.chown(path, uid, gid)
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   196
        for subdir in self._subdirs:
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   197
            dir_ = os.path.join(path, subdir)
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   198
            os.mkdir(dir_, mode)
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   199
            os.chown(dir_, uid, gid)
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   200
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   201
    def _subscribe_boxes(self):
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   202
        """Writes all created mailboxes to the subscriptions file."""
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   203
        if not self._boxes:
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   204
            return
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   205
        subscriptions = open('subscriptions', 'w')
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   206
        subscriptions.write('\n'.join(self._boxes))
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   207
        subscriptions.write('\n')
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   208
        subscriptions.flush()
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   209
        subscriptions.close()
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   210
        os.chown('subscriptions', self._user.uid, self._user.gid)
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   211
        os.chmod('subscriptions', self.__class__.FILE_MODE)
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   212
        del self._boxes[:]
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   213
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   214
    def _add_boxes(self, mailboxes, subscribe):
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   215
        for mailbox in mailboxes:
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   216
            self._make_maildir(self._sep + mailbox)
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   217
            self._create_maildirfolder_file(mailbox)
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   218
            self._boxes.append(mailbox)
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   219
        if subscribe:
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   220
            self._subscribe_boxes()
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   221
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   222
    def create(self):
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   223
        """Creates a Maildir++ INBOX."""
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   224
        self._make_maildir(self._root)
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   225
        os.chdir(self._root)
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   226
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   227
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   228
class SingleDbox(Mailbox):
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   229
    """
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   230
    Class for (single) dbox mailboxes.
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   231
    See http://wiki.dovecot.org/MailboxFormat/dbox for details.
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   232
    """
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   233
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   234
    __slots__ = ()
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   235
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   236
    def __init__(self, account):
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   237
        """
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   238
        Create a new dbox instance.
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   239
        Call the instance's create() method, in order to create the INBOX.
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   240
        For additional mailboxes use the add_boxes() method.
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   241
        """
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   242
        assert cfg_dget('misc.dovecot_version') >= \
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   243
                account.mail_location.dovecot_version
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   244
        super(SingleDbox, self).__init__(account)
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   245
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   246
    def _doveadm_create(self, mailboxes, subscribe):
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   247
        """Wrap around Dovecot's doveadm"""
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   248
        cmd_args = [cfg_dget('bin.dovecotpw'), 'mailbox', 'create', '-u',
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   249
                    str(self._user.address)]
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   250
        if subscribe:
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   251
            cmd_args.append('-s')
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   252
        cmd_args.extend(mailboxes)
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   253
        print '\n -> %r\n' % cmd_args
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   254
        process = Popen(cmd_args, stdout=PIPE, stderr=PIPE)
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   255
        stdout, stderr = process.communicate()
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   256
        if process.returncode:
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   257
            raise VMMError(stderr.strip(), VMM_ERROR)
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   258
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   259
    def create(self):
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   260
        """Create a dbox INBOX"""
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   261
        os.mkdir(self._root, cfg_dget('account.directory_mode'))
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   262
        os.chown(self._root, self._user.uid, self._user.gid)
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   263
        self._doveadm_create(('INBOX',), False)
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   264
        os.chdir(self._root)
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   265
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   266
    def _add_boxes(self, mailboxes, subscribe):
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   267
        self._doveadm_create(mailboxes, subscribe)
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   268
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   269
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   270
class MultiDbox(SingleDbox):
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   271
    """
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   272
    Class for multi dbox mailboxes.
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   273
    See http://wiki.dovecot.org/MailboxFormat/dbox#Multi-dbox for details.
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   274
    """
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   275
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   276
    __slots__ = ()
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   277
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   278
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   279
def __get_mailbox_class(mbfmt):
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   280
    if mbfmt == 'maildir':
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   281
        return Maildir
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   282
    elif mbfmt == 'mdbox':
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   283
        return MultiDbox
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   284
    elif mbfmt == 'sdbox':
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   285
        return SingleDbox
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   286
    raise ValueError('unsupported mailbox format: %r' % mbfmt)
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   287
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   288
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   289
def new(account):
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   290
    """Create a new Mailbox instance for the given Account."""
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   291
    return __get_mailbox_class(account.mail_location.mbformat)(account)
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   292
d21423478803 VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   293
del cfg_dget