def getAlias(self, alias): filter_ = '(&(objectClass=mailAlias)(mail=' + str(alias) + '))' attrs = ['*'] basedn = str(Config.get('ldap', 'basedn')) result = self.ldapcon.search_s(basedn, ldap.SCOPE_SUBTREE, filter_, attrs) if not result: raise LookupError('No such alias !') a = Alias() a.dn_mail = alias for dn, attr in result: for k, v in attr.iteritems(): if 'objectClass' in k: # @TODO ignore for now continue elif k == 'mail': if len(v) == 1: a.mail.append(v[0]) else: for i in v: a.mail.append(i) continue elif k == 'maildrop': if len(v) == 1: a.maildrop.append(v[0]) else: for i in v: a.maildrop.append(i) continue else: # @TODO handle multiple results v = v[0] setattr(a, k, v) return a
def doEditAlias(self, items, *args, **kwargs): try: alias = Alias() alias.dn_mail = items['alias'] alias.mail = items['mail'] alias.maildrop = items['maildrop'] if items['mode'] == 'edit': self.mf.updateAlias(alias) else: self.mf.addAlias(alias) self.session['flash'] = _('Alias successfully edited') self.session.save() except Exception as e: import sys, traceback traceback.print_exc(file=sys.stdout) msg = _('Error while editing alias') return self.index(msg=msg) raise HTTPRedirect('/mails/editAlias/?alias={0}'.format(alias.dn_mail))
def doEditAlias(self, items, *args, **kwargs): try: alias = Alias() alias.dn_mail = items["alias"] alias.mail = items["mail"] alias.maildrop = items["maildrop"] if items["mode"] == "edit": self.mf.updateAlias(alias) else: self.mf.addAlias(alias) self.session["flash"] = _("Alias successfully edited") self.session.save() except Exception as e: import sys, traceback traceback.print_exc(file=sys.stdout) msg = _("Error while editing alias") return self.index(msg=msg) raise HTTPRedirect("/mails/editAlias/?alias={0}".format(alias.dn_mail))