示例#1
0
    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
示例#2
0
文件: mails.py 项目: sim0nx/mematool
  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))
示例#3
0
  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
示例#4
0
文件: mails.py 项目: sim0nx/mematool
    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))