mailcvt 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/lib/grep_mail.rb CHANGED
@@ -68,7 +68,7 @@ class GrepMail
68
68
 
69
69
  def tolog
70
70
  cols = tocols
71
- cols.join("\t")
71
+ return cols[1], cols.join("\t")
72
72
  end
73
73
 
74
74
  def tocols
data/lib/log_helper.rb CHANGED
@@ -56,11 +56,21 @@ class LogHelper
56
56
  def concatattach(group)
57
57
  v = concatval(group)
58
58
 
59
- pstart = v.index('filename="')
60
- pend = v.rindex('"')
59
+ pstart = v.index('filename=')
60
+ return '' unless pstart
61
+ pstart += 9
61
62
 
62
- return '' if pstart.nil? or pend.nil?
63
- v[(pstart+10)..(pend-1)]
63
+ pend = v.length - 1
64
+ return '' unless pend >= pstart
65
+ if v[pstart] == '"'
66
+ quote2nd = v.rindex('"')
67
+ if quote2nd and quote2nd > pstart
68
+ pstart += 1
69
+ pend = quote2nd - 1
70
+ end
71
+ end
72
+
73
+ v[pstart..pend]
64
74
  end
65
75
 
66
76
  def concatval(group)
data/lib/mail_cleaner.rb CHANGED
@@ -4,7 +4,7 @@ require 'fileutils'
4
4
 
5
5
  class MailCleaner
6
6
  def initialize(output, timestamp)
7
- @fh = OutputHelper.new(output, timestamp)
7
+ @oh = OutputHelper.new(output, timestamp)
8
8
  end
9
9
 
10
10
  def clean
@@ -16,12 +16,12 @@ class MailCleaner
16
16
  def cleantocc
17
17
  move 'tocc2'
18
18
 
19
- d = @fh.getdir("dtocc")
19
+ d = @oh.getdir("dtocc")
20
20
  FileUtils.rm_r(d) if Dir.exists?(d)
21
21
  end
22
22
 
23
23
  def removeok
24
- fok = @fh.getmout('.fok')
24
+ fok = @oh.getmout('.fok')
25
25
  raise "Can't find #{fok}." unless File.exist?(fok)
26
26
 
27
27
  File.foreach(fok) do |line|
@@ -35,9 +35,9 @@ class MailCleaner
35
35
  end
36
36
 
37
37
  def move(suffix)
38
- f = @fh.getmout(".f#{suffix}")
38
+ f = @oh.getmout(".f#{suffix}")
39
39
  return unless File.exist?(f)
40
- d = @fh.getdir("d#{suffix}")
40
+ d = @oh.getdir("d#{suffix}")
41
41
  raise "#{d} exits." if Dir.exist?(d)
42
42
 
43
43
  Dir.mkdir d
@@ -46,7 +46,7 @@ class MailCleaner
46
46
  begin
47
47
  path = line[0..-2]
48
48
  filename = File.basename(path)
49
- File.rename path, File.join(d, filename)
49
+ FileUtils.mv path, File.join(d, filename)
50
50
  hasfile = true
51
51
  rescue Exception => e
52
52
  puts "Can't move file [#{path}] to [#{d}]. \nMessage:#{e.message}"
data/lib/mail_parser.rb CHANGED
@@ -5,51 +5,51 @@ require 'output_helper'
5
5
 
6
6
  class MailParser
7
7
  def initialize(output, timestamp)
8
- @fh = OutputHelper.new(output, timestamp)
8
+ @oh = OutputHelper.new(output, timestamp)
9
9
  end
10
10
 
11
11
  def parse
12
- grep = @fh.getmout('.grep')
12
+ grep = @oh.getmout('.grep')
13
13
  raise "Can't find #{grep}." unless File.exist?(grep)
14
- mlog = @fh.getmout('.mlog')
14
+ mlog = @oh.getmout('.mlog')
15
15
  raise "#{mlog} exits." if File.exist?(mlog)
16
- fok = @fh.getmout('.fok')
16
+ fok = @oh.getmout('.fok')
17
17
  raise "#{fok} exits." if File.exist?(fok)
18
18
 
19
19
  lines = []
20
20
  curfile = nil
21
- @fh.output(mlog, fok) do |omlog, ofok|
22
- File.foreach(grep) do |line|
23
- curfile = @fh.getfile(line) unless curfile
24
- next unless curfile
25
-
26
- if line != "--\n" and !line.start_with?(curfile)
27
- convert curfile, lines, omlog, ofok
28
-
29
- curfile = @fh.getfile(line)
30
- lines = []
31
- end
32
- lines << line
33
- end
21
+ File.foreach(grep) do |line|
22
+ curfile = @oh.getfile(line) unless curfile
23
+ next unless curfile
24
+
25
+ if line != "--\n" and !line.start_with?(curfile)
26
+ convert curfile, lines
34
27
 
35
- convert curfile, lines, omlog, ofok
28
+ curfile = @oh.getfile(line)
29
+ lines = []
30
+ end
31
+ lines << line
36
32
  end
37
- @fh.closetocc
38
- @fh.closeothers
33
+ convert curfile, lines
34
+ @oh.finishoutput
39
35
  end
40
36
 
41
- def convert(curfile, lines, omlog, ofok)
37
+ def convert(curfile, lines)
42
38
  return if lines.length == 0
43
39
 
44
40
  gm = GrepMail.new(curfile, lines, 9)
45
- mlog = gm.tolog
46
- if gm.iscomplete?
47
- omlog.puts mlog
48
- ofok.puts curfile
49
- elsif gm.istocc?
50
- @fh.outputtocc(curfile, mlog)
41
+ msgid, mlog = gm.tolog
42
+ if msgid and smgid.length > 0 and msgid == @prevmsgid
43
+ @oh.outputmlog curfile, nil
51
44
  else
52
- @fh.outputothers(curfile)
45
+ @prevmsgid = msgid
46
+ if gm.iscomplete?
47
+ @oh.outputmlog curfile, mlog
48
+ elsif gm.istocc?
49
+ @oh.outputtocc curfile, mlog
50
+ else
51
+ @oh.outputothers curfile
52
+ end
53
53
  end
54
54
  end
55
55
  end
@@ -1,3 +1,3 @@
1
1
  module Mailcvt
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
3
3
  end
data/lib/output_helper.rb CHANGED
@@ -4,6 +4,11 @@ class OutputHelper
4
4
  def initialize(output, timestamp)
5
5
  @output = output
6
6
  @timestamp = timestamp
7
+
8
+ @mlogcount = 0
9
+ @duplicount = 0
10
+ @tocccount = 0
11
+ @otherscount = 0
7
12
  end
8
13
 
9
14
  def getfile(line)
@@ -20,17 +25,43 @@ class OutputHelper
20
25
  dirname = "#{prefix}#{@timestamp}"
21
26
  File.join(@output, dirname)
22
27
  end
28
+
29
+ def finishoutput
30
+ @omlog.close if @omlog
31
+ @ofok.close if @ofok
32
+
33
+ @omlogtocc.close if @omlogtocc
34
+ @oftocc.close if @oftocc
35
+
36
+ @ofothers.close if @ofothers
23
37
 
24
- def output(f1, f2)
25
- tmp1 = f1 + '.tmp'
26
- tmp2 = f2 + '.tmp'
27
- File.open(tmp1, 'w') do |of1|
28
- File.open(tmp2, 'w') do |of2|
29
- yield of1, of2
30
- end
38
+ totalcount = @mlogcount + @duplicount + @tocccount + @otherscount
39
+ puts "#{totalcount} mails processsed. log = #{countmsg(@mlogcount)}"
40
+ puts " duplicate = #{countmsg(@duplicount)}, tocc = #{countmsg(@tocccount)}, others = #{countmsg(@otherscount)}"
41
+ end
42
+
43
+ def countmsg(count, total)
44
+ if total == 0
45
+ "#{count}(-%)"
46
+ else
47
+ "#{count}(#{count * 100 / total}%)"
31
48
  end
