Changeset View
Standalone View
cyruslib.py
Show All 16 Lines | |||||
# You should have received a copy of the GNU General Public License | # You should have received a copy of the GNU General Public License | ||||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
# | # | ||||
# Requires python >= 2.3 | # Requires python >= 2.3 | ||||
# | # | ||||
__version__ = '0.8.5' | __version__ = '0.8.5' | ||||
__all__ = [ 'CYRUS' ] | __all__ = [ 'CYRUS' ] | ||||
Lint: PEP8 E201: whitespace after '[' | |||||
Lint: PEP8 E202 whitespace before ']' Lint: PEP8 E202: whitespace before ']' | |||||
__doc__ = """Cyrus admin wrapper | __doc__ = """Cyrus admin wrapper | ||||
Adds cyrus-specific commands to imaplib IMAP4 Class | Adds cyrus-specific commands to imaplib IMAP4 Class | ||||
and defines new CYRUS class for cyrus imapd commands | and defines new CYRUS class for cyrus imapd commands | ||||
""" | """ | ||||
from sys import exit, stdout | from sys import exit, stdout | ||||
Lint: PEP8 E402 module level import not at top of file Lint: PEP8 E402: module level import not at top of file | |||||
try: | try: | ||||
import imaplib | import imaplib | ||||
import re | import re | ||||
from binascii import b2a_base64 | from binascii import b2a_base64 | ||||
except ImportError, e: | except ImportError, e: | ||||
print e | print e | ||||
exit(1) | exit(1) | ||||
Commands = { | Commands = { | ||||
'RECONSTRUCT' : ('AUTH',), | 'RECONSTRUCT' : ('AUTH',), | ||||
Lint: PEP8 E203 whitespace before ':' Lint: PEP8 E203: whitespace before ':' | |||||
'DUMP' : ('AUTH',), # To check admin status | 'DUMP' : ('AUTH',), # To check admin status | ||||
Lint: PEP8 E203 whitespace before ':' Lint: PEP8 E203: whitespace before ':' | |||||
Lint: PEP8 E261 at least two spaces before inline comment Lint: PEP8 E261: at least two spaces before inline comment | |||||
'ID' : ('AUTH',), # Only one ID allowed in non auth mode | 'ID' : ('AUTH',), # Only one ID allowed in non auth mode | ||||
Lint: PEP8 E203 whitespace before ':' Lint: PEP8 E203: whitespace before ':' | |||||
Lint: PEP8 E261 at least two spaces before inline comment Lint: PEP8 E261: at least two spaces before inline comment | |||||
'GETANNOTATION': ('AUTH',), | 'GETANNOTATION': ('AUTH',), | ||||
'SETANNOTATION': ('AUTH',), | 'SETANNOTATION': ('AUTH',), | ||||
'XFER' : ('AUTH',) | 'XFER' : ('AUTH',) | ||||
Lint: PEP8 E203 whitespace before ':' Lint: PEP8 E203: whitespace before ':' | |||||
} | } | ||||
imaplib.Commands.update(Commands) | imaplib.Commands.update(Commands) | ||||
DEFAULT_SEP = '.' | DEFAULT_SEP = '.' | ||||
QUOTE = '"' | QUOTE = '"' | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
DQUOTE = '""' | DQUOTE = '""' | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
re_ns = re.compile(r'.*\(\(\".*(\.|/)\"\)\).*') | re_ns = re.compile(r'.*\(\(\".*(\.|/)\"\)\).*') | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
re_q0 = re.compile(r'(.*)\s\(\)') | re_q0 = re.compile(r'(.*)\s\(\)') | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
re_q = re.compile(r'(.*)\s\(STORAGE (\d+) (\d+)\)') | re_q = re.compile(r'(.*)\s\(STORAGE (\d+) (\d+)\)') | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
re_mb = re.compile(r'\((.*)\)\s\".\"\s(.*)') | re_mb = re.compile(r'\((.*)\)\s\".\"\s(.*)') | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
re_url = re.compile(r'^(imaps?)://(.+?):?(\d{0,5})$') | re_url = re.compile(r'^(imaps?)://(.+?):?(\d{0,5})$') | ||||
def ok(res): | def ok(res): | ||||
Lint: PEP8 E302 expected 2 blank lines, found 1 Lint: PEP8 E302: expected 2 blank lines, found 1 | |||||
return res.upper().startswith('OK') | return res.upper().startswith('OK') | ||||
def quote(text, qchar=QUOTE): | def quote(text, qchar=QUOTE): | ||||
Lint: PEP8 E302 expected 2 blank lines, found 1 Lint: PEP8 E302: expected 2 blank lines, found 1 | |||||
return text.join([qchar, qchar]) | return text.join([qchar, qchar]) | ||||
def unquote(text, qchar=QUOTE): | def unquote(text, qchar=QUOTE): | ||||
Lint: PEP8 E302 expected 2 blank lines, found 1 Lint: PEP8 E302: expected 2 blank lines, found 1 | |||||
return ''.join(text.split(qchar)) | return ''.join(text.split(qchar)) | ||||
def getflags(test): | def getflags(test): | ||||
Lint: PEP8 E302 expected 2 blank lines, found 1 Lint: PEP8 E302: expected 2 blank lines, found 1 | |||||
flags = [] | flags = [] | ||||
for flag in test.split('\\'): | for flag in test.split('\\'): | ||||
flag = flag.strip() | flag = flag.strip() | ||||
if len(flag): flags.append(flag) | if len(flag): flags.append(flag) | ||||
Lint: PEP8 E701 multiple statements on one line (colon) Lint: PEP8 E701: multiple statements on one line (colon) | |||||
return flags | return flags | ||||
### A smart function to return an array of split strings | ### A smart function to return an array of split strings | ||||
Lint: PEP8 E266 too many leading '#' for block comment Lint: PEP8 E266: too many leading '#' for block comment | |||||
### and honours quoted strings | ### and honours quoted strings | ||||
Lint: PEP8 E266 too many leading '#' for block comment Lint: PEP8 E266: too many leading '#' for block comment | |||||
def splitquote(text): | def splitquote(text): | ||||
Lint: PEP8 E302 expected 2 blank lines, found 1 Lint: PEP8 E302: expected 2 blank lines, found 1 | |||||
data = text.split(QUOTE) | data = text.split(QUOTE) | ||||
if len(data) == 1: # no quotes | if len(data) == 1: # no quotes | ||||
Lint: PEP8 E261 at least two spaces before inline comment Lint: PEP8 E261: at least two spaces before inline comment | |||||
res = data[0].split() | res = data[0].split() | ||||
else: | else: | ||||
res = [] | res = [] | ||||
for match in data: | for match in data: | ||||
if len(match.strip()) == 0: continue | if len(match.strip()) == 0: continue | ||||
Lint: PEP8 E701 multiple statements on one line (colon) Lint: PEP8 E701: multiple statements on one line (colon) | |||||
if match[0] == ' ': | if match[0] == ' ': | ||||
res = res + match.strip().split() | res = res + match.strip().split() | ||||
else: | else: | ||||
res.append(match) | res.append(match) | ||||
return res | return res | ||||
### return a dictionary from a cyrus info response | ### return a dictionary from a cyrus info response | ||||
Lint: PEP8 E266 too many leading '#' for block comment Lint: PEP8 E266: too many leading '#' for block comment | |||||
def res2dict(data): | def res2dict(data): | ||||
Lint: PEP8 E302 expected 2 blank lines, found 1 Lint: PEP8 E302: expected 2 blank lines, found 1 | |||||
data = splitquote(data) | data = splitquote(data) | ||||
datalen = len(data) | datalen = len(data) | ||||
if datalen % 2: # Unmatched pair | if datalen % 2: # Unmatched pair | ||||
Lint: PEP8 E261 at least two spaces before inline comment Lint: PEP8 E261: at least two spaces before inline comment | |||||
return False, {} | return False, {} | ||||
res = {} | res = {} | ||||
for i in range(0, datalen, 2): | for i in range(0, datalen, 2): | ||||
res[data[i]] = data[i+1] | res[data[i]] = data[i+1] | ||||
return True, res | return True, res | ||||
class CYRUSError(Exception): pass | class CYRUSError(Exception): pass | ||||
Lint: PEP8 E701 multiple statements on one line (colon) Lint: PEP8 E701: multiple statements on one line (colon) | |||||
class IMAP4(imaplib.IMAP4): | class IMAP4(imaplib.IMAP4): | ||||
Lint: PEP8 E302 expected 2 blank lines, found 1 Lint: PEP8 E302: expected 2 blank lines, found 1 | |||||
def getsep(self): | def getsep(self): | ||||
"""Get mailbox separator""" | """Get mailbox separator""" | ||||
### yes, ugly but cyradm does it in the same way | ### yes, ugly but cyradm does it in the same way | ||||
Lint: PEP8 E266 too many leading '#' for block comment Lint: PEP8 E266: too many leading '#' for block comment | |||||
### also more realable then calling NAMESPACE | ### also more realable then calling NAMESPACE | ||||
Lint: PEP8 E266 too many leading '#' for block comment Lint: PEP8 E266: too many leading '#' for block comment | |||||
### and it should be also compatibile with other servers | ### and it should be also compatibile with other servers | ||||
Lint: PEP8 E266 too many leading '#' for block comment Lint: PEP8 E266: too many leading '#' for block comment | |||||
try: | try: | ||||
return unquote(self.list(DQUOTE, DQUOTE)[1][0]).split()[1] | return unquote(self.list(DQUOTE, DQUOTE)[1][0]).split()[1] | ||||
except: | except: | ||||
return DEFAULT_SEP | return DEFAULT_SEP | ||||
def isadmin(self): | def isadmin(self): | ||||
### A trick to check if the user is admin or not | ### A trick to check if the user is admin or not | ||||
Lint: PEP8 E266 too many leading '#' for block comment Lint: PEP8 E266: too many leading '#' for block comment | |||||
### normal users cannot use dump command | ### normal users cannot use dump command | ||||
Lint: PEP8 E266 too many leading '#' for block comment Lint: PEP8 E266: too many leading '#' for block comment | |||||
try: | try: | ||||
res, msg = self._simple_command('DUMP', 'NIL') | res, msg = self._simple_command('DUMP', 'NIL') | ||||
if msg[0].lower().find('denied') == -1: | if msg[0].lower().find('denied') == -1: | ||||
return True | return True | ||||
except: | except: | ||||
pass | pass | ||||
return False | return False | ||||
def id(self): | def id(self): | ||||
try: | try: | ||||
typ, dat = self._simple_command('ID', 'NIL') | typ, dat = self._simple_command('ID', 'NIL') | ||||
res, dat = self._untagged_response(typ, dat, 'ID') | res, dat = self._untagged_response(typ, dat, 'ID') | ||||
except: | except: | ||||
return False, dat[0] | return False, dat[0] | ||||
return ok(res), dat[0] | return ok(res), dat[0] | ||||
def getannotation(self, mailbox, pattern='*', shared=None): | def getannotation(self, mailbox, pattern='*', shared=None): | ||||
if shared == None: | if shared == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
typ, dat = self._simple_command('GETANNOTATION', mailbox, quote(pattern), quote('*')) | typ, dat = self._simple_command('GETANNOTATION', mailbox, quote(pattern), quote('*')) | ||||
Lint: PEP8 E501 line too long (97 > 79 characters) Lint: PEP8 E501: line too long (97 > 79 characters) | |||||
elif shared: | elif shared: | ||||
typ, dat = self._simple_command('GETANNOTATION', mailbox, quote(pattern), quote('value.shared')) | typ, dat = self._simple_command('GETANNOTATION', mailbox, quote(pattern), quote('value.shared')) | ||||
Lint: PEP8 E501 line too long (108 > 79 characters) Lint: PEP8 E501: line too long (108 > 79 characters) | |||||
else: | else: | ||||
typ, dat = self._simple_command('GETANNOTATION', mailbox, quote(pattern), quote('value.priv')) | typ, dat = self._simple_command('GETANNOTATION', mailbox, quote(pattern), quote('value.priv')) | ||||
Lint: PEP8 E501 line too long (106 > 79 characters) Lint: PEP8 E501: line too long (106 > 79 characters) | |||||
return self._untagged_response(typ, dat, 'ANNOTATION') | return self._untagged_response(typ, dat, 'ANNOTATION') | ||||
def setannotation(self, mailbox, desc, value, shared=False): | def setannotation(self, mailbox, desc, value, shared=False): | ||||
if value: | if value: | ||||
value = quote(value) | value = quote(value) | ||||
else: | else: | ||||
value = "NIL" | value = "NIL" | ||||
if shared: | if shared: | ||||
typ, dat = self._simple_command('SETANNOTATION', mailbox, quote(desc), "(%s %s)" % (quote('value.shared'), value) ) | typ, dat = self._simple_command('SETANNOTATION', mailbox, quote(desc), "(%s %s)" % (quote('value.shared'), value) ) | ||||
Lint: PEP8 E501 line too long (127 > 79 characters) Lint: PEP8 E501: line too long (127 > 79 characters) | |||||
Lint: PEP8 E202 whitespace before ')' Lint: PEP8 E202: whitespace before ')' | |||||
else: | else: | ||||
typ, dat = self._simple_command('SETANNOTATION', mailbox, quote(desc), "(%s %s)" % (quote('value.priv'), value) ) | typ, dat = self._simple_command('SETANNOTATION', mailbox, quote(desc), "(%s %s)" % (quote('value.priv'), value) ) | ||||
Lint: PEP8 E501 line too long (125 > 79 characters) Lint: PEP8 E501: line too long (125 > 79 characters) | |||||
Lint: PEP8 E202 whitespace before ')' Lint: PEP8 E202: whitespace before ')' | |||||
return self._untagged_response(typ, dat, 'ANNOTATION') | return self._untagged_response(typ, dat, 'ANNOTATION') | ||||
def setquota(self, mailbox, limit): | def setquota(self, mailbox, limit): | ||||
"""Set quota of a mailbox""" | """Set quota of a mailbox""" | ||||
if limit == 0: | if limit == 0: | ||||
quota = '()' | quota = '()' | ||||
else: | else: | ||||
quota = '(STORAGE %s)' % limit | quota = '(STORAGE %s)' % limit | ||||
return self._simple_command('SETQUOTA', mailbox, quota) | return self._simple_command('SETQUOTA', mailbox, quota) | ||||
### Overridden to support partition | ### Overridden to support partition | ||||
Lint: PEP8 E266 too many leading '#' for block comment Lint: PEP8 E266: too many leading '#' for block comment | |||||
### Pychecker will complain about non matching signature | ### Pychecker will complain about non matching signature | ||||
Lint: PEP8 E266 too many leading '#' for block comment Lint: PEP8 E266: too many leading '#' for block comment | |||||
def create(self, mailbox, partition=None): | def create(self, mailbox, partition=None): | ||||
"""Create a mailbox, partition is optional""" | """Create a mailbox, partition is optional""" | ||||
if partition is not None: | if partition is not None: | ||||
return self._simple_command('CREATE', mailbox, partition) | return self._simple_command('CREATE', mailbox, partition) | ||||
else: | else: | ||||
return self._simple_command('CREATE', mailbox) | return self._simple_command('CREATE', mailbox) | ||||
### Overridden to support partition | ### Overridden to support partition | ||||
Lint: PEP8 E266 too many leading '#' for block comment Lint: PEP8 E266: too many leading '#' for block comment | |||||
### Pychecker: same here | ### Pychecker: same here | ||||
Lint: PEP8 E266 too many leading '#' for block comment Lint: PEP8 E266: too many leading '#' for block comment | |||||
def rename(self, from_mailbox, to_mailbox, partition=None): | def rename(self, from_mailbox, to_mailbox, partition=None): | ||||
"""Rename a from_mailbox to to_mailbox, partition is optional""" | """Rename a from_mailbox to to_mailbox, partition is optional""" | ||||
if partition is not None: | if partition is not None: | ||||
return self._simple_command('RENAME', from_mailbox, to_mailbox, partition) | return self._simple_command('RENAME', from_mailbox, to_mailbox, partition) | ||||
Lint: PEP8 E501 line too long (86 > 79 characters) Lint: PEP8 E501: line too long (86 > 79 characters) | |||||
else: | else: | ||||
return self._simple_command('RENAME', from_mailbox, to_mailbox) | return self._simple_command('RENAME', from_mailbox, to_mailbox) | ||||
def reconstruct(self, mailbox): | def reconstruct(self, mailbox): | ||||
return self._simple_command('RECONSTRUCT', mailbox) | return self._simple_command('RECONSTRUCT', mailbox) | ||||
class IMAP4_SSL(imaplib.IMAP4_SSL): | class IMAP4_SSL(imaplib.IMAP4_SSL): | ||||
Lint: PEP8 E302 expected 2 blank lines, found 1 Lint: PEP8 E302: expected 2 blank lines, found 1 | |||||
def getsep(self): | def getsep(self): | ||||
"""Get mailbox separator""" | """Get mailbox separator""" | ||||
### yes, ugly but cyradm does it in the same way | ### yes, ugly but cyradm does it in the same way | ||||
Lint: PEP8 E266 too many leading '#' for block comment Lint: PEP8 E266: too many leading '#' for block comment | |||||
### also more realable then calling NAMESPACE | ### also more realable then calling NAMESPACE | ||||
Lint: PEP8 E266 too many leading '#' for block comment Lint: PEP8 E266: too many leading '#' for block comment | |||||
### and it should be also compatibile with other servers | ### and it should be also compatibile with other servers | ||||
Lint: PEP8 E266 too many leading '#' for block comment Lint: PEP8 E266: too many leading '#' for block comment | |||||
try: | try: | ||||
return unquote(self.list(DQUOTE, DQUOTE)[1][0]).split()[1] | return unquote(self.list(DQUOTE, DQUOTE)[1][0]).split()[1] | ||||
except: | except: | ||||
return DEFAULT_SEP | return DEFAULT_SEP | ||||
def isadmin(self): | def isadmin(self): | ||||
### A trick to check if the user is admin or not | ### A trick to check if the user is admin or not | ||||
Lint: PEP8 E266 too many leading '#' for block comment Lint: PEP8 E266: too many leading '#' for block comment | |||||
### normal users cannot use dump command | ### normal users cannot use dump command | ||||
Lint: PEP8 E266 too many leading '#' for block comment Lint: PEP8 E266: too many leading '#' for block comment | |||||
try: | try: | ||||
res, msg = self._simple_command('DUMP', 'NIL') | res, msg = self._simple_command('DUMP', 'NIL') | ||||
if msg[0].lower().find('denied') == -1: | if msg[0].lower().find('denied') == -1: | ||||
return True | return True | ||||
except: | except: | ||||
pass | pass | ||||
return False | return False | ||||
def id(self): | def id(self): | ||||
try: | try: | ||||
typ, dat = self._simple_command('ID', 'NIL') | typ, dat = self._simple_command('ID', 'NIL') | ||||
res, dat = self._untagged_response(typ, dat, 'ID') | res, dat = self._untagged_response(typ, dat, 'ID') | ||||
except: | except: | ||||
return False, dat[0] | return False, dat[0] | ||||
return ok(res), dat[0] | return ok(res), dat[0] | ||||
def getannotation(self, mailbox, pattern='*', shared=None): | def getannotation(self, mailbox, pattern='*', shared=None): | ||||
if shared == None: | if shared == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
typ, dat = self._simple_command('GETANNOTATION', mailbox, quote(pattern), quote('*')) | typ, dat = self._simple_command('GETANNOTATION', mailbox, quote(pattern), quote('*')) | ||||
Lint: PEP8 E501 line too long (97 > 79 characters) Lint: PEP8 E501: line too long (97 > 79 characters) | |||||
elif shared: | elif shared: | ||||
typ, dat = self._simple_command('GETANNOTATION', mailbox, quote(pattern), quote('value.shared')) | typ, dat = self._simple_command('GETANNOTATION', mailbox, quote(pattern), quote('value.shared')) | ||||
Lint: PEP8 E501 line too long (108 > 79 characters) Lint: PEP8 E501: line too long (108 > 79 characters) | |||||
else: | else: | ||||
typ, dat = self._simple_command('GETANNOTATION', mailbox, quote(pattern), quote('value.priv')) | typ, dat = self._simple_command('GETANNOTATION', mailbox, quote(pattern), quote('value.priv')) | ||||
Lint: PEP8 E501 line too long (106 > 79 characters) Lint: PEP8 E501: line too long (106 > 79 characters) | |||||
return self._untagged_response(typ, dat, 'ANNOTATION') | return self._untagged_response(typ, dat, 'ANNOTATION') | ||||
def setannotation(self, mailbox, desc, value, shared=False): | def setannotation(self, mailbox, desc, value, shared=False): | ||||
if value: | if value: | ||||
value = quote(value) | value = quote(value) | ||||
else: | else: | ||||
value = "NIL" | value = "NIL" | ||||
if shared: | if shared: | ||||
typ, dat = self._simple_command('SETANNOTATION', mailbox, quote(desc), "(%s %s)" % (quote('value.shared'), value) ) | typ, dat = self._simple_command('SETANNOTATION', mailbox, quote(desc), "(%s %s)" % (quote('value.shared'), value) ) | ||||
Lint: PEP8 E501 line too long (127 > 79 characters) Lint: PEP8 E501: line too long (127 > 79 characters) | |||||
Lint: PEP8 E202 whitespace before ')' Lint: PEP8 E202: whitespace before ')' | |||||
else: | else: | ||||
typ, dat = self._simple_command('SETANNOTATION', mailbox, quote(desc), "(%s %s)" % (quote('value.priv'), value) ) | typ, dat = self._simple_command('SETANNOTATION', mailbox, quote(desc), "(%s %s)" % (quote('value.priv'), value) ) | ||||
Lint: PEP8 E501 line too long (125 > 79 characters) Lint: PEP8 E501: line too long (125 > 79 characters) | |||||
Lint: PEP8 E202 whitespace before ')' Lint: PEP8 E202: whitespace before ')' | |||||
return self._untagged_response(typ, dat, 'ANNOTATION') | return self._untagged_response(typ, dat, 'ANNOTATION') | ||||
def setquota(self, mailbox, limit): | def setquota(self, mailbox, limit): | ||||
"""Set quota of a mailbox""" | """Set quota of a mailbox""" | ||||
if limit == 0: | if limit == 0: | ||||
quota = '()' | quota = '()' | ||||
else: | else: | ||||
quota = '(STORAGE %s)' % limit | quota = '(STORAGE %s)' % limit | ||||
return self._simple_command('SETQUOTA', mailbox, quota) | return self._simple_command('SETQUOTA', mailbox, quota) | ||||
### Overridden to support partition | ### Overridden to support partition | ||||
Lint: PEP8 E266 too many leading '#' for block comment Lint: PEP8 E266: too many leading '#' for block comment | |||||
### Pychecker will complain about non matching signature | ### Pychecker will complain about non matching signature | ||||
Lint: PEP8 E266 too many leading '#' for block comment Lint: PEP8 E266: too many leading '#' for block comment | |||||
def create(self, mailbox, partition=None): | def create(self, mailbox, partition=None): | ||||
"""Create a mailbox, partition is optional""" | """Create a mailbox, partition is optional""" | ||||
if partition is not None: | if partition is not None: | ||||
return self._simple_command('CREATE', mailbox, partition) | return self._simple_command('CREATE', mailbox, partition) | ||||
else: | else: | ||||
return self._simple_command('CREATE', mailbox) | return self._simple_command('CREATE', mailbox) | ||||
### Overridden to support partition | ### Overridden to support partition | ||||
Lint: PEP8 E266 too many leading '#' for block comment Lint: PEP8 E266: too many leading '#' for block comment | |||||
### Pychecker: same here | ### Pychecker: same here | ||||
Lint: PEP8 E266 too many leading '#' for block comment Lint: PEP8 E266: too many leading '#' for block comment | |||||
def rename(self, from_mailbox, to_mailbox, partition=None): | def rename(self, from_mailbox, to_mailbox, partition=None): | ||||
"""Rename a from_mailbox to to_mailbox, partition is optional""" | """Rename a from_mailbox to to_mailbox, partition is optional""" | ||||
if partition is not None: | if partition is not None: | ||||
return self._simple_command('RENAME', from_mailbox, to_mailbox, partition) | return self._simple_command('RENAME', from_mailbox, to_mailbox, partition) | ||||
Lint: PEP8 E501 line too long (86 > 79 characters) Lint: PEP8 E501: line too long (86 > 79 characters) | |||||
else: | else: | ||||
return self._simple_command('RENAME', from_mailbox, to_mailbox) | return self._simple_command('RENAME', from_mailbox, to_mailbox) | ||||
def reconstruct(self, mailbox): | def reconstruct(self, mailbox): | ||||
return self._simple_command('RECONSTRUCT', mailbox) | return self._simple_command('RECONSTRUCT', mailbox) | ||||
def login_plain(self, admin, password, asUser): | def login_plain(self, admin, password, asUser): | ||||
if asUser: | if asUser: | ||||
encoded = b2a_base64("%s\0%s\0%s" % (asUser, admin, password)).strip() | encoded = b2a_base64("%s\0%s\0%s" % (asUser, admin, password)).strip() | ||||
Lint: PEP8 E501 line too long (82 > 79 characters) Lint: PEP8 E501: line too long (82 > 79 characters) | |||||
else: | else: | ||||
encoded = b2a_base64("%s\0%s\0%s" % (admin, admin, password)).strip() | encoded = b2a_base64("%s\0%s\0%s" % (admin, admin, password)).strip() | ||||
Lint: PEP8 E501 line too long (81 > 79 characters) Lint: PEP8 E501: line too long (81 > 79 characters) | |||||
res, data = self._simple_command('AUTHENTICATE', 'PLAIN', encoded) | res, data = self._simple_command('AUTHENTICATE', 'PLAIN', encoded) | ||||
if ok(res): | if ok(res): | ||||
self.state = 'AUTH' | self.state = 'AUTH' | ||||
return res, data | return res, data | ||||
class CYRUS: | class CYRUS: | ||||
ERROR = {} | ERROR = {} | ||||
ERROR["CONNECT"] = [0, "Connection error"] | ERROR["CONNECT"] = [0, "Connection error"] | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
ERROR["INVALID_URL"] = [1, "Invalid URL"] | ERROR["INVALID_URL"] = [1, "Invalid URL"] | ||||
ERROR["ENCODING"] = [3, "Invalid encondig"] | ERROR["ENCODING"] = [3, "Invalid encondig"] | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
ERROR["MBXNULL"] = [5, "Mailbox is Null"] | ERROR["MBXNULL"] = [5, "Mailbox is Null"] | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
ERROR["NOAUTH"] = [7, "Connection is not authenticated"] | ERROR["NOAUTH"] = [7, "Connection is not authenticated"] | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
ERROR["LOGIN"] = [10, "User or password is wrong"] | ERROR["LOGIN"] = [10, "User or password is wrong"] | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
ERROR["ADMIN"] = [11, "User is not cyrus administrator"] | ERROR["ADMIN"] = [11, "User is not cyrus administrator"] | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
ERROR["AUTH"] = [12, "Connection already authenticated"] | ERROR["AUTH"] = [12, "Connection already authenticated"] | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
ERROR["LOGINPLAIN"] = [15, "Encryption needed to use mechanism"] | ERROR["LOGINPLAIN"] = [15, "Encryption needed to use mechanism"] | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
ERROR["LOGIN_PLAIN"] = [16, "User or password is wrong"] | ERROR["LOGIN_PLAIN"] = [16, "User or password is wrong"] | ||||
ERROR["CREATE"] = [20, "Unable create mailbox"] | ERROR["CREATE"] = [20, "Unable create mailbox"] | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
ERROR["DELETE"] = [25, "Unable delete mailbox"] | ERROR["DELETE"] = [25, "Unable delete mailbox"] | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
ERROR["GETACL"] = [30, "Unable parse GETACL result"] | ERROR["GETACL"] = [30, "Unable parse GETACL result"] | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
ERROR["SETQUOTA"] = [40, "Invalid integer argument"] | ERROR["SETQUOTA"] = [40, "Invalid integer argument"] | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
ERROR["GETQUOTA"] = [45, "Quota root does not exist"] | ERROR["GETQUOTA"] = [45, "Quota root does not exist"] | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
ERROR["RENAME"] = [50, "Unable rename mailbox"] | ERROR["RENAME"] = [50, "Unable rename mailbox"] | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
ERROR["RECONSTRUCT"] = [60, "Unable reconstruct mailbox"] | ERROR["RECONSTRUCT"] = [60, "Unable reconstruct mailbox"] | ||||
ERROR["SUBSCRIBE"] = [70, "User is cyrus administrator, normal user required"] | ERROR["SUBSCRIBE"] = [70, "User is cyrus administrator, normal user required"] | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
Lint: PEP8 E501 line too long (84 > 79 characters) Lint: PEP8 E501: line too long (84 > 79 characters) | |||||
ERROR["UNSUBSCRIBE"] = [75, "User is cyrus administrator, normal user required"] | ERROR["UNSUBSCRIBE"] = [75, "User is cyrus administrator, normal user required"] | ||||
Lint: PEP8 E501 line too long (84 > 79 characters) Lint: PEP8 E501: line too long (84 > 79 characters) | |||||
ERROR["LSUB"] = [77, "User is cyrus administrator, normal user required"] | ERROR["LSUB"] = [77, "User is cyrus administrator, normal user required"] | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
Lint: PEP8 E501 line too long (84 > 79 characters) Lint: PEP8 E501: line too long (84 > 79 characters) | |||||
ERROR["UNKCMD"] = [98, "Command not implemented"] | ERROR["UNKCMD"] = [98, "Command not implemented"] | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
ERROR["IMAPLIB"] = [99, "Generic imaplib error"] | ERROR["IMAPLIB"] = [99, "Generic imaplib error"] | ||||
Lint: PEP8 E221 multiple spaces before operator Lint: PEP8 E221: multiple spaces before operator | |||||
ENCODING_LIST = ['imap', 'utf-8', 'iso-8859-1'] | ENCODING_LIST = ['imap', 'utf-8', 'iso-8859-1'] | ||||
def __init__(self, url = 'imap://localhost:143'): | def __init__(self, url = 'imap://localhost:143'): | ||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
self.VERBOSE = False | self.VERBOSE = False | ||||
self.AUTH = False | self.AUTH = False | ||||
self.ADMIN = None | self.ADMIN = None | ||||
self.AUSER = None | self.AUSER = None | ||||
self.ADMINACL = 'c' | self.ADMINACL = 'c' | ||||
self.SEP = DEFAULT_SEP | self.SEP = DEFAULT_SEP | ||||
self.ENCODING = 'imap' | self.ENCODING = 'imap' | ||||
self.LOGFD = stdout | self.LOGFD = stdout | ||||
Show All 30 Lines | def __doexception(self, function, msg=None, *args): | ||||
msg = self.ERROR.get(function.upper())[1] | msg = self.ERROR.get(function.upper())[1] | ||||
except: | except: | ||||
msg = self.ERROR.get("IMAPLIB")[1] | msg = self.ERROR.get("IMAPLIB")[1] | ||||
value = "" | value = "" | ||||
for arg in args: | for arg in args: | ||||
if arg is not None: | if arg is not None: | ||||
value = "%s %s" % (value, arg) | value = "%s %s" % (value, arg) | ||||
self.__verbose( '[%s%s] %s: %s' % (function.upper(), value, "BAD", msg) ) | self.__verbose( '[%s%s] %s: %s' % (function.upper(), value, "BAD", msg) ) | ||||
Lint: PEP8 E201 whitespace after '(' Lint: PEP8 E201: whitespace after '(' | |||||
Lint: PEP8 E202 whitespace before ')' Lint: PEP8 E202: whitespace before ')' | |||||
Lint: PEP8 E501 line too long (81 > 79 characters) Lint: PEP8 E501: line too long (81 > 79 characters) | |||||
self.__doraise( function.upper(), msg ) | self.__doraise( function.upper(), msg ) | ||||
Lint: PEP8 E201 whitespace after '(' Lint: PEP8 E201: whitespace after '(' | |||||
Lint: PEP8 E202 whitespace before ')' Lint: PEP8 E202: whitespace before ')' | |||||
def __doraise(self, mode, msg=None): | def __doraise(self, mode, msg=None): | ||||
idError = self.ERROR.get(mode) | idError = self.ERROR.get(mode) | ||||
if idError: | if idError: | ||||
if msg is None: | if msg is None: | ||||
msg = idError[1] | msg = idError[1] | ||||
else: | else: | ||||
idError = [self.ERROR.get("IMAPLIB")[0]] | idError = [self.ERROR.get("IMAPLIB")[0]] | ||||
raise CYRUSError( idError[0], mode, msg ) | raise CYRUSError( idError[0], mode, msg ) | ||||
Lint: PEP8 E201 whitespace after '(' Lint: PEP8 E201: whitespace after '(' | |||||
Lint: PEP8 E202 whitespace before ')' Lint: PEP8 E202: whitespace before ')' | |||||
def __prepare(self, command, mailbox=True): | def __prepare(self, command, mailbox=True): | ||||
Lint: PEP8 E303 too many blank lines (2) Lint: PEP8 E303: too many blank lines (2) | |||||
if not self.AUTH: | if not self.AUTH: | ||||
self.__doexception(command, self.ERROR.get("NOAUTH")[1]) | self.__doexception(command, self.ERROR.get("NOAUTH")[1]) | ||||
elif not mailbox: | elif not mailbox: | ||||
self.__doexception(command, self.ERROR.get("MBXNULL")[1]) | self.__doexception(command, self.ERROR.get("MBXNULL")[1]) | ||||
def __docommand(self, function, *args): | def __docommand(self, function, *args): | ||||
wrapped = getattr(self.m, function, None) | wrapped = getattr(self.m, function, None) | ||||
if wrapped is None: | if wrapped is None: | ||||
raise self.__doraise("UNKCMD") | raise self.__doraise("UNKCMD") | ||||
try: | try: | ||||
res, msg = wrapped(*args) | res, msg = wrapped(*args) | ||||
if ok(res): | if ok(res): | ||||
return res, msg | return res, msg | ||||
except Exception, info: | except Exception, info: | ||||
error = info.args[0].split(':').pop().strip() | error = str(info).split(':').pop().strip() | ||||
if error.upper().startswith('BAD'): | if error.upper().startswith('BAD'): | ||||
error = error.split('BAD', 1).pop().strip() | error = error.split('BAD', 1).pop().strip() | ||||
error = unquote(error[1:-1], '\'') | error = unquote(error[1:-1], '\'') | ||||
self.__doexception(function, error, *args) | self.__doexception(function, error, *args) | ||||
self.__doexception(function, msg[0], *args) | self.__doexception(function, msg[0], *args) | ||||
def xfer(self, mailbox, server): | def xfer(self, mailbox, server): | ||||
"""Xfer a mailbox to server""" | """Xfer a mailbox to server""" | ||||
return self.m._simple_command('XFER', mailbox, server) | return self.m._simple_command('XFER', mailbox, server) | ||||
def id(self): | def id(self): | ||||
self.__prepare('id') | self.__prepare('id') | ||||
res, data = self.m.id() | res, data = self.m.id() | ||||
data = data.strip() | data = data.strip() | ||||
if not res or (len(data) < 3): return False, {} | if not res or (len(data) < 3): return False, {} | ||||
Lint: PEP8 E701 multiple statements on one line (colon) Lint: PEP8 E701: multiple statements on one line (colon) | |||||
data = data[1:-1] # Strip () | data = data[1:-1] # Strip () | ||||
Lint: PEP8 E261 at least two spaces before inline comment Lint: PEP8 E261: at least two spaces before inline comment | |||||
res, rdata = res2dict(data) | res, rdata = res2dict(data) | ||||
if not res: | if not res: | ||||
self.__verbose( '[ID] Umatched pairs in result' ) | self.__verbose( '[ID] Umatched pairs in result' ) | ||||
Lint: PEP8 E201 whitespace after '(' Lint: PEP8 E201: whitespace after '(' | |||||
Lint: PEP8 E202 whitespace before ')' Lint: PEP8 E202: whitespace before ')' | |||||
return res, rdata | return res, rdata | ||||
def login(self, username, password): | def login(self, username, password): | ||||
if self.AUTH: | if self.AUTH: | ||||
self.__doexception("LOGIN", self.ERROR.get("AUTH")[1]) | self.__doexception("LOGIN", self.ERROR.get("AUTH")[1]) | ||||
try: | try: | ||||
res, msg = self.m.login(username, password) | res, msg = self.m.login(username, password) | ||||
admin = self.m.isadmin() | admin = self.m.isadmin() | ||||
except Exception, info: | except Exception, info: | ||||
error = info.args[0].split(':').pop().strip() | error = str(info).split(':').pop().strip() | ||||
self.__doexception("LOGIN", error) | self.__doexception("LOGIN", error) | ||||
if admin: | if admin: | ||||
self.ADMIN = username | self.ADMIN = username | ||||
self.SEP = self.m.getsep() | self.SEP = self.m.getsep() | ||||
self.AUTH = True | self.AUTH = True | ||||
self.__verbose( '[LOGIN %s] %s: %s' % (username, res, msg[0]) ) | self.__verbose( '[LOGIN %s] %s: %s' % (username, res, msg[0]) ) | ||||
Lint: PEP8 E201 whitespace after '(' Lint: PEP8 E201: whitespace after '(' | |||||
Lint: PEP8 E202 whitespace before ')' Lint: PEP8 E202: whitespace before ')' | |||||
def login_plain(self, username, password, asUser = None): | def login_plain(self, username, password, asUser = None): | ||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
if self.AUTH: | if self.AUTH: | ||||
self.__doexception("LOGINPLAIN", self.ERROR.get("AUTH")[1]) | self.__doexception("LOGINPLAIN", self.ERROR.get("AUTH")[1]) | ||||
if not self.ssl: | if not self.ssl: | ||||
self.__doexception("LOGINPLAIN", self.ERROR.get("LOGINPLAIN")[1]) | self.__doexception("LOGINPLAIN", self.ERROR.get("LOGINPLAIN")[1]) | ||||
res, msg = self.__docommand("login_plain", username, password, asUser) | res, msg = self.__docommand("login_plain", username, password, asUser) | ||||
self.__verbose( '[AUTHENTICATE PLAIN %s] %s: %s' % (username, res, msg[0]) ) | self.__verbose( '[AUTHENTICATE PLAIN %s] %s: %s' % (username, res, msg[0]) ) | ||||
Lint: PEP8 E201 whitespace after '(' Lint: PEP8 E201: whitespace after '(' | |||||
Lint: PEP8 E501 line too long (84 > 79 characters) Lint: PEP8 E501: line too long (84 > 79 characters) | |||||
Lint: PEP8 E202 whitespace before ')' Lint: PEP8 E202: whitespace before ')' | |||||
if ok(res): | if ok(res): | ||||
if asUser is None: | if asUser is None: | ||||
if self.m.isadmin(): | if self.m.isadmin(): | ||||
self.ADMIN = admin | self.ADMIN = admin | ||||
else: | else: | ||||
self.ADMIN = asUser | self.ADMIN = asUser | ||||
self.AUSER = asUser | self.AUSER = asUser | ||||
self.SEP = self.m.getsep() | self.SEP = self.m.getsep() | ||||
self.AUTH = True | self.AUTH = True | ||||
def logout(self): | def logout(self): | ||||
try: | try: | ||||
res, msg = self.m.logout() | res, msg = self.m.logout() | ||||
except Exception, info: | except Exception, info: | ||||
error = info.args[0].split(':').pop().strip() | error = str(info).split(':').pop().strip() | ||||
self.__doexception("LOGOUT", error) | self.__doexception("LOGOUT", error) | ||||
self.AUTH = False | self.AUTH = False | ||||
self.ADMIN = None | self.ADMIN = None | ||||
self.AUSER = None | self.AUSER = None | ||||
self.__verbose( '[LOGOUT] %s: %s' % (res, msg[0]) ) | self.__verbose( '[LOGOUT] %s: %s' % (res, msg[0]) ) | ||||
Lint: PEP8 E201 whitespace after '(' Lint: PEP8 E201: whitespace after '(' | |||||
Lint: PEP8 E202 whitespace before ')' Lint: PEP8 E202: whitespace before ')' | |||||
def getEncoding(self): | def getEncoding(self): | ||||
"""Get current input/output codification""" | """Get current input/output codification""" | ||||
return self.ENCODING | return self.ENCODING | ||||
def setEncoding(self, enc = None): | def setEncoding(self, enc = None): | ||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
Lint: PEP8 E251 unexpected spaces around keyword / parameter equals Lint: PEP8 E251: unexpected spaces around keyword / parameter equals | |||||
"""Set current input/output codification""" | """Set current input/output codification""" | ||||
if enc is None: | if enc is None: | ||||
self.ENCODING = 'imap' | self.ENCODING = 'imap' | ||||
elif enc in self.ENCODING_LIST: | elif enc in self.ENCODING_LIST: | ||||
self.ENCODING = enc | self.ENCODING = enc | ||||
else: | else: | ||||
raise self.__doraise("ENCODING") | raise self.__doraise("ENCODING") | ||||
Show All 34 Lines | def lm(self, pattern="*"): | ||||
To list all users mailboxes lm("user/*") | To list all users mailboxes lm("user/*") | ||||
To list users mailboxes startwith a word lm("user/word*") | To list users mailboxes startwith a word lm("user/word*") | ||||
To list global top folders lm("%") | To list global top folders lm("%") | ||||
To list global startwith a word unsupported by server | To list global startwith a word unsupported by server | ||||
suggestion lm("word*") | suggestion lm("word*") | ||||
""" | """ | ||||
self.__prepare('LIST') | self.__prepare('LIST') | ||||
if pattern == '': pattern = "*" | if pattern == '': pattern = "*" | ||||
Lint: PEP8 E701 multiple statements on one line (colon) Lint: PEP8 E701: multiple statements on one line (colon) | |||||
if pattern == '%': | if pattern == '%': | ||||
res, ml = self.__docommand('list', '', '%') | res, ml = self.__docommand('list', '', '%') | ||||
else: | else: | ||||
res, ml = self.__docommand('list', '""', self.decode(pattern)) | res, ml = self.__docommand('list', '""', self.decode(pattern)) | ||||
if not ok(res): | if not ok(res): | ||||
self.__verbose( '[LIST] %s: %s' % (res, ml) ) | self.__verbose( '[LIST] %s: %s' % (res, ml) ) | ||||
Lint: PEP8 E201 whitespace after '(' Lint: PEP8 E201: whitespace after '(' | |||||
Lint: PEP8 E202 whitespace before ')' Lint: PEP8 E202: whitespace before ')' | |||||
return [] | return [] | ||||
if (len(ml) == 1) and ml[0] is None: | if (len(ml) == 1) and ml[0] is None: | ||||
self.__verbose( '[LIST] No results' ) | self.__verbose( '[LIST] No results' ) | ||||
Lint: PEP8 E201 whitespace after '(' Lint: PEP8 E201: whitespace after '(' | |||||
Lint: PEP8 E202 whitespace before ')' Lint: PEP8 E202: whitespace before ')' | |||||
return [] | return [] | ||||
mb = [] | mb = [] | ||||
for mailbox in ml: | for mailbox in ml: | ||||
res = re_mb.match(mailbox) | res = re_mb.match(mailbox) | ||||
if res is None: continue | if res is None: continue | ||||
Lint: PEP8 E701 multiple statements on one line (colon) Lint: PEP8 E701: multiple statements on one line (colon) | |||||
mbe = unquote(res.group(2)) | mbe = unquote(res.group(2)) | ||||
if 'Noselect' in getflags(res.group(1)): continue | if 'Noselect' in getflags(res.group(1)): continue | ||||
Lint: PEP8 E701 multiple statements on one line (colon) Lint: PEP8 E701: multiple statements on one line (colon) | |||||
mb.append(self.encode(mbe)) | mb.append(self.encode(mbe)) | ||||
return mb | return mb | ||||
def cm(self, mailbox, partition=None): | def cm(self, mailbox, partition=None): | ||||
"""Create mailbox""" | """Create mailbox""" | ||||
self.__prepare('CREATE', mailbox) | self.__prepare('CREATE', mailbox) | ||||
res, msg = self.__docommand('create', self.decode(mailbox), partition) | res, msg = self.__docommand('create', self.decode(mailbox), partition) | ||||
self.__verbose( '[CREATE %s partition=%s] %s: %s' % (mailbox, partition, res, msg[0]) ) | self.__verbose( '[CREATE %s partition=%s] %s: %s' % (mailbox, partition, res, msg[0]) ) | ||||
Lint: PEP8 E201 whitespace after '(' Lint: PEP8 E201: whitespace after '(' | |||||
Lint: PEP8 E501 line too long (95 > 79 characters) Lint: PEP8 E501: line too long (95 > 79 characters) | |||||
Lint: PEP8 E202 whitespace before ')' Lint: PEP8 E202: whitespace before ')' | |||||
def __dm(self, mailbox): | def __dm(self, mailbox): | ||||
if not mailbox: | if not mailbox: | ||||
return True | return True | ||||
self.__docommand("setacl", self.decode(mailbox), self.ADMIN, self.ADMINACL) | self.__docommand("setacl", self.decode(mailbox), self.ADMIN, self.ADMINACL) | ||||
Lint: PEP8 E501 line too long (83 > 79 characters) Lint: PEP8 E501: line too long (83 > 79 characters) | |||||
res, msg = self.__docommand("delete", self.decode(mailbox)) | res, msg = self.__docommand("delete", self.decode(mailbox)) | ||||
self.__verbose( '[DELETE %s] %s: %s' % (mailbox, res, msg[0]) ) | self.__verbose( '[DELETE %s] %s: %s' % (mailbox, res, msg[0]) ) | ||||
Lint: PEP8 E201 whitespace after '(' Lint: PEP8 E201: whitespace after '(' | |||||
Lint: PEP8 E202 whitespace before ')' Lint: PEP8 E202: whitespace before ')' | |||||
def dm(self, mailbox, recursive=True): | def dm(self, mailbox, recursive=True): | ||||
"""Delete mailbox""" | """Delete mailbox""" | ||||
self.__prepare('DELETE', mailbox) | self.__prepare('DELETE', mailbox) | ||||
mbxTmp = mailbox.split(self.SEP) | mbxTmp = mailbox.split(self.SEP) | ||||
# Cyrus is not recursive for user subfolders and global folders | # Cyrus is not recursive for user subfolders and global folders | ||||
if (recursive and mbxTmp[0] != "user") or (len(mbxTmp) > 2): | if (recursive and mbxTmp[0] != "user") or (len(mbxTmp) > 2): | ||||
mbxList = self.lm("%s%s*" % (mailbox, self.SEP)) | mbxList = self.lm("%s%s*" % (mailbox, self.SEP)) | ||||
mbxList.reverse() | mbxList.reverse() | ||||
for mbox in mbxList: | for mbox in mbxList: | ||||
self.__dm(mbox) | self.__dm(mbox) | ||||
self.__dm(mailbox) | self.__dm(mailbox) | ||||
def rename(self, fromMbx, toMbx, partition=None): | def rename(self, fromMbx, toMbx, partition=None): | ||||
"""Rename or change partition""" | """Rename or change partition""" | ||||
self.__prepare('RENAME', fromMbx) | self.__prepare('RENAME', fromMbx) | ||||
# Rename is recursive! Amen! | # Rename is recursive! Amen! | ||||
res, msg = self.__docommand("rename", self.decode(fromMbx), self.decode(toMbx), partition) | res, msg = self.__docommand("rename", self.decode(fromMbx), self.decode(toMbx), partition) | ||||
Lint: PEP8 E501 line too long (98 > 79 characters) Lint: PEP8 E501: line too long (98 > 79 characters) | |||||
self.__verbose( '[RENAME %s %s] %s: %s' % (fromMbx, toMbx, res, msg[0]) ) | self.__verbose( '[RENAME %s %s] %s: %s' % (fromMbx, toMbx, res, msg[0]) ) | ||||
Lint: PEP8 E201 whitespace after '(' Lint: PEP8 E201: whitespace after '(' | |||||
Lint: PEP8 E202 whitespace before ')' Lint: PEP8 E202: whitespace before ')' | |||||
Lint: PEP8 E501 line too long (81 > 79 characters) Lint: PEP8 E501: line too long (81 > 79 characters) | |||||
def lam(self, mailbox): | def lam(self, mailbox): | ||||
"""List ACLs""" | """List ACLs""" | ||||
self.__prepare('GETACL', mailbox) | self.__prepare('GETACL', mailbox) | ||||
res, acl = self.__docommand("getacl", self.decode(mailbox)) | res, acl = self.__docommand("getacl", self.decode(mailbox)) | ||||
acls = {} | acls = {} | ||||
aclList = splitquote(acl.pop().strip()) | aclList = splitquote(acl.pop().strip()) | ||||
del aclList[0] # mailbox | del aclList[0] # mailbox | ||||
Lint: PEP8 E261 at least two spaces before inline comment Lint: PEP8 E261: at least two spaces before inline comment | |||||
for i in range(0, len(aclList), 2): | for i in range(0, len(aclList), 2): | ||||
try: | try: | ||||
userid = self.encode(aclList[i]) | userid = self.encode(aclList[i]) | ||||
rights = aclList[i + 1] | rights = aclList[i + 1] | ||||
except Exception, info: | except Exception, info: | ||||
self.__verbose( '[GETACL %s] BAD: %s' % (mailbox, info.args[0]) ) | self.__verbose( '[GETACL %s] BAD: %s' % (mailbox, info.args[0]) ) | ||||
Lint: PEP8 E201 whitespace after '(' Lint: PEP8 E201: whitespace after '(' | |||||
Lint: PEP8 E202 whitespace before ')' Lint: PEP8 E202: whitespace before ')' | |||||
Lint: PEP8 E501 line too long (81 > 79 characters) Lint: PEP8 E501: line too long (81 > 79 characters) | |||||
raise self.__doraise("GETACL") | raise self.__doraise("GETACL") | ||||
self.__verbose( '[GETACL %s] %s %s' % (mailbox, userid, rights) ) | self.__verbose( '[GETACL %s] %s %s' % (mailbox, userid, rights) ) | ||||
Lint: PEP8 E201 whitespace after '(' Lint: PEP8 E201: whitespace after '(' | |||||
Lint: PEP8 E202 whitespace before ')' Lint: PEP8 E202: whitespace before ')' | |||||
acls[userid] = rights | acls[userid] = rights | ||||
return acls | return acls | ||||
def sam(self, mailbox, userid, rights): | def sam(self, mailbox, userid, rights): | ||||
"""Set ACL""" | """Set ACL""" | ||||
self.__prepare('SETACL', mailbox) | self.__prepare('SETACL', mailbox) | ||||
res, msg = self.__docommand("setacl", self.decode(mailbox), userid, rights) | res, msg = self.__docommand("setacl", self.decode(mailbox), userid, rights) | ||||
Lint: PEP8 E501 line too long (83 > 79 characters) Lint: PEP8 E501: line too long (83 > 79 characters) | |||||
self.__verbose( '[SETACL %s %s %s] %s: %s' % (mailbox, userid, rights, res, msg[0]) ) | self.__verbose( '[SETACL %s %s %s] %s: %s' % (mailbox, userid, rights, res, msg[0]) ) | ||||
Lint: PEP8 E201 whitespace after '(' Lint: PEP8 E201: whitespace after '(' | |||||
Lint: PEP8 E501 line too long (93 > 79 characters) Lint: PEP8 E501: line too long (93 > 79 characters) | |||||
Lint: PEP8 E202 whitespace before ')' Lint: PEP8 E202: whitespace before ')' | |||||
def lq(self, mailbox): | def lq(self, mailbox): | ||||
"""List Quota""" | """List Quota""" | ||||
self.__prepare('GETQUOTA', mailbox) | self.__prepare('GETQUOTA', mailbox) | ||||
res, msg = self.__docommand("getquota", self.decode(mailbox)) | res, msg = self.__docommand("getquota", self.decode(mailbox)) | ||||
match = re_q0.match(msg[0]) | match = re_q0.match(msg[0]) | ||||
if match: | if match: | ||||
self.__verbose( '[GETQUOTA %s] QUOTA (Unlimited)' % mailbox ) | self.__verbose( '[GETQUOTA %s] QUOTA (Unlimited)' % mailbox ) | ||||
Lint: PEP8 E201 whitespace after '(' Lint: PEP8 E201: whitespace after '(' | |||||
Lint: PEP8 E202 whitespace before ')' Lint: PEP8 E202: whitespace before ')' | |||||
return None, None | return None, None | ||||
match = re_q.match(msg[0]) | match = re_q.match(msg[0]) | ||||
if match is None: | if match is None: | ||||
self.__verbose( '[GETQUOTA %s] BAD: RegExp not matched, please report' % mailbox ) | self.__verbose( '[GETQUOTA %s] BAD: RegExp not matched, please report' % mailbox ) | ||||
Lint: PEP8 E201 whitespace after '(' Lint: PEP8 E201: whitespace after '(' | |||||
Lint: PEP8 E501 line too long (94 > 79 characters) Lint: PEP8 E501: line too long (94 > 79 characters) | |||||
Lint: PEP8 E202 whitespace before ')' Lint: PEP8 E202: whitespace before ')' | |||||
return None, None | return None, None | ||||
try: | try: | ||||
used = int(match.group(2)) | used = int(match.group(2)) | ||||
quota = int(match.group(3)) | quota = int(match.group(3)) | ||||
self.__verbose( '[GETQUOTA %s] %s: QUOTA (%d/%d)' % (mailbox, res, used, quota) ) | self.__verbose( '[GETQUOTA %s] %s: QUOTA (%d/%d)' % (mailbox, res, used, quota) ) | ||||
Lint: PEP8 E201 whitespace after '(' Lint: PEP8 E201: whitespace after '(' | |||||
Lint: PEP8 E501 line too long (93 > 79 characters) Lint: PEP8 E501: line too long (93 > 79 characters) | |||||
Lint: PEP8 E202 whitespace before ')' Lint: PEP8 E202: whitespace before ')' | |||||
return used, quota | return used, quota | ||||
except: | except: | ||||
self.__verbose( '[GETQUOTA %s] BAD: Error while parsing results' % mailbox ) | self.__verbose( '[GETQUOTA %s] BAD: Error while parsing results' % mailbox ) | ||||
Lint: PEP8 E201 whitespace after '(' Lint: PEP8 E201: whitespace after '(' | |||||
Lint: PEP8 E501 line too long (88 > 79 characters) Lint: PEP8 E501: line too long (88 > 79 characters) | |||||
Lint: PEP8 E202 whitespace before ')' Lint: PEP8 E202: whitespace before ')' | |||||
return None, None | return None, None | ||||
def lqr(self, mailbox): | def lqr(self, mailbox): | ||||
"""List Quota Root""" | """List Quota Root""" | ||||
self.__prepare('GETQUOTAROOT', mailbox) | self.__prepare('GETQUOTAROOT', mailbox) | ||||
res, msg = self.__docommand("getquotaroot", self.decode(mailbox)) | res, msg = self.__docommand("getquotaroot", self.decode(mailbox)) | ||||
(_mailbox, _root) = msg[0][0].split() | (_mailbox, _root) = msg[0][0].split() | ||||
match = re_q0.match(msg[1][0]) | match = re_q0.match(msg[1][0]) | ||||
if match: | if match: | ||||
self.__verbose( '[GETQUOTAROOT %s] QUOTAROOT (Unlimited)' % mailbox ) | self.__verbose( '[GETQUOTAROOT %s] QUOTAROOT (Unlimited)' % mailbox ) | ||||
Lint: PEP8 E201 whitespace after '(' Lint: PEP8 E201: whitespace after '(' | |||||
Lint: PEP8 E202 whitespace before ')' Lint: PEP8 E202: whitespace before ')' | |||||
Lint: PEP8 E501 line too long (81 > 79 characters) Lint: PEP8 E501: line too long (81 > 79 characters) | |||||
return _root, None, None | return _root, None, None | ||||
match = re_q.match(msg[1][0]) | match = re_q.match(msg[1][0]) | ||||
try: | try: | ||||
used = int(match.group(2)) | used = int(match.group(2)) | ||||
quota = int(match.group(3)) | quota = int(match.group(3)) | ||||
self.__verbose( '[GETQUOTAROOT %s] %s: QUOTA (%d/%d)' % (mailbox, res, used, quota) ) | self.__verbose( '[GETQUOTAROOT %s] %s: QUOTA (%d/%d)' % (mailbox, res, used, quota) ) | ||||
Lint: PEP8 E201 whitespace after '(' Lint: PEP8 E201: whitespace after '(' | |||||
Lint: PEP8 E501 line too long (97 > 79 characters) Lint: PEP8 E501: line too long (97 > 79 characters) | |||||
Lint: PEP8 E202 whitespace before ')' Lint: PEP8 E202: whitespace before ')' | |||||
return _root, used, quota | return _root, used, quota | ||||
except: | except: | ||||
self.__verbose( '[GETQUOTAROOT %s] BAD: Error while parsing results' % mailbox ) | self.__verbose( '[GETQUOTAROOT %s] BAD: Error while parsing results' % mailbox ) | ||||
Lint: PEP8 E201 whitespace after '(' Lint: PEP8 E201: whitespace after '(' | |||||
Lint: PEP8 E501 line too long (92 > 79 characters) Lint: PEP8 E501: line too long (92 > 79 characters) | |||||
Lint: PEP8 E202 whitespace before ')' Lint: PEP8 E202: whitespace before ')' | |||||
return _root, None, None | return _root, None, None | ||||
def sq(self, mailbox, limit): | def sq(self, mailbox, limit): | ||||
"""Set Quota""" | """Set Quota""" | ||||
self.__prepare('SETQUOTA', mailbox) | self.__prepare('SETQUOTA', mailbox) | ||||
try: | try: | ||||
limit = int(limit) | limit = int(limit) | ||||
except ValueError, e: | except ValueError, e: | ||||
self.__verbose( '[SETQUOTA %s] BAD: %s %s' % (mailbox, self.ERROR.get("SETQUOTA")[1], limit) ) | self.__verbose( '[SETQUOTA %s] BAD: %s %s' % (mailbox, self.ERROR.get("SETQUOTA")[1], limit) ) | ||||
Lint: PEP8 E201 whitespace after '(' Lint: PEP8 E201: whitespace after '(' | |||||
Lint: PEP8 E501 line too long (106 > 79 characters) Lint: PEP8 E501: line too long (106 > 79 characters) | |||||
Lint: PEP8 E202 whitespace before ')' Lint: PEP8 E202: whitespace before ')' | |||||
raise self.__doraise("SETQUOTA") | raise self.__doraise("SETQUOTA") | ||||
res, msg = self.__docommand("setquota", self.decode(mailbox), limit) | res, msg = self.__docommand("setquota", self.decode(mailbox), limit) | ||||
self.__verbose( '[SETQUOTA %s %s] %s: %s' % (mailbox, limit, res, msg[0]) ) | self.__verbose( '[SETQUOTA %s %s] %s: %s' % (mailbox, limit, res, msg[0]) ) | ||||
Lint: PEP8 E201 whitespace after '(' Lint: PEP8 E201: whitespace after '(' | |||||
Lint: PEP8 E501 line too long (83 > 79 characters) Lint: PEP8 E501: line too long (83 > 79 characters) | |||||
Lint: PEP8 E202 whitespace before ')' Lint: PEP8 E202: whitespace before ')' | |||||
def getannotation(self, mailbox, pattern='*'): | def getannotation(self, mailbox, pattern='*'): | ||||
"""Get Annotation""" | """Get Annotation""" | ||||
self.__prepare('GETANNOTATION') | self.__prepare('GETANNOTATION') | ||||
res, data = self.__docommand('getannotation', self.decode(mailbox), pattern) | res, data = self.__docommand('getannotation', self.decode(mailbox), pattern) | ||||
Lint: PEP8 E501 line too long (84 > 79 characters) Lint: PEP8 E501: line too long (84 > 79 characters) | |||||
if (len(data) == 1) and data[0] is None: | if (len(data) == 1) and data[0] is None: | ||||
self.__verbose( '[GETANNOTATION %s] No results' % (mailbox) ) | self.__verbose( '[GETANNOTATION %s] No results' % (mailbox) ) | ||||
Lint: PEP8 E201 whitespace after '(' Lint: PEP8 E201: whitespace after '(' | |||||
Lint: PEP8 E202 whitespace before ')' Lint: PEP8 E202: whitespace before ')' | |||||
return {} | return {} | ||||
ann = {} | ann = {} | ||||
annotations = [] | annotations = [] | ||||
empty_values = [ "NIL", '" "', None, '', ' ' ] | empty_values = [ "NIL", '" "', None, '', ' ' ] | ||||
Lint: PEP8 E201 whitespace after '[' Lint: PEP8 E201: whitespace after '[' | |||||
Lint: PEP8 E202 whitespace before ']' Lint: PEP8 E202: whitespace before ']' | |||||
concat_items = [] | concat_items = [] | ||||
for item in data: | for item in data: | ||||
if isinstance(item, tuple): | if isinstance(item, tuple): | ||||
item = ' '.join([str(x) for x in item]) | item = ' '.join([str(x) for x in item]) | ||||
if len(concat_items) > 0: | if len(concat_items) > 0: | ||||
concat_items.append(item) | concat_items.append(item) | ||||
if ''.join(concat_items).count('(') == ''.join(concat_items).count(')'): | if ''.join(concat_items).count('(') == ''.join(concat_items).count(')'): | ||||
Lint: PEP8 E501 line too long (88 > 79 characters) Lint: PEP8 E501: line too long (88 > 79 characters) | |||||
annotations.append(''.join(concat_items)) | annotations.append(''.join(concat_items)) | ||||
concat_items = [] | concat_items = [] | ||||
continue | continue | ||||
else: | else: | ||||
if item.count('(') == item.count(')'): | if item.count('(') == item.count(')'): | ||||
annotations.append(item) | annotations.append(item) | ||||
continue | continue | ||||
else: | else: | ||||
concat_items.append(item) | concat_items.append(item) | ||||
continue | continue | ||||
for annotation in annotations: | for annotation in annotations: | ||||
annotation = annotation.strip() | annotation = annotation.strip() | ||||
if not annotation[0] == '"': | if not annotation[0] == '"': | ||||
folder = annotation.split('"')[0].replace('"','').strip() | folder = annotation.split('"')[0].replace('"','').strip() | ||||
Lint: PEP8 E231 missing whitespace after ',' Lint: PEP8 E231: missing whitespace after ',' | |||||
key = annotation.split('"')[1].replace('"','').replace("'","").strip() | key = annotation.split('"')[1].replace('"','').replace("'","").strip() | ||||
Lint: PEP8 E231 missing whitespace after ',' Lint: PEP8 E231: missing whitespace after ',' | |||||
Lint: PEP8 E231 missing whitespace after ',' Lint: PEP8 E231: missing whitespace after ',' | |||||
Lint: PEP8 E501 line too long (86 > 79 characters) Lint: PEP8 E501: line too long (86 > 79 characters) | |||||
_annot = annotation.split('(')[1].split(')')[0].strip() | _annot = annotation.split('(')[1].split(')')[0].strip() | ||||
else: | else: | ||||
folder = annotation.split('"')[1].replace('"','').strip() | folder = annotation.split('"')[1].replace('"','').strip() | ||||
Lint: PEP8 E231 missing whitespace after ',' Lint: PEP8 E231: missing whitespace after ',' | |||||
key = annotation.split('"')[3].replace('"','').replace("'","").strip() | key = annotation.split('"')[3].replace('"','').replace("'","").strip() | ||||
Lint: PEP8 E231 missing whitespace after ',' Lint: PEP8 E231: missing whitespace after ',' | |||||
Lint: PEP8 E231 missing whitespace after ',' Lint: PEP8 E231: missing whitespace after ',' | |||||
Lint: PEP8 E501 line too long (86 > 79 characters) Lint: PEP8 E501: line too long (86 > 79 characters) | |||||
_annot = annotation.split('(')[1].split(')')[0].strip() | _annot = annotation.split('(')[1].split(')')[0].strip() | ||||
if not ann.has_key(folder): | if not ann.has_key(folder): | ||||
ann[folder] = {} | ann[folder] = {} | ||||
try: | try: | ||||
value_priv = _annot[(_annot.index('"value.priv"')+len('"value.priv"')):_annot.index('"size.priv"')].strip() | value_priv = _annot[(_annot.index('"value.priv"')+len('"value.priv"')):_annot.index('"size.priv"')].strip() | ||||
Lint: PEP8 E501 line too long (123 > 79 characters) Lint: PEP8 E501: line too long (123 > 79 characters) | |||||
except ValueError, errmsg: | except ValueError, errmsg: | ||||
value_priv = None | value_priv = None | ||||
try: | try: | ||||
size_priv = _annot[(_annot.index('"size.priv"')+len('"size.priv"')):].strip().split('"')[1].strip() | size_priv = _annot[(_annot.index('"size.priv"')+len('"size.priv"')):].strip().split('"')[1].strip() | ||||
Lint: PEP8 E501 line too long (115 > 79 characters) Lint: PEP8 E501: line too long (115 > 79 characters) | |||||
try: | try: | ||||
value_priv = value_priv[value_priv.index('{%s}' % (size_priv))+len('{%s}' % (size_priv)):].strip() | value_priv = value_priv[value_priv.index('{%s}' % (size_priv))+len('{%s}' % (size_priv)):].strip() | ||||
Lint: PEP8 E501 line too long (118 > 79 characters) Lint: PEP8 E501: line too long (118 > 79 characters) | |||||
except Exception, errmsg: | except Exception, errmsg: | ||||
pass | pass | ||||
except Exception, errmsg: | except Exception, errmsg: | ||||
pass | pass | ||||
if value_priv in empty_values: | if value_priv in empty_values: | ||||
value_priv = None | value_priv = None | ||||
else: | else: | ||||
try: | try: | ||||
value_priv = value_priv[:value_priv.index('"content-type.priv"')].strip() | value_priv = value_priv[:value_priv.index('"content-type.priv"')].strip() | ||||
Lint: PEP8 E501 line too long (93 > 79 characters) Lint: PEP8 E501: line too long (93 > 79 characters) | |||||
except: | except: | ||||
pass | pass | ||||
try: | try: | ||||
value_priv = value_priv[:value_priv.index('"modifiedsince.priv"')].strip() | value_priv = value_priv[:value_priv.index('"modifiedsince.priv"')].strip() | ||||
Lint: PEP8 E501 line too long (94 > 79 characters) Lint: PEP8 E501: line too long (94 > 79 characters) | |||||
except: | except: | ||||
pass | pass | ||||
if value_priv.startswith('"'): | if value_priv.startswith('"'): | ||||
value_priv = value_priv[1:] | value_priv = value_priv[1:] | ||||
if value_priv.endswith('"'): | if value_priv.endswith('"'): | ||||
value_priv = value_priv[:-1] | value_priv = value_priv[:-1] | ||||
if value_priv in empty_values: | if value_priv in empty_values: | ||||
value_priv = None | value_priv = None | ||||
try: | try: | ||||
value_shared = _annot[(_annot.index('"value.shared"')+len('"value.shared"')):_annot.index('"size.shared"')].strip() | value_shared = _annot[(_annot.index('"value.shared"')+len('"value.shared"')):_annot.index('"size.shared"')].strip() | ||||
Lint: PEP8 E501 line too long (131 > 79 characters) Lint: PEP8 E501: line too long (131 > 79 characters) | |||||
except ValueError, errmsg: | except ValueError, errmsg: | ||||
value_shared = None | value_shared = None | ||||
try: | try: | ||||
size_shared = _annot[(_annot.index('"size.shared"')+len('"size.shared"')):].strip().split('"')[1].strip() | size_shared = _annot[(_annot.index('"size.shared"')+len('"size.shared"')):].strip().split('"')[1].strip() | ||||
Lint: PEP8 E501 line too long (121 > 79 characters) Lint: PEP8 E501: line too long (121 > 79 characters) | |||||
try: | try: | ||||
value_shared = value_shared[value_shared.index('{%s}' % (size_shared))+len('{%s}' % (size_shared)):].strip() | value_shared = value_shared[value_shared.index('{%s}' % (size_shared))+len('{%s}' % (size_shared)):].strip() | ||||
Lint: PEP8 E501 line too long (128 > 79 characters) Lint: PEP8 E501: line too long (128 > 79 characters) | |||||
except Exception, errmsg: | except Exception, errmsg: | ||||
pass | pass | ||||
except Exception, errmsg: | except Exception, errmsg: | ||||
pass | pass | ||||
if value_shared in empty_values: | if value_shared in empty_values: | ||||
value_shared = None | value_shared = None | ||||
else: | else: | ||||
try: | try: | ||||
value_shared = value_shared[:value_shared.index('"content-type.shared"')].strip() | value_shared = value_shared[:value_shared.index('"content-type.shared"')].strip() | ||||
Lint: PEP8 E501 line too long (101 > 79 characters) Lint: PEP8 E501: line too long (101 > 79 characters) | |||||
except: | except: | ||||
pass | pass | ||||
try: | try: | ||||
value_shared = value_shared[:value_shared.index('"modifiedsince.shared"')].strip() | value_shared = value_shared[:value_shared.index('"modifiedsince.shared"')].strip() | ||||
Lint: PEP8 E501 line too long (102 > 79 characters) Lint: PEP8 E501: line too long (102 > 79 characters) | |||||
except: | except: | ||||
pass | pass | ||||
if value_shared.startswith('"'): | if value_shared.startswith('"'): | ||||
value_shared = value_shared[1:] | value_shared = value_shared[1:] | ||||
if value_shared.endswith('"'): | if value_shared.endswith('"'): | ||||
value_shared = value_shared[:-1] | value_shared = value_shared[:-1] | ||||
if value_shared in empty_values: | if value_shared in empty_values: | ||||
value_shared = None | value_shared = None | ||||
if not value_priv == None: | if not value_priv == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
ann[folder]['/private' + key] = value_priv | ann[folder]['/private' + key] = value_priv | ||||
if not value_shared == None: | if not value_shared == None: | ||||
Lint: PEP8 E711 comparison to None should be 'if cond is None:' Lint: PEP8 E711: comparison to None should be 'if cond is None:' | |||||
ann[folder]['/shared' + key] = value_shared | ann[folder]['/shared' + key] = value_shared | ||||
return ann | return ann | ||||
def setannotation(self, mailbox, annotation, value, shared=False): | def setannotation(self, mailbox, annotation, value, shared=False): | ||||
"""Set Annotation""" | """Set Annotation""" | ||||
self.__prepare('SETANNOTATION') | self.__prepare('SETANNOTATION') | ||||
res, msg = self.__docommand("setannotation", self.decode(mailbox), annotation, value, shared) | res, msg = self.__docommand("setannotation", self.decode(mailbox), annotation, value, shared) | ||||
Lint: PEP8 E501 line too long (101 > 79 characters) Lint: PEP8 E501: line too long (101 > 79 characters) | |||||
self.__verbose( '[SETANNOTATION %s] %s: %s' % (mailbox, res, msg[0]) ) | self.__verbose( '[SETANNOTATION %s] %s: %s' % (mailbox, res, msg[0]) ) | ||||
Lint: PEP8 E201 whitespace after '(' Lint: PEP8 E201: whitespace after '(' | |||||
Lint: PEP8 E202 whitespace before ')' Lint: PEP8 E202: whitespace before ')' | |||||
def __reconstruct(self, mailbox): | def __reconstruct(self, mailbox): | ||||
if not mailbox: | if not mailbox: | ||||
return True | return True | ||||
res, msg = self.__docommand("reconstruct", self.decode(mailbox)) | res, msg = self.__docommand("reconstruct", self.decode(mailbox)) | ||||
self.__verbose( '[RECONSTRUCT %s] %s: %s' % (mailbox, res, msg[0]) ) | self.__verbose( '[RECONSTRUCT %s] %s: %s' % (mailbox, res, msg[0]) ) | ||||
Lint: PEP8 E201 whitespace after '(' Lint: PEP8 E201: whitespace after '(' | |||||
Lint: PEP8 E202 whitespace before ')' Lint: PEP8 E202: whitespace before ')' | |||||
def reconstruct(self, mailbox, recursive=True): | def reconstruct(self, mailbox, recursive=True): | ||||
"""Reconstruct""" | """Reconstruct""" | ||||
self.__prepare('RECONSTRUCT', mailbox) | self.__prepare('RECONSTRUCT', mailbox) | ||||
# Cyrus is not recursive for remote reconstruct | # Cyrus is not recursive for remote reconstruct | ||||
if recursive: | if recursive: | ||||
mbxList = self.lm("%s%s*" % (mailbox, self.SEP)) | mbxList = self.lm("%s%s*" % (mailbox, self.SEP)) | ||||
mbxList.reverse() | mbxList.reverse() | ||||
for mbox in mbxList: | for mbox in mbxList: | ||||
self.__reconstruct(mbox) | self.__reconstruct(mbox) | ||||
self.__reconstruct(mailbox) | self.__reconstruct(mailbox) | ||||
def lsub(self, pattern="*"): | def lsub(self, pattern="*"): | ||||
if self.AUSER is None: | if self.AUSER is None: | ||||
self.__doexception("lsub") | self.__doexception("lsub") | ||||
self.__prepare('LSUB') | self.__prepare('LSUB') | ||||
if pattern == '': pattern = "*" | if pattern == '': pattern = "*" | ||||
Lint: PEP8 E701 multiple statements on one line (colon) Lint: PEP8 E701: multiple statements on one line (colon) | |||||
res, ml = self.__docommand('lsub', '*', pattern) | res, ml = self.__docommand('lsub', '*', pattern) | ||||
if not ok(res): | if not ok(res): | ||||
self.__verbose( '[LIST] %s: %s' % (res, ml) ) | self.__verbose( '[LIST] %s: %s' % (res, ml) ) | ||||
Lint: PEP8 E201 whitespace after '(' Lint: PEP8 E201: whitespace after '(' | |||||
Lint: PEP8 E202 whitespace before ')' Lint: PEP8 E202: whitespace before ')' | |||||
return [] | return [] | ||||
if (len(ml) == 1) and ml[0] is None: | if (len(ml) == 1) and ml[0] is None: | ||||
self.__verbose( '[LIST] No results' ) | self.__verbose( '[LIST] No results' ) | ||||
Lint: PEP8 E201 whitespace after '(' Lint: PEP8 E201: whitespace after '(' | |||||
Lint: PEP8 E202 whitespace before ')' Lint: PEP8 E202: whitespace before ')' | |||||
return [] | return [] | ||||
mb = [] | mb = [] | ||||
for mailbox in ml: | for mailbox in ml: | ||||
res = re_mb.match(mailbox) | res = re_mb.match(mailbox) | ||||
if res is None: continue | if res is None: continue | ||||
Lint: PEP8 E701 multiple statements on one line (colon) Lint: PEP8 E701: multiple statements on one line (colon) | |||||
mbe = unquote(res.group(2)) | mbe = unquote(res.group(2)) | ||||
if 'Noselect' in getflags(res.group(1)): continue | if 'Noselect' in getflags(res.group(1)): continue | ||||
Lint: PEP8 E701 multiple statements on one line (colon) Lint: PEP8 E701: multiple statements on one line (colon) | |||||
mb.append(self.encode(mbe)) | mb.append(self.encode(mbe)) | ||||
return mb | return mb | ||||
def subscribe(self, mailbox): | def subscribe(self, mailbox): | ||||
"""Subscribe""" | """Subscribe""" | ||||
self.__prepare('SUBSCRIBE') | self.__prepare('SUBSCRIBE') | ||||
res, msg = self.__docommand("subscribe", self.decode(mailbox)) | res, msg = self.__docommand("subscribe", self.decode(mailbox)) | ||||
self.__verbose( '[SUBSCRIBE %s] %s: %s' % (mailbox, res, msg[0]) ) | self.__verbose( '[SUBSCRIBE %s] %s: %s' % (mailbox, res, msg[0]) ) | ||||
Lint: PEP8 E201 whitespace after '(' Lint: PEP8 E201: whitespace after '(' | |||||
Lint: PEP8 E202 whitespace before ')' Lint: PEP8 E202: whitespace before ')' | |||||
def unsubscribe(self, mailbox): | def unsubscribe(self, mailbox): | ||||
"""Unsubscribe""" | """Unsubscribe""" | ||||
self.__prepare('UNSUBSCRIBE') | self.__prepare('UNSUBSCRIBE') | ||||
res, msg = self.__docommand("unsubscribe", self.decode(mailbox)) | res, msg = self.__docommand("unsubscribe", self.decode(mailbox)) | ||||
self.__verbose( '[UNSUBSCRIBE %s] %s: %s' % (mailbox, res, msg[0]) ) | self.__verbose( '[UNSUBSCRIBE %s] %s: %s' % (mailbox, res, msg[0]) ) | ||||
Lint: PEP8 E201 whitespace after '(' Lint: PEP8 E201: whitespace after '(' | |||||
Lint: PEP8 E202 whitespace before ')' Lint: PEP8 E202: whitespace before ')' | |||||
whitespace after '['