Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 69 lines (56 sloc) 1.314 kb
08e6952 @trans initial import
trans authored
1 #
2 # parser benchmark
3 #
4
5 require 'tmail'
6
7
8 if ARGV.empty? then
9 $stderr.puts "usage: #{$0} <mhdir> <mhdir>..."
10 exit 0
11 end
12 ARGV.each do |dname|
13 unless File.directory? dname then
14 $stderr.puts "not directory: #{dname}"
15 exit 1
16 end
17 end
18
19 $stdout.sync = true
20
21 $count = 0
22 $failnum = 0
23 $dirfail = 0
24 $fieldname = ''
25 $dirname = ''
26 $port = nil
27
28 begin
29 ARGV.each do |dirname|
30 $dirname = dirname
31
32 TMail::MhLoader.new( dirname ).each do |port|
33 begin
34 t = TMail::Mail.new( port )
35 $port = port
36
37 t.each_header do |key, field|
38 $fieldname = key
39 next if /received/i === key
40 if ::TMail::StructH === field then
41 field.instance_eval { parse unless @parsed }
42 end
43 end
44 rescue TMail::SyntaxError
45 $stderr.puts "fail in #{$count+1}, field #{$fieldname}"
46 $stderr.puts $!.to_s
47 $failnum += 1
48 $dirfail += 1
49
50 if $failnum % 10 == 0 then
51 puts 'fail = ' + $failnum.to_s
52 #raise
53 end
54 end
55
56 $count += 1
57 puts "end #{$count}" if $count % 50 == 0
58 end
59
60 puts "directory #{dirname} end, fail=#{$dirfail}"
61 $dirfail = 0
62 end
63 rescue
64 puts "at #{$port.inspect}, non ParseError raised"
65 raise
66 end
67
68 puts "parse #{$count} files, fail=#{$failnum}"
Something went wrong with that request. Please try again.