mailcvt 0.2.13 → 0.2.15

Sign up to get free protection for your applications and to get access to all the features.
data/bin/mailcvt CHANGED
@@ -64,6 +64,18 @@ command :parsetocc do |c|
64
64
  end
65
65
  end
66
66
 
67
+ desc 'Parse others to mail log.'
68
+ command :parseothers do |c|
69
+ c.action do |global_options,options,args|
70
+ err = "parseothers usage: mailcvt parseothers [daily dir] [timestamp]"
71
+ raise err if args.length != 2
72
+
73
+ raise "Cannot find daily dir #{args[0]}" unless Dir.exists?(args[0])
74
+ tp = OthersParser.new(args[0], args[1])
75
+ tp.parse
76
+ end
77
+ end
78
+
67
79
  desc 'Remove parsed mails and move unprocessed files to special folder.'
68
80
  command :clean do |c|
69
81
  c.action do |global_options,options,args|
@@ -88,6 +100,18 @@ command :cleantocc do |c|
88
100
  end
89
101
  end
90
102
 
103
+ desc 'Delete others folder.'
104
+ command :cleanothers do |c|
105
+ c.action do |global_options,options,args|
106
+ err = "cleanothers usage: mailcvt cleanothers [daily dir] [timestamp]"
107
+ raise err if args.length != 2
108
+
109
+ raise "Cannot find daily dir #{args[0]}" unless Dir.exists?(args[0])
110
+ mp = MailCleaner.new(args[0], args[1])
111
+ mp.cleanothers
112
+ end
113
+ end
114
+
91
115
  command :setup do |c|
92
116
  c.action do |global_options,options,args|
93
117
  mi = SetupMailcvt.new
data/bin/runmailcvt CHANGED
@@ -75,5 +75,18 @@ if [ -d $dtocc ]; then
75
75
  mailcvt cleantocc $dailydir $timestamp
76
76
  fi
77
77
 
78
+ dothers="$dailydir/dothers$timestamp"
79
+ if [ -d $dothers ]; then
80
+ copyonly1 $dothers
81
+ echo "[$(now)] find $dothers -type f -print0 | xargs -0 grep -i -E -A300 \"$grepexp\" > $grepout.others"
82
+ find $dothers -type f -print0 | xargs -0 grep -i -E -A300 "$grepexp" > "$grepout.others"
83
+
84
+ echo "[$(now)] mailcvt parseothers $dailydir $timestamp"
85
+ mailcvt parseothers $dailydir $timestamp
86
+
87
+ echo "[$(now)] mailcvt cleanothers $dailydir $timestamp"
88
+ mailcvt cleanothers $dailydir $timestamp
89
+ fi
90
+
78
91
  echo "[$(now)] runmailcvt finished."
79
92
  echo "-------------------------------------------------------------------------------"
data/lib/base_parser.rb CHANGED
@@ -60,4 +60,12 @@ class BaseParser
60
60
 
61
61
  def convert(curfile, lines)
62
62
  end
63
+
64
+ def isduplicate(msgid)
65
+ return false unless msgid and msgid.length > 0
66
+ return true if @prevmsgid and msgid == @prevmsgid
67
+
68
+ @prevmsgid = msgid
69
+ return false
70
+ end
63
71
  end
data/lib/mail_cleaner.rb CHANGED
@@ -19,14 +19,18 @@ class MailCleaner
19
19
  end
20
20
 
21
21
  def cleantocc
22
- move 'tocc2'
23
-
24
22
  d = @oh.getdir("dtocc")
25
23
  FileUtils.rm_r(d) if Dir.exists?(d)
26
24
 
27
25
  delmout '.grep.tocc'
28
26
  delmout '.mtocc'
29
- delmout '.ftocc2'
27
+ end
28
+
29
+ def cleanothers
30
+ d = @oh.getdir("dothers")
31
+ FileUtils.rm_r(d) if Dir.exists?(d)
32
+
33
+ delmout '.grep.others'
30
34
  end
31
35
 
32
36
  def removeok
data/lib/mail_parser.rb CHANGED
@@ -18,10 +18,9 @@ class MailParser < BaseParser
18
18
 
19
19
  gm = GrepMail.new(curfile, lines, 9)
20
20
  msgid, mlog = gm.tolog
21
- if msgid and msgid.length > 0 and msgid == @prevmsgid
21
+ if isduplicate(msgid)
22
22
  @oh.outputmlog curfile, nil
23
23
  else
24
- @prevmsgid = msgid
25
24
  if gm.iscomplete?
26
25
  @oh.outputmlog curfile, mlog
27
26
  elsif gm.istocc?
data/lib/mailcvt.rb CHANGED
@@ -8,3 +8,4 @@ require 'mail_parser'
8
8
  require 'setup_mailcvt'
9
9
  require 'to_cc_parser'
10
10
  require 'mail_cleaner'
11
+ require 'others_parser.rb'
@@ -1,3 +1,3 @@
1
1
  module Mailcvt
2
- VERSION = '0.2.13'
2
+ VERSION = '0.2.15'
3
3
  end
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'grep_mail'
4
+ require 'output_helper'
5
+ require 'base_parser'
6
+
7
+ class OthersParser < BaseParser
8
+ def parse_with_summary
9
+ grep = shouldexist('.grep.others')
10
+
11
+ parsegrep grep
12
+ @oh.finishoutput
13
+ end
14
+
15
+ def convert(curfile, lines)
16
+ return unless lines and lines.length > 0
17
+
18
+ gm = GrepMail.new(curfile, lines, 300)
19
+ msgid, mlog = gm.tolog
20
+ if isduplicate(msgid)
21
+ @oh.outputmlog_from_others nil
22
+ else
23
+ #output tocc or others mails anyway, better than disk overflow.
24
+ @oh.outputmlog_from_others mlog
25
+ end
26
+ end
27
+ end
data/lib/output_helper.rb CHANGED
@@ -44,7 +44,6 @@ class OutputHelper
44
44
  summary << "\n duplicate = #{countmsg(@duplicount, totalcount)}"
