HowTo: Use Multiple Addresses in Gmail Filters
Gmail has incredible filtering, and I forward most of my older addresses to it to take advantage of its spam filtering capabilities before pulling the messages down to my box. Another cool feature is having the ability to tag messages based on some criteria, such as based on who sent a message. The only thing lacking is the user interface for creating these filters, because it doesn’t make readily obvious how to incorporate multiple addresses into one filter.
I’ve incorporated the knowledge gleamed from a google search on the topic into a Ruby script that takes multiple addresses in and returns a filter string that will work with gmail filters. I hope someone else finds it useful! (download)
#!/usr/bin/ruby -w
#
# Gmail supports filters, but the interface provided doesn't make it appear
# to support filtering multiple addresses at the same time. It does,
# and given multiple addresses, this script will return a filter string
# that matches multiple sources.
#
# Author: Robert Peaslee
#
if $*.length < 3
p "Usage: filters.rb ..."
exit( 1 )
end
case $*[0]
when "from"
# Get rid of first element
$*.shift
string = "from:("
$*.each { |addr|
string << "#{addr}) OR from:("
}
string.slice!( -8, string.length )
p "Copy this into the filter:"
p "#{string}"
exit( 0 )
when "to"
# Get rid of first element
$*.shift
string = "to:("
$*.each { |addr|
string << "#{addr}) OR to:("
}
string.slice!( -8, string.length )
p "Copy this into the filter:"
p "#{string}"
exit( 0 )
else
p "Please supply either from or to as the first argument."
exit( 1 )
end