Quoth Steve Schmerler on Thursday, 02 September 2010: > Hi > > Say I have abook entries like > > [0] > name=Bob B. > [email protected] > nick=bob > notes=friend,coworker > > [1] > name=Alice A. > [email protected] > nick=alice > notes=friend > > Is it possible to query the notes field? > abook --mutt-query friend > abook --mutt-query coworker > > abook returns "Not found" in that case and seems to search only in the > name and email fields. > > The background is that I want to high-jack the notes field to tag > entries with an arbitrary (comma separated) list of tags ("friend", > "coworker") and, for instance, send a mail to all people with the > "friend" tag. > > If that is not possible, what other address book systems do people use > which can handle tags which can be queried? > > Thanks. > > best, > Steve
I have a solution for you. See the attached ruby script. Change .muttrc to read: set query_command="aqua %s" now you can search any or every field. For instance, Query: friend would give you anyone with 'friend' in any field. Query: notes=friend would give you only people who have 'friend' in the 'notes' field. Query state=wa notes=friend name=smith would give you all your friends in Waashington with smith in their name. Note that multiple arguments have an implied AND conjunction. You can also use limited regexen (whatever you can get passed the CLI -- you might have to quote): Query 'name=^(smith|jones)' everyone with either smith or jones at the beginning of their name. Enjoy! -- Sterling (Chip) Camden | [email protected] | 2048D/3A978E4F http://camdensoftware.com | http://chipstips.com | http://chipsquips.com
#!/usr/bin/env ruby
require 'optparse'
abook = '~/.abook/addressbook'
optparse = OptionParser.new do |opts|
opts.banner = 'usage: aqua [-f addressbook] term...'
opts.on('-f', '--file addressbook', 'Specify address book to use') do |file|
abook = file
end
end
begin
optparse.parse!
rescue OptionParser::InvalidOption, OptionParser::MissingArgument => e
puts e
puts optparse
exit 1
end
search = []
ARGV.each do |arg|
if /(\w+?)=(.+)/ =~ arg
key = $1
val = /#{$2}/i
search << lambda {|who| val =~ who[key]}
else
val = /#{arg}/i
search << lambda {|who| who.detect {|k,v| val =~ v}}
end
end
who = nil
puts ""
File.open(File.expand_path abook).each do |line|
case line
when /^\s*$/
puts "#{who['email']}\t#{who['name']}\t#{who['notes']}" if who &&
who['email'] && !search.detect {|s| !s.call(who)}
when /^\[\d+\]/
who = {}
when /^(\w+?)=(.+)/
who[$1] = $2 if who
end
end
pgp4cORg7jiNC.pgp
Description: PGP signature