45
45
  summary << ", tocc = #{countmsg(@tocccount, totalcount)}"
46
46
  summary << ", others = #{countmsg(@otherscount, totalcount)}"
47
- summary
48
47
  end
49
48
 
50
49
  def countmsg(count, total)
@@ -96,16 +95,16 @@ class OutputHelper
96
95
  @otherscount += 1
97
96
  end
98
97
 
99
- def outputtocc2(mailpath)
100
- unless @oftocc2
101
- ftocc2 = getmout('.ftocc2')
102
- @oftocc2 = File.open(ftocc2, 'w')
98
+ def outputmlog_from_others(line)
99
+ unless @omlog
100
+ mlog = getmout('.mlog')
101
+ @omlog = File.open(mlog, 'w')
102
+ end
103
+ if line
104
+ @omlog.puts line
105
+ @mlogcount += 1
106
+ else
107
+ @duplicount += 1
103
108
  end
104
-
105
- @oftocc2.puts mailpath
106
- end
107
-
108
- def closetocc2
109
- @oftocc2.close if @oftocc2
110
109
  end
111
110
  end
data/lib/to_cc_parser.rb CHANGED
@@ -8,6 +8,7 @@ class ToCcParser < BaseParser
8
8
  def parse_with_summary
9
9
  grep, mtocc = shouldexist('.grep.tocc', '.mtocc')
10
10
 
11
+ @tocc2count = 0
11
12
  parsetocc grep
12
13
  replace_tocc mtocc
13
14
  end
@@ -15,7 +16,6 @@ class ToCcParser < BaseParser
15
16
  def replace_tocc(mtocc)
16
17
  inputcount = 0
17
18
  replacecount = 0
18
- tocc2count = 0
19
19
  mlog = @oh.getmout('.mlog')
20
20
  File.open(mlog, 'a') do |omlog|
21
21
  File.foreach(mtocc) do |line|
@@ -30,15 +30,13 @@ class ToCcParser < BaseParser
30
30
  cols[4+1] = tocc[4]
31
31
  cols[5+1] = tocc[5]
32
32
  omlog.puts cols[1..-1].join("\t")
33
- else
34
- tocc2count += 1
35
33
  end
36
34
  end
37
35
  end
38
36
 
39
- msg = "#{formatcount(replacecount, inputcount)} replaced. "
40
- msg << "#{formatcount(tocc2count, inputcount)} to others dir. "
41
- msg << "#{formatcount(inputcount - replacecount - tocc2count, inputcount)} ignored. "
37
+ msg = "#{formatcount(replacecount, inputcount)} replaced "
38
+ msg << "(include #{formatcount(@tocc2count, inputcount)} tocc cut). "
39
+ msg << "#{formatcount(inputcount - replacecount, inputcount)} ignored. "
42
40
  msg << "Totally #{inputcount} row#{inputcount > 1 ? 's' : ''} from .mtocc file."
43
41
  end
44
42
 
@@ -57,7 +55,6 @@ class ToCcParser < BaseParser
57
55
  def parsetocc(grep)
58
56
  @toccs = {}
59
57
  parsegrep grep
60
- @oh.closetocc2
61
58
  end
62
59
 
63
60
  def convert(curfile, lines)
@@ -65,12 +62,12 @@ class ToCcParser < BaseParser
65
62
 
66
63
  gm = GrepMail.new(curfile, lines, 300)
67
64
  cols = gm.tocols
68
- if gm.istocc?
69
- @oh.outputtocc2(curfile)
70
- else
71
- key = File.basename(curfile)
72
- @toccs[key] = cols unless @toccs.has_key?(key)
73
- end
65
+ #no need to check duplicate here, cause no COPY_ file in mlog
66
+ #output tocc or others mails anyway, better than disk overflow.
67
+ key = File.basename(curfile)
68
+ @toccs[key] = cols unless @toccs.has_key?(key)
69
+
70
+ @tocc2count += 1 if gm.istocc?
74
71
  end
75
72
  end
76
73
 
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.13
4
+ version: 0.2.15
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-08-30 00:00:00.000000000 Z
12
+ date: 2013-09-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -96,6 +96,7 @@ files:
96
96
  - lib/mail_parser.rb
97
97
  - lib/mailcvt/version.rb
98
98
  - lib/mailcvt.rb
99
+ - lib/others_parser.rb
99
100
  - lib/output_helper.rb
100
101
  - lib/setup_mailcvt.rb
101
102
  - lib/to_cc_parser.rb
@@ -121,7 +122,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
121
122
  version: '0'
122
123
  segments:
123
124
  - 0
124
- hash: 1463266947147316996
125
+ hash: -4026955693453475253
125
126
  required_rubygems_version: !ruby/object:Gem::Requirement
126
127
  none: false
127
128
  requirements:
@@ -130,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
131
  version: '0'
131
132
  segments:
132
133
  - 0
133
- hash: 1463266947147316996
134
+ hash: -4026955693453475253
134
135
  requirements: []
135
136
  rubyforge_project:
136
137
  rubygems_version: 1.8.25