Skip to content

Instantly share code, notes, and snippets.

@gpanders
Last active November 13, 2019 20:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gpanders/e700b59c49d26528a93246a4c3c8facf to your computer and use it in GitHub Desktop.
Save gpanders/e700b59c49d26528a93246a4c3c8facf to your computer and use it in GitHub Desktop.
Query lbdb and cache results into a mutt aliases file
#!/bin/bash
# Query lbdbq and save results to Mutt alias file
set -e
# Mutt aliases file to save results to
ALIASES="$HOME/.cache/mutt/aliases"
# Only save email addresses from $DOMAIN. Leave empty to save all email addresses
DOMAIN="example.com"
query_and_cache() {
results=$(lbdbq "$@" 2>/dev/null)
printf '%s\n' "$results"
# Remove first line from results
results=$(sed '1d' <<< "$results")
# Format results like mutt aliases
sed -E $'s/^([[:alnum:]_.]+)@([[:alnum:]_.]+)\t([[:alnum:] -]+)/alias \\1 \\1@\\2 (\\3)/' <<< "$results" | awk -v domain="$DOMAIN" '$3 ~ domain {$2=tolower($2);print}' >> "$ALIASES"
# Sort and remove duplicates
sort -u -o "$ALIASES" "$ALIASES"
}
query_and_cache "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment