01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
#!/usr/local/bin/ruby
require 'mailread'
require 'ftools'
require 'md5'
require 'getopts'
class String
def shorten(len = 50)
require 'nkf'
lines = NKF.nkf( "-e -f#{len}", self.gsub( /\n/, ' ' ) ).split(/\n/)
lines[0].concat( '..' ) if lines[0] and lines[1]
lines[0] || ''
end
end
cache = {}
total = 0
ARGV.each do |dir|
Dir.new(dir).entries.grep(/^\d+$/).sort{|a,b| a.to_i <=> b.to_i}.each do |f|
path = dir + "/" + f
m = Mail.new(path)
md5 = MD5::new(m.body.join("") + m["subject"].to_s).digest
if cache[md5] then
# puts "#{f} == #{cache[md5]}\t(#{m["subject"]})"
puts "#{cache[md5]}\t#{m["subject"].to_s.shorten}"
total += File.size(path)
end
cache[md5] = path
end
end
puts "Total: #{total}"