Changeset View
Changeset View
Standalone View
Standalone View
cyruslib.py
Show First 20 Lines • Show All 378 Lines • ▼ Show 20 Lines | class CYRUS: | ||||
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 as info: | ||||
error = str(info).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): | ||||
Show All 14 Lines | class CYRUS: | ||||
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) | ||||
self.AUTH = True | self.AUTH = True | ||||
self.id() | self.id() | ||||
admin = self.m.isadmin() | admin = self.m.isadmin() | ||||
except Exception, info: | except Exception as info: | ||||
self.AUTH = False | self.AUTH = False | ||||
error = str(info).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() | ||||
Show All 16 Lines | def login_plain(self, username, password, asUser = None): | ||||
else: | else: | ||||
self.ADMIN = asUser | self.ADMIN = asUser | ||||
self.AUSER = asUser | self.AUSER = asUser | ||||
self.SEP = self.m.getsep() | self.SEP = self.m.getsep() | ||||
def logout(self): | def logout(self): | ||||
try: | try: | ||||
res, msg = self.m.logout() | res, msg = self.m.logout() | ||||
except Exception, info: | except Exception as info: | ||||
error = str(info).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]) ) | ||||
def getEncoding(self): | def getEncoding(self): | ||||
▲ Show 20 Lines • Show All 112 Lines • ▼ Show 20 Lines | def lam(self, 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 | ||||
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 as info: | ||||
self.__verbose( '[GETACL %s] BAD: %s' % (mailbox, info.args[0]) ) | self.__verbose( '[GETACL %s] BAD: %s' % (mailbox, info.args[0]) ) | ||||
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) ) | ||||
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""" | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | def lqr(self, mailbox): | ||||
self.__verbose( '[GETQUOTAROOT %s] BAD: Error while parsing results' % mailbox ) | self.__verbose( '[GETQUOTAROOT %s] BAD: Error while parsing results' % mailbox ) | ||||
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: | ||||
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) ) | ||||
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]) ) | ||||
def getannotation(self, mailbox, pattern='*'): | def getannotation(self, mailbox, pattern='*'): | ||||
"""Get Annotation""" | """Get Annotation""" | ||||
self.__prepare('GETANNOTATION') | self.__prepare('GETANNOTATION') | ||||
Show All 40 Lines | def getannotation(self, mailbox, pattern='*'): | ||||
key = annotation.split('"')[3].replace('"','').replace("'","").strip() | key = annotation.split('"')[3].replace('"','').replace("'","").strip() | ||||
_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() | ||||
except ValueError, errmsg: | except ValueError: | ||||
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() | ||||
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() | ||||
except Exception, errmsg: | except Exception: | ||||
pass | pass | ||||
except Exception, errmsg: | except Exception: | ||||
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() | ||||
except: | except: | ||||
Show All 10 Lines | def getannotation(self, mailbox, pattern='*'): | ||||
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() | ||||
except ValueError, errmsg: | except ValueError: | ||||
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() | ||||
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() | ||||
except Exception, errmsg: | except Exception: | ||||
pass | pass | ||||
except Exception, errmsg: | except Exception: | ||||
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() | ||||
except: | except: | ||||
▲ Show 20 Lines • Show All 83 Lines • Show Last 20 Lines |