MUTT_LDAP_QUERY(1)
π MUTT_LDAP_QUERY(1) π
okay bestie, welcome to the manual for mutt_ldap_query from the User Contributed Perl Documentation section. It's giving "query an LDAP server for Mutt mail-reader" and honestly? iconic. β¨
πΈ NAME πΈ
mutt_ldap_query β query LDAP server for Mutt mail-reader. That's the name, that's the game. π
β¨ SYNOPSIS β¨
mutt_ldap_query.pl [options] <name_to_query> [[<other_name_to_query>] ...]
π OPTIONS π
--config=config_fileor-c config_fileβ specify an alternate resource file other than the system ones (/etc/lbdb_ldap.rcor/etc/mutt_ldap_query.rc) or the default personal ones ($XDG_CONFIG_HOME/lbdb/ldap.rc,$HOME/.lbdb/ldap.rcor$HOME/.mutt_ldap_query.rc). ποΈ--server=ldap_serveror-ls ldap_serverβ hostname of your LDAP server. You can also use anldap://foo[:port]orldaps://foo[:port]URL here to talk to different ports or SSL encrypted servers. Or useldapi://%2fvar%2flib%2fldap_sockto access an LDAP server via a socket (use%2fas a replacement for a slash in the file name). π--search_base=ldap_search_baseor-sb ldap_search_baseβ use<search_base>as the starting point for the search instead of the default. π³--search_fields=ldap_search_fieldsor-sf ldap_search_fieldsβ list of the fields on which the query will be performed. π--expected_answers=ldap_expected_answersor-ea ldap_expected_answersβ list of the fields expected as the answer of the LDAP server that will be used for composing the output of the script. π--format_email=result_format_emailor-fe result_format_emailβ format to be used for composing the email output result. It has to be based on the expected LDAP server answers and can use variable containers of the form${variable}wherevariablebelongs to the<ldap_expected_answers>set. π§--format_realname=result_format_realnameor-fr result_format_realnameβ format to be used for composing the realname output result. It has to be based on the expected LDAP server answers and can use variable containers of the form${variable}wherevariablebelongs to the<ldap_expected_answers>set. πͺͺ--format_comment=result_format_commentor-fc result_format_commentβ format to be used for composing the comment output result. It has to be based on the expected LDAP server answers and can use variable containers of the form${variable}wherevariablebelongs to the<ldap_expected_answers>set. π¬--bind_dn=bind_distinguished_nameor-bd bind_distinguished_nameβ the distinguished name of the user who binds to the LDAP server. Leave it empty for an anonymous bind. π--bind_password=secretor-bp secretβ the bind password for binding to the LDAP server. Leave it empty for an anonymous bind. π€«--tls=1or--tls=0β enable or disable transport layer security (TLS). π--sasl_mech=mechanismor-sm mechanismβ the SASL mechanism, for exampleGSSAPI(empty string to turn off). π‘οΈ--scope=ldap_scopeβ The default search applies to the whole tree. Specifying the optional scope parameter allows the search to be limited in various ways. Some valid values include:'base','one','sub','subtree','children'. See the Net::LDAP CPAN documentation for more information. π²--nickname=ldap_server_nicknameor-n ldap_server_nicknameβ shortcut for avoiding to use all the previous options by using the script builtin or alternate config file table of common servers and associated options. All the required parameters are then derived by performing a<lbdb_server_nickname>lookup. π·οΈ--debugor-dβ turn on debugging messages. π--helpor-?or-hor--manor-mβ generates this help message. π--ignorantor-iβ ignorant mode: search using wildcard for*name_to_query*(requires a longer processing from LDAP server but is quite convenient :). π--lbdb_outputor-lβ suppress number of matches output (suited for interfacing with little brother databasehttps://www.spinnaker.de/lbdb/). π€--versionor-vβ show the version. π’
π¦ DESCRIPTION π¦
mutt_ldap_query performs ldap queries using either ldapsearch command or the perl-ldap module and it outputs the required formatted data for feeding mutt when using its "External Address Query" feature.
The output of the script consists in 3 fields separated with tabs: the email address, the name of the person and a comment.
π INTERFACING WITH MUTT π
This perl script can be interfaced with mutt by defining in your .muttrc:
set query_command = "mutt_ldap_query.pl %s"
Multiple requests are supported: the "Q" command of mutt accepts as argument a list of queries (e.g. "Gosse de\ Courville").
Alternatively mutt_ldap_query can be interfaced with the more generic little brother database query program (https://www.spinnaker.de/lbdb/) using:
set query_command = "lbdbq %s"
and by specifying in your ~/.lbdb/lbdbrc file another method of query just adding to the METHODS variable the m_ldap module e.g.:
METHODS='m_inmail m_passwd m_ldap m_muttalias m_finger'
and the right path to access m_ldap in MODULES_PATH, e.g. if you moved m_ldap in ~/.lbdb/modules:
MODULES_PATH="/usr/local/lib $HOME/.lbdb/modules"
Just make sure to use the correct path for calling mutt_ldap_query in the m_ldap script.
π RESOURCE FILE FORMAT π
mutt_ldap_query is now fully customizable using an external resource file. By default mutt_ldap_query parses the system definition file located generally at /etc/mutt_ldap_query.rc or /usr/local/etc/mutt_ldap_query.rc and also the user one: $HOME/.mutt_ldap_query.rc.
Instead of using command line options, the user can redefine all the variables using the resource file by two manners in order to match his site configuration. A file example is provided below:
# The format of each entry of the ldap server database is the following:
# LDAP_NICKNAME => ['LDAP_SERVER',
# 'LDAP_SEARCH_BASE',
# 'LDAP_SEARCH_FIELDS',
# 'LDAP_EXPECTED_ANSWERS',
# 'LDAP_RESULT_EMAIL',
# 'LDAP_RESULT_REALNAME',
# 'LDAP_RESULT_COMMENT'],
# a practical illustrating example being:
# debian => ['ldaps://db.debian.org',
# 'ou=users,dc=debian,dc=org',
# 'uid cn sn ircnick gecos',
# 'uid cn sn ircnick',
# '${uid}@debian.org',
# '${cn} ${sn}',
# '${ircnick}',
# 1],
# the output of the query will be then:
# ${uid}@debian.org\t${cn} ${sn}\t${ircnick} (i.e.: email name comment)
# (Note, that db.debian.org stores the firstname (instead of the common
# name) in cn, while the common name is only in gecos field (as a prefix),
# so we have to search gecos and enable ignorant flag to support wildcard
# search)
# warning this database will erase default script builtin
%ldap_server_db = (
'four11' => ['ldap.four11.com',
'c=US',
'givenname sn cn mail',
'givenname cn sn mail o',
'${mail}',
'${givenname} ${sn}',
'${o}' ],
'infospace' => ['ldap.infospace.com',
'c=US',
'givenname sn cn mail',
'givenname cn sn mail o',
'${mail}',
'${givenname} ${sn}',
'${o}' ],
'whowhere' => ['ldap.whowhere.com',
'c=US',
'givenname sn cn mail',
'givenname cn sn mail o',
'${mail}',
'${givenname} ${sn}',
'${o}' ],
'bigfoot' => ['ldap.bigfoot.com',
'c=US',
'givenname sn cn mail'
, 'givenname cn sn mail o'
, '${mail}'
, '${givenname} ${sn}',
'${o}' ],
'switchboard' => ['ldap.switchboard.com',
'c=US',
'givenname sn cn mail'
, 'givenname cn sn mail o',
'${mail}',
'${givenname} ${sn}',
'${o}' ],
'infospacebiz' => ['ldapbiz.infospace.com',
'c=US',
'givenname sn cn mail',
'givenname cn sn mail o',
'${mail}',
'${givenname} ${sn}',
'${o}' ],
);
# hostname of your ldap server
$ldap_server = 'ldap.four11.com';
# ldap base search
$search_base = 'c=US';
# list of the fields that will be used for the query
$ldap_search_fields = 'givenname sn cn mail';
# list of the fields that will be used for composing the answer
$ldap_expected_answers = 'givenname sn cn mail o';
# format of the email result based on the expected answers of the ldap query
$ldap_result_email = '${mail}';
# format of the realname result based on the expected answers of the ldap query
$ldap_result_realname = '${givenname} ${sn}';
# format of the comment result based on the expected answers of the ldap query
$ldap_result_comment = '(${o})';
πΈ EXAMPLES OF QUERIES πΈ
Okay bestie, this is where it all comes together, so lock in π
mutt_ldap_query.pl --ldap_server='ldap.mot.com' \
--search_base='ou=employees, o=Motorola,c=US' \
--ldap_search_fields='commonName gn sn cn uid' \
--ldap_expected_answers='gn sn preferredRfc822Recipient ou c telephonenumber' \
--ldap_result_email='${preferredRfc822Recipient}' \
--ldap_result_realname='${gn} ${sn}' \
--ldap_result_comment='(${telephonenumber}) ${ou} ${c}' \
Gosse de\ Courville
So what is this actually doing, you ask? It runs a query against the LDAP server ldap.mot.com, using the search base 'ou=employees, o=Motorola,c=US', and it searches the fields 'commonName gn sn cn uid' for 'Gosse' and then "de Courville". Then it looks for the answers 'gn sn preferredRfc822Recipient ou c telephonenumber'. Based on those answers, mutt_ldap_query hands back a list of entries shaped like this:
<${preferredRfc822Recipient}>\t${gn} ${sn}\t(${telephonenumber}) ${ou} ${c}
And those ${} thingies? They're containers that get swapped out for whatever the query actually returns. Very main-character of them β¨
Now here's the glow-up: that whole giant query can be massively simplified by using the LDAP server mini-database feature of the resource file β just drop in a nickname, like so:
mutt_ldap_query.pl --ldap_server_nickname='motorola' Gosse de\ Courville
Obsessed. π
And when you're not sure of the full name (say, you know it should contain Courville), the ignorant mode is your bestie, because the query gets performed with wildcards β so *Courville* in this case:
mutt_ldap_query.pl --ignorant Courville
Slay. That's the whole toolkit, go forth and find people π¦
π WHERE TO GET IT π
The latest version can be retrieved at
ftp://ftp.mutt.org/pub/mutt/contrib or
http://www.courville.org/
Heads up, bestie π‘ β the script is now integrated into the latest version of the little brother database, available at https://www.spinnaker.de/lbdb/. So it's genuinely easier to use it through that standard package than to hand-customize it to fit your system/distribution needs. No cap.
π REFERENCES π
- perl-ldap module β
http://perl-ldap.sourceforge.net/ - mutt is the ultimate email client β
http://www.mutt.org/ - historical Brandon Blong's "External Address Query" feature patch for mutt β
http://www.fiction.net/blong/programs/mutt/#query - little brother database is an interface query program for mutt that allow multiple searches for email addresses based on external query scripts just like this one 8-) β
https://www.spinnaker.de/lbdb/
π AUTHORS π
Marc de Courville <marc@courville.org> and the various other contributors... that kindly sent their patches. π«Ά
Please report any bugs, or post any suggestions, to <marc@courville.org>.
π COPYRIGHT π
Copyright (c) 1998-2003 Marc de Courville <marc@courville.org>. All rights reserved. This program is free software; you can redistribute it and/or modify it under the GNU General Public License (GPL). See http://www.opensource.org/gpl-license.html and http://www.opensource.org/.
And that's the whole page, babe β this one was generated by perl v5.40.1, dated 2026-01-10, and it's the MUTT_LDAP_QUERY(1) manual page, periodt π
β¨
π¦ where this page comes from
- ubuntu resolute: lbdb 0.57-1 Β· GPL-2.0-or-later
- ubuntu stonking: lbdb 0.57-1 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms