tmail/sample/from-check.rb

#!/usr/local/bin/ruby
#
# check From: in Mh mbox
#

require 'tmail/tmail'

unless ARGV[0] then
  puts "usage:  fromcheck.rb <mhdir>"
  exit 1
end

names = {}
m = TMail::MhLoader.new( ARGV[0] )
m.each_mail do |port|
  tmail = TMail::Mail.new( port )
  n = tmail.from_phrase(nil) || tmail.from
  if names.key? n then
    names[n] += 1
  else
    names[n] = 1
  end
end
i = 1
names.to_a.sort {|a,b| b[1] <=> a[1] }.each do |name,cnt|
  printf "%3d %-33s %d\n", i, name, cnt
  i += 1
end