ref: 2b8f0f70933ab69c811a11601538628cf1337e96 gpanders.com/content/blog/caching-ldap-queries-in-mutt.md -rw-r--r-- 1.8 KiB
2b8f0f70Gregory Anders Remove root directory from zipped site 4 months ago

#title: "Caching LDAP Queries in Mutt" date: 2020-03-11 tags: [mutt, ldap]

You can use the lbdb tool to query an LDAP server within Mutt using the query_command setting. Setting up lbdb is out of scope for this article, although you can find plenty of documentation and examples online (here and here, for instance). One drawback to this approach, however, is that everytime you want to look up a recipient in Mutt you have to query your LDAP server, which can be quite slow.

A workaround to this problem is to "cache" the results of prior LDAP queries into a Mutt aliases file. That way you only have to query lbdb once, and future recipients can be found in the aliases file, which is significantly faster.

The following script does exactly this: {{< gist gpanders e700b59c49d26528a93246a4c3c8facf >}}

The script queries your LDAP server using lbdbq and returns those "raw" results to Mutt so that you can make your selection. However, it also reformats the output and saves it to an aliases file for Mutt to use later.

Save this script to ~/.lbdb/query.sh, make it executable, and use it in Mutt's query_command setting:

set query_command = "~/.lbdb/query.sh '%s'"

Now, everytime you make a query in Mutt the results will be saved to $HOME/.cache/mutt/aliases. Obviously, you need to tell Mutt to read from this alias file as well:

set alias_file = ~/.cache/mutt/aliases
source $alias_file

One caveat to this is that Mutt only reads the alias file on startup, so any changes to that file will not be detected unless you manually run :source $alias_file or restart Mutt.