mailcvt 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/base_parser.rb +58 -0
- data/lib/grep_mail.rb +7 -5
- data/lib/mail_cleaner.rb +7 -1
- data/lib/mail_parser.rb +8 -29
- data/lib/mailcvt/version.rb +1 -1
- data/lib/output_helper.rb +17 -8
- data/lib/to_cc_parser.rb +26 -28
- metadata +6 -5
data/lib/base_parser.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'grep_mail'
|
4
|
+
require 'output_helper'
|
5
|
+
|
6
|
+
class BaseParser
|
7
|
+
def initialize(output, timestamp)
|
8
|
+
@oh = OutputHelper.new(output, timestamp)
|
9
|
+
end
|
10
|
+
|
11
|
+
def shouldexist(*exts)
|
12
|
+
paths = []
|
13
|
+
exts.each do |ext|
|
14
|
+
path = @oh.getmout(ext)
|
15
|
+
raise "Can't find #{path}" unless File.exist?(path)
|
16
|
+
paths << path
|
17
|
+
end
|
18
|
+
|
19
|
+
return paths[0] if paths.length == 1
|
20
|
+
paths
|
21
|
+
end
|
22
|
+
|
23
|
+
def shouldabsent(*exts)
|
24
|
+
exts.each do |ext|
|
25
|
+
path = @oh.getmout(ext)
|
26
|
+
raise "#{path} already exists." if File.exist?(path)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def parse
|
31
|
+
summary = parse_with_summary
|
32
|
+
puts summary
|
33
|
+
end
|
34
|
+
|
35
|
+
def parse_with_summary
|
36
|
+
end
|
37
|
+
|
38
|
+
def parsegrep(grep)
|
39
|
+
lines = []
|
40
|
+
curfile = nil
|
41
|
+
File.foreach(grep) do |line|
|
42
|
+
curfile = @oh.getfile(line) unless curfile
|
43
|
+
next unless curfile
|
44
|
+
|
45
|
+
if line != "--\n" and !line.start_with?(curfile)
|
46
|
+
convert curfile, lines
|
47
|
+
|
48
|
+
curfile = @oh.getfile(line)
|
49
|
+
lines = []
|
50
|
+
end
|
51
|
+
lines << line
|
52
|
+
end
|
53
|
+
convert curfile, lines
|
54
|
+
end
|
55
|
+
|
56
|
+
def convert(curfile, lines)
|
57
|
+
end
|
58
|
+
end
|
data/lib/grep_mail.rb
CHANGED
@@ -3,16 +3,16 @@
|
|
3
3
|
require 'log_helper'
|
4
4
|
|
5
5
|
class GrepMail
|
6
|
-
def initialize(file,
|
6
|
+
def initialize(file, lines_has_newline, maxval)
|
7
7
|
@maxval = maxval
|
8
8
|
@pcontent= file.length + 1
|
9
|
-
grouplines(
|
9
|
+
grouplines(lines_has_newline)
|
10
10
|
end
|
11
11
|
|
12
|
-
def grouplines(
|
12
|
+
def grouplines(lines_has_newline)
|
13
13
|
@groups = []
|
14
14
|
valend = false
|
15
|
-
|
15
|
+
lines_has_newline.each do |line|
|
16
16
|
dlm = line[@pcontent-1]
|
17
17
|
if dlm == ':'
|
18
18
|
finish_multiline_value
|
@@ -34,6 +34,8 @@ class GrepMail
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|
37
|
+
|
38
|
+
finish_multiline_value
|
37
39
|
end
|
38
40
|
|
39
41
|
def finish_multiline_value
|
@@ -43,7 +45,7 @@ class GrepMail
|
|
43
45
|
end
|
44
46
|
|
45
47
|
def keyvalue(line)
|
46
|
-
if is_content_key?(@pcontent)
|
48
|
+
if is_content_key?(line, @pcontent)
|
47
49
|
dlm = ';'
|
48
50
|
else
|
49
51
|
dlm = ':'
|
data/lib/mail_cleaner.rb
CHANGED
@@ -44,7 +44,7 @@ class MailCleaner
|
|
44
44
|
hasfile = false
|
45
45
|
File.foreach(f) do |line|
|
46
46
|
begin
|
47
|
-
path = line
|
47
|
+
path = getpath(line)
|
48
48
|
filename = File.basename(path)
|
49
49
|
FileUtils.mv path, File.join(d, filename)
|
50
50
|
hasfile = true
|
@@ -55,4 +55,10 @@ class MailCleaner
|
|
55
55
|
|
56
56
|
Dir.rmdir d unless hasfile
|
57
57
|
end
|
58
|
+
|
59
|
+
def getpath(line)
|
60
|
+
start = 0
|
61
|
+
start = 1 if line[0] == '#'
|
62
|
+
line[start..-2]
|
63
|
+
end
|
58
64
|
end
|
data/lib/mail_parser.rb
CHANGED
@@ -2,44 +2,23 @@
|
|
2
2
|
|
3
3
|
require 'grep_mail'
|
4
4
|
require 'output_helper'
|
5
|
+
require 'base_parser'
|
5
6
|
|
6
|
-
class MailParser
|
7
|
-
def
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
def parse
|
12
|
-
grep = @oh.getmout('.grep')
|
13
|
-
raise "Can't find #{grep}." unless File.exist?(grep)
|
14
|
-
mlog = @oh.getmout('.mlog')
|
15
|
-
raise "#{mlog} exits." if File.exist?(mlog)
|
16
|
-
fok = @oh.getmout('.fok')
|
17
|
-
raise "#{fok} exits." if File.exist?(fok)
|
18
|
-
|
19
|
-
lines = []
|
20
|
-
curfile = nil
|
21
|
-
File.foreach(grep) do |line|
|
22
|
-
curfile = @oh.getfile(line) unless curfile
|
23
|
-
next unless curfile
|
7
|
+
class MailParser < BaseParser
|
8
|
+
def parse_with_summary
|
9
|
+
grep = shouldexist('.grep')
|
10
|
+
shouldabsent('.mlog', '.fok')
|
24
11
|
|
25
|
-
|
26
|
-
convert curfile, lines
|
27
|
-
|
28
|
-
curfile = @oh.getfile(line)
|
29
|
-
lines = []
|
30
|
-
end
|
31
|
-
lines << line
|
32
|
-
end
|
33
|
-
convert curfile, lines
|
12
|
+
parsegrep grep
|
34
13
|
@oh.finishoutput
|
35
14
|
end
|
36
15
|
|
37
16
|
def convert(curfile, lines)
|
38
|
-
return
|
17
|
+
return unless lines and lines.length > 0
|
39
18
|
|
40
19
|
gm = GrepMail.new(curfile, lines, 9)
|
41
20
|
msgid, mlog = gm.tolog
|
42
|
-
if msgid and
|
21
|
+
if msgid and msgid.length > 0 and msgid == @prevmsgid
|
43
22
|
@oh.outputmlog curfile, nil
|
44
23
|
else
|
45
24
|
@prevmsgid = msgid
|
data/lib/mailcvt/version.rb
CHANGED
data/lib/output_helper.rb
CHANGED
@@ -35,9 +35,16 @@ class OutputHelper
|
|
35
35
|
|
36
36
|
@ofothers.close if @ofothers
|
37
37
|
|
38
|
+
getsummary
|
39
|
+
end
|
40
|
+
|
41
|
+
def getsummary
|
38
42
|
totalcount = @mlogcount + @duplicount + @tocccount + @otherscount
|
39
|
-
|
40
|
-
|
43
|
+
summary = "#{totalcount} mails processsed. log = #{countmsg(@mlogcount, totalcount)}"
|
44
|
+
summary << "\n duplicate = #{countmsg(@duplicount, totalcount)}"
|
45
|
+
summary << ", tocc = #{countmsg(@tocccount, totalcount)}"
|
46
|
+
summary << ", others = #{countmsg(@otherscount, totalcount)}"
|
47
|
+
summary
|
41
48
|
end
|
42
49
|
|
43
50
|
def countmsg(count, total)
|
@@ -48,23 +55,25 @@ class OutputHelper
|
|
48
55
|
end
|
49
56
|
end
|
50
57
|
|
51
|
-
def outputmlog(mailpath,
|
58
|
+
def outputmlog(mailpath, line)
|
52
59
|
unless @omlog
|
53
60
|
mlog = getmout('.mlog')
|
54
61
|
@omlog = File.open(mlog, 'w')
|
55
62
|
fok = getmout('.fok')
|
56
63
|
@ofok = File.open(fok, 'w')
|
57
64
|
end
|
58
|
-
if
|
59
|
-
@omlog.puts
|
65
|
+
if line
|
66
|
+
@omlog.puts line
|
60
67
|
@mlogcount += 1
|
68
|
+
@ofok.puts mailpath
|
61
69
|
else
|
62
70
|
@duplicount += 1
|
71
|
+
@ofok.write '#'
|
72
|
+
@ofok.puts mailpath
|
63
73
|
end
|
64
|
-
@ofok.puts mailpath
|
65
74
|
end
|
66
75
|
|
67
|
-
def outputtocc(mailpath,
|
76
|
+
def outputtocc(mailpath, line)
|
68
77
|
unless @oftocc
|
69
78
|
ftocc = getmout('.ftocc')
|
70
79
|
@oftocc = File.open(ftocc, 'w')
|
@@ -72,7 +81,7 @@ class OutputHelper
|
|
72
81
|
@omlogtocc = File.open(mlogtocc, 'w')
|
73
82
|
end
|
74
83
|
|
75
|
-
@omlogtocc.puts "#{File.basename(mailpath)}\t#{
|
84
|
+
@omlogtocc.puts "#{File.basename(mailpath)}\t#{line}"
|
76
85
|
@oftocc.puts mailpath
|
77
86
|
@tocccount += 1
|
78
87
|
end
|
data/lib/to_cc_parser.rb
CHANGED
@@ -2,37 +2,47 @@
|
|
2
2
|
|
3
3
|
require 'grep_mail'
|
4
4
|
require 'output_helper'
|
5
|
+
require 'base_parser'
|
5
6
|
|
6
|
-
class ToCcParser
|
7
|
-
def
|
8
|
-
|
9
|
-
end
|
10
|
-
|
11
|
-
def parse
|
12
|
-
grep = @oh.getmout('.grep.tocc')
|
13
|
-
raise "Can't find #{grep}." unless File.exist?(grep)
|
14
|
-
mtocc = @oh.getmout('.mtocc')
|
15
|
-
raise "Can't find #{mtocc}." unless File.exist?(mtocc)
|
16
|
-
mlog = @oh.getmout('.mlog')
|
17
|
-
raise "Can't find #{mlog}." unless File.exist?(mlog)
|
7
|
+
class ToCcParser < BaseParser
|
8
|
+
def parse_with_summary
|
9
|
+
grep, mtocc = shouldexist('.grep.tocc', '.mtocc')
|
18
10
|
|
19
11
|
parsetocc grep
|
20
|
-
|
12
|
+
replace_tocc mtocc
|
13
|
+
end
|
21
14
|
|
15
|
+
def replace_tocc(mtocc)
|
16
|
+
inputcount = 0
|
17
|
+
replacecount = 0
|
18
|
+
outputcount = 0
|
19
|
+
mlog = @oh.getmout('.mlog')
|
22
20
|
File.open(mlog, 'a') do |omlog|
|
23
21
|
File.foreach(mtocc) do |line|
|
22
|
+
inputcount += 1
|
24
23
|
cols = splitmlog(line)
|
25
24
|
next unless cols
|
26
25
|
|
27
26
|
fn = cols[0]
|
28
27
|
if @toccs.has_key?(fn)
|
28
|
+
replacecount += 1
|
29
29
|
tocc = @toccs[fn]
|
30
30
|
cols[4+1] = tocc[4]
|
31
31
|
cols[5+1] = tocc[5]
|
32
32
|
end
|
33
|
+
outputcount += 1
|
33
34
|
omlog.puts cols[1..-1].join("\t")
|
34
35
|
end
|
35
36
|
end
|
37
|
+
|
38
|
+
msg = "#{formatcount(replacecount, inputcount)} replaced. "
|
39
|
+
msg << "#{formatcount(outputcount - replacecount, inputcount)} output without change. "
|
40
|
+
msg << "#{formatcount(inputcount - outputcount , inputcount)} ignored. "
|
41
|
+
msg << "Totally #{inputcount} row#{inputcount > 1 ? 's' : ''} from .mtocc file."
|
42
|
+
end
|
43
|
+
|
44
|
+
def formatcount(part, total)
|
45
|
+
"#{part}(#{total == 0 ? '-' : part * 100 / total}%) row#{part > 1 ? 's' : ''}"
|
36
46
|
end
|
37
47
|
|
38
48
|
def splitmlog(linehasn, colcount = 7)
|
@@ -45,24 +55,12 @@ class ToCcParser
|
|
45
55
|
|
46
56
|
def parsetocc(grep)
|
47
57
|
@toccs = {}
|
48
|
-
|
49
|
-
|
50
|
-
File.foreach(grep) do |line|
|
51
|
-
curfile = @oh.getfile(line) unless curfile
|
52
|
-
if line != "--\n" and !line.start_with?(curfile)
|
53
|
-
convert curfile, lines
|
54
|
-
|
55
|
-
curfile = @oh.getfile(line)
|
56
|
-
lines = []
|
57
|
-
end
|
58
|
-
lines << line
|
59
|
-
end
|
60
|
-
|
61
|
-
convert curfile, lines
|
58
|
+
parsegrep grep
|
59
|
+
@oh.closetocc2
|
62
60
|
end
|
63
61
|
|
64
62
|
def convert(curfile, lines)
|
65
|
-
return
|
63
|
+
return unless lines and lines.length > 0
|
66
64
|
|
67
65
|
gm = GrepMail.new(curfile, lines, 300)
|
68
66
|
cols = gm.tocols
|
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.
|
4
|
+
version: 0.2.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-08-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -88,16 +88,17 @@ files:
|
|
88
88
|
- bin/mailcvt
|
89
89
|
- bin/runmailcvt
|
90
90
|
- bin/updatesize
|
91
|
+
- lib/base_parser.rb
|
91
92
|
- lib/big_mail_generator.rb
|
92
93
|
- lib/grep_mail.rb
|
93
94
|
- lib/log_helper.rb
|
94
95
|
- lib/mail_cleaner.rb
|
95
96
|
- lib/mail_parser.rb
|
97
|
+
- lib/mailcvt/version.rb
|
96
98
|
- lib/mailcvt.rb
|
97
99
|
- lib/output_helper.rb
|
98
100
|
- lib/setup_mailcvt.rb
|
99
101
|
- lib/to_cc_parser.rb
|
100
|
-
- lib/mailcvt/version.rb
|
101
102
|
- README.rdoc
|
102
103
|
- mailcvt.rdoc
|
103
104
|
homepage: http://github.com/ryu-kahou/mailcvt
|
@@ -120,7 +121,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
120
121
|
version: '0'
|
121
122
|
segments:
|
122
123
|
- 0
|
123
|
-
hash:
|
124
|
+
hash: -1276762649925627637
|
124
125
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
126
|
none: false
|
126
127
|
requirements:
|
@@ -129,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
129
130
|
version: '0'
|
130
131
|
segments:
|
131
132
|
- 0
|
132
|
-
hash:
|
133
|
+
hash: -1276762649925627637
|
133
134
|
requirements: []
|
134
135
|
rubyforge_project:
|
135
136
|
rubygems_version: 1.8.25
|