File: from-check.rb

package info (click to toggle)
libtmail-ruby 0.10.8-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 860 kB
  • ctags: 1,458
  • sloc: ruby: 8,406; ansic: 678; objc: 584; yacc: 305; makefile: 142
file content (26 lines) | stat: -rw-r--r-- 528 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#
# checking mail From: header
#

require 'tmail'

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

table = {}    # from-addr-spec => [count, friendly-from]
ld = TMail::MhLoader.new( ARGV[0] )
ld.each_port do |port|
  mail = TMail::Mail.new( port )
  addr, = mail.from_addrs
  if addr then
    (table[addr.spec] ||= [0, mail.friendly_from])[0] += 1
  end
end

table.to_a.sort {|a,b|
    b[1][0] <=> a[1][0]
}.each_with_index do |(spec,(n,from)), i|
  printf "%3d %-33s %d\n", i+1, from, n
end