32
- File.rename(tmp1, f1)
33
- File.rename(tmp2, f2)
49
+ end
50
+
51
+ def outputmlog(mailpath, mlog)
52
+ unless @omlog
53
+ mlog = getmout('.mlog')
54
+ @omlog = File.open(mlog, 'w')
55
+ fok = getmout('.fok')
56
+ @ofok = File.open(fok, 'w')
57
+ end
58
+ if mlog
59
+ @omlog.puts mlog
60
+ @mlogcount += 1
61
+ else
62
+ @duplicount += 1
63
+ end
64
+ @ofok.puts mailpath
34
65
  end
35
66
 
36
67
  def outputtocc(mailpath, mlog)
@@ -41,13 +72,9 @@ class OutputHelper
41
72
  @omlogtocc = File.open(mlogtocc, 'w')
42
73
  end
43
74
 
44
- @oftocc.puts mailpath
45
75
  @omlogtocc.puts "#{File.basename(mailpath)}\t#{mlog}"
46
- end
47
-
48
- def closetocc
49
- @oftocc.close if @oftocc
50
- @omlogtocc.close if @omlogtocc
76
+ @oftocc.puts mailpath
77
+ @tocccount += 1
51
78
  end
52
79
 
53
80
  def outputothers(mailpath)
@@ -57,10 +84,7 @@ class OutputHelper
57
84
  end
58
85
 
59
86
  @ofothers.puts mailpath
60
- end
61
-
62
- def closeothers
63
- @ofothers.close if @ofothers
87
+ @otherscount += 1
64
88
  end
65
89
 
66
90
  def outputtocc2(mailpath)
data/lib/to_cc_parser.rb CHANGED
@@ -5,19 +5,19 @@ require 'output_helper'
5
5
 
6
6
  class ToCcParser
7
7
  def initialize(output, timestamp)
8
- @fh = OutputHelper.new(output, timestamp)
8
+ @oh = OutputHelper.new(output, timestamp)
9
9
  end
10
10
 
11
11
  def parse
12
- grep = @fh.getmout('.grep.tocc')
12
+ grep = @oh.getmout('.grep.tocc')
13
13
  raise "Can't find #{grep}." unless File.exist?(grep)
14
- mtocc = @fh.getmout('.mtocc')
14
+ mtocc = @oh.getmout('.mtocc')
15
15
  raise "Can't find #{mtocc}." unless File.exist?(mtocc)
16
- mlog = @fh.getmout('.mlog')
16
+ mlog = @oh.getmout('.mlog')
17
17
  raise "Can't find #{mlog}." unless File.exist?(mlog)
18
18
 
19
19
  parsetocc grep
20
- @fh.closetocc2
20
+ @oh.closetocc2
21
21
 
22
22
  File.open(mlog, 'a') do |omlog|
23
23
  File.foreach(mtocc) do |line|
@@ -48,11 +48,11 @@ class ToCcParser
48
48
  lines = []
49
49
  curfile = nil
50
50
  File.foreach(grep) do |line|
51
- curfile = @fh.getfile(line) unless curfile
51
+ curfile = @oh.getfile(line) unless curfile
52
52
  if line != "--\n" and !line.start_with?(curfile)
53
53
  convert curfile, lines
54
54
 
55
- curfile = @fh.getfile(line)
55
+ curfile = @oh.getfile(line)
56
56
  lines = []
57
57
  end
58
58
  lines << line
@@ -67,7 +67,7 @@ class ToCcParser
67
67
  gm = GrepMail.new(curfile, lines, 300)
68
68
  cols = gm.tocols
69
69
  if gm.istocc?
70
- @fh.outputtocc2(curfile)
70
+ @oh.outputtocc2(curfile)
71
71
  else
72
72
  key = File.basename(curfile)
73
73
  @toccs[key] = cols unless @toccs.has_key?(key)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mailcvt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -120,7 +120,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
120
120
  version: '0'
121
121
  segments:
122
122
  - 0
123
- hash: 422392363216308818
123
+ hash: 1727808477597720220
124
124
  required_rubygems_version: !ruby/object:Gem::Requirement
125
125
  none: false
126
126
  requirements:
@@ -129,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
129
  version: '0'
130
130
  segments:
131
131
  - 0
132
- hash: 422392363216308818
132
+ hash: 1727808477597720220
133
133
  requirements: []
134
134
  rubyforge_project:
135
135
  rubygems_version: 1.8.25