#!/usr/bin/perl -w # $Id: mutt-ldif-query,v 1.4 2011/05/24 12:32:09 mas Exp $ # Copyright (C) 2011 Marc Andre Selig # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # Retrieve information from an LDIF address book file. # Suitable for use as a mutt query command: # mutt query_command="mutt-ldif-query ~/.addr.ldif '%s'" open(my $in, "<", $ARGV[0]) or die "Cannot read $ARGV[0]: $!"; $/ = ""; # slurp whole paragraphs my @addr = (); while (<$in>) { /^cn: (.*)$/m; my $cn = $1; while (s/^mail: (.*)$//m) { push @addr, "$1\t$cn\n"; } } print "Querying $ARGV[0]\n"; # header line for mutt print grep { /$ARGV[1]/oi } @addr;