Feature request and my dirty patch: placeholders %u, %d in LDAP query_filter

Mark Martinec Mark.Martinec+amavis at ijs.si
Sun Jul 1 22:37:28 CEST 2012

Zhang Huangbin,

> The default placeholder, %m, in LDAP query filter will generate unwanted
> query values (e.g. @.domain.ltd, @domain.ltd, @.),  and no exact domain
> name (without prepended '@'). It would be great to support placeholders %u
> and %d in LDAP query_filter.
> - %u: local part of email address. e.g. replaced by 'username' if email
> address is 'username at domain.ltd'. - %d: domain part of email address. e.g.
> replaced by 'domain.ltd' if email address is 'username at domain.ltd'.
> With these two new placeholders, we can clearly query mail user and mail
> domain in ldap filter. e.g.
> - (&(objectClass=amavisAccount)(mail=%u@%d))
> - (&(objectClass=amavisAccount)(domainName=%d))
> Attachment is my dirty patch (i don't know Perl) for
> amavisd-new-2.8.0-pre7, tested and works for me.

Your suggestion is good, but was too close to my release schedule,
so it will have to wait. Better still, it would make sense to
allow for LDAP the same or similar set of placeholders as they are
available for SQL lookups. Here is the relevant code from the
SQL section:

  # The SQL select clause to fetch per-recipient policy settings.
  # The %k will be replaced by a comma-separated list of query addresses
  # for a recipient (e.g. a full address, domain only, catchall), %a will be
  # replaced by an exact recipient address (same as the first entry in %k,
  # suitable for pattern matching), %l by a full unmodified localpart, %u by
  # a lowercased username (a localpart without extension), %e by lowercased
  # addr extension (which includes a delimiter), and %d for lowercased domain.
  my($keys_ref,$rhs_ref) = make_query_keys($addr, ...
  # substitute %k for a list of keys, %a for unmodified full mail address,
  # %l for full unmodified localpart, %u for lowercased username (a localpart
  # without extension), %e for lowercased extension, %d for lowercased domain,
  # and ? for each extra argument
  $sel =~ s{ ( %[kaluedL] | \? ) }
           { push(@pos_args,
                  $1 eq '%k' ? map([$_,$datatype], @$keys_ref)
                : $1 eq '%a' ? [$rhs_ref->[0], $datatype] #full addr
                : $1 eq '%l' ? [$rhs_ref->[1], $datatype] #localpart
                : $1 eq '%u' ? [$rhs_ref->[2], $datatype] #username
                : $1 eq '%e' ? [$rhs_ref->[3], $datatype] #extension
                : $1 eq '%d' ? [$rhs_ref->[4], $datatype] #domain
                   #*** (%L is experimental, incomplete)
                : $1 eq '%L' ? [($is_local?'1':'0'), SQL_BOOLEAN] #is local
                : shift @extras_tmp),
             $1 eq '%k' ? join(',', ('?') x $n) : '?' }gxe;


More information about the amavis-users mailing list