mailcvt 0.1.43 → 0.1.44
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/runmailcvt +4 -12
- data/bin/updatesize +12 -0
- data/lib/grep_mail.rb +16 -5
- data/lib/log_helper.rb +7 -5
- data/lib/mail_parser.rb +2 -0
- data/lib/mailcvt/version.rb +1 -1
- data/lib/output_helper.rb +2 -2
- data/lib/setup_mailcvt.rb +1 -1
- data/lib/to_cc_parser.rb +18 -12
- metadata +10 -10
- data/lib/line_converter.rb +0 -58
data/bin/runmailcvt
CHANGED
@@ -43,8 +43,8 @@ fi
|
|
43
43
|
copyonly1 $maildir
|
44
44
|
allmail=$maildir/*
|
45
45
|
grepexp="^Date: |^Message-ID: |^Subject: |^From: |^To: |^Cc: |^Content-Disposition: attachment;"
|
46
|
-
echo "[$(now)] grep -E -A9 \"$grepexp\" $allmail > $grepout"
|
47
|
-
grep -E -A9 "$grepexp" $allmail > $grepout
|
46
|
+
echo "[$(now)] grep -i -E -A9 \"$grepexp\" $allmail > $grepout"
|
47
|
+
grep -i -E -A9 "$grepexp" $allmail > $grepout
|
48
48
|
|
49
49
|
bindir=$(cd $(dirname $0) && pwd)
|
50
50
|
rubydir=$(cd $(dirname $(dirname $(dirname $bindir))) && pwd)
|
@@ -60,8 +60,8 @@ dtocc="$dailydir/dtocc$timestamp"
|
|
60
60
|
if [ -d $dtocc ]; then
|
61
61
|
copyonly1 $dtocc
|
62
62
|
alldtocc="$dtocc/*"
|
63
|
-
echo "[$(now)] grep -E -
|
64
|
-
grep -E -
|
63
|
+
echo "[$(now)] grep -i -E -A300 \"^To: |^Cc: \" $alldtocc > $grepout.tocc"
|
64
|
+
grep -i -E -A300 "^To: |^Cc: " $alldtocc > "$grepout.tocc"
|
65
65
|
|
66
66
|
echo "[$(now)] mailcvt parsetocc $dailydir $timestamp"
|
67
67
|
mailcvt parsetocc $dailydir $timestamp
|
@@ -70,13 +70,5 @@ if [ -d $dtocc ]; then
|
|
70
70
|
mailcvt cleantocc $dailydir $timestamp
|
71
71
|
fi
|
72
72
|
|
73
|
-
echo "[$(now)] update reject size."
|
74
|
-
recipient=/etc/postfix/recipient_access
|
75
|
-
size=$({ du -sh $maildir; du -sh $dailydir; } | sed "s/\t.*$//g" | tr '\n' ' ')
|
76
|
-
cursec=$(date +"%m%d%H%M%S")
|
77
|
-
sed -i "s/REJECT\t.*$/REJECT\t$size$cursec/g" $recipient
|
78
|
-
postmap $recipient
|
79
|
-
|
80
|
-
|
81
73
|
echo "[$(now)] runmailcvt finished."
|
82
74
|
echo "-------------------------------------------------------------------------------"
|
data/bin/updatesize
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
set -e
|
4
|
+
maildir=$(cd $1 && pwd)
|
5
|
+
dailydir=$(cd $2 && pwd)/$(date +"%Y%m%d")
|
6
|
+
|
7
|
+
recipient=/etc/postfix/recipient_access
|
8
|
+
size=$({ du -sh $maildir; du -sh $dailydir; } | sed "s/\t.*$//g" | tr '\n' ' ')
|
9
|
+
cursec=$(date +"%m%d%H%M%S")
|
10
|
+
sed -i "s/REJECT\t.*$/REJECT\t$size$cursec/g" $recipient
|
11
|
+
postmap $recipient
|
12
|
+
postfix reload
|
data/lib/grep_mail.rb
CHANGED
@@ -4,9 +4,9 @@ require 'log_helper'
|
|
4
4
|
|
5
5
|
class GrepMail
|
6
6
|
def initialize(file, lines, maxval)
|
7
|
+
@maxval = maxval
|
7
8
|
@pcontent= file.length + 1
|
8
9
|
grouplines(lines)
|
9
|
-
@maxval = maxval
|
10
10
|
end
|
11
11
|
|
12
12
|
def grouplines(lines)
|
@@ -43,7 +43,7 @@ class GrepMail
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def keyvalue(line)
|
46
|
-
if
|
46
|
+
if is_content_key?(@pcontent)
|
47
47
|
dlm = ';'
|
48
48
|
else
|
49
49
|
dlm = ':'
|
@@ -54,15 +54,26 @@ class GrepMail
|
|
54
54
|
return line[@pcontent..pos], line[(pos+2)..-2]
|
55
55
|
end
|
56
56
|
|
57
|
+
def is_content_key?(line, start)
|
58
|
+
return false unless line and line.length > start + 1
|
59
|
+
return false unless line[start].upcase == 'C' and line[start+1].downcase == 'o'
|
60
|
+
true
|
61
|
+
end
|
62
|
+
|
57
63
|
def valueonly(line)
|
58
64
|
cap = line[@pcontent]
|
59
65
|
return nil if cap != ' ' and cap != "\t"
|
60
|
-
line[(@pcontent+1)..-2]
|
66
|
+
line[(@pcontent+1)..-2]
|
61
67
|
end
|
62
68
|
|
63
69
|
def tolog
|
70
|
+
cols = tocols
|
71
|
+
cols.join("\t")
|
72
|
+
end
|
73
|
+
|
74
|
+
def tocols
|
64
75
|
lh = LogHelper.new(@groups)
|
65
|
-
|
76
|
+
cols = lh.tocols
|
66
77
|
|
67
78
|
toccok = lh.tocc_complete?
|
68
79
|
othersok = lh.others_complete?
|
@@ -73,7 +84,7 @@ class GrepMail
|
|
73
84
|
elsif othersok
|
74
85
|
@istocc = true
|
75
86
|
end
|
76
|
-
|
87
|
+
cols
|
77
88
|
end
|
78
89
|
|
79
90
|
def iscomplete?
|
data/lib/log_helper.rb
CHANGED
@@ -22,16 +22,18 @@ class LogHelper
|
|
22
22
|
@valends[0] && @valends[1] && @valends[2] && @valends[3] && @valends[6]
|
23
23
|
end
|
24
24
|
|
25
|
-
def
|
25
|
+
def tocols
|
26
26
|
@valends = Array.new(7, true)
|
27
27
|
cols = Array.new(6)
|
28
28
|
|
29
29
|
@groups.each do |g|
|
30
|
-
|
31
|
-
|
30
|
+
key = g[:key]
|
31
|
+
next unless key and key.length > 1
|
32
|
+
|
33
|
+
cap = key[0].upcase
|
32
34
|
next unless @@ids.has_key?(cap)
|
33
35
|
|
34
|
-
if cap == 'C' and
|
36
|
+
if cap == 'C' and key[1].downcase == 'o'
|
35
37
|
cols << concatattach(g)
|
36
38
|
@valends[-1] &= isvalend?(g)
|
37
39
|
else
|
@@ -42,7 +44,7 @@ class LogHelper
|
|
42
44
|
end
|
43
45
|
end
|
44
46
|
|
45
|
-
cols
|
47
|
+
cols
|
46
48
|
end
|
47
49
|
|
48
50
|
def isvalend?(group)
|
data/lib/mail_parser.rb
CHANGED
data/lib/mailcvt/version.rb
CHANGED
data/lib/output_helper.rb
CHANGED
@@ -8,7 +8,7 @@ class OutputHelper
|
|
8
8
|
|
9
9
|
def getfile(line)
|
10
10
|
pos = line.index(':')
|
11
|
-
return
|
11
|
+
return nil unless pos
|
12
12
|
line[0..(pos-1)]
|
13
13
|
end
|
14
14
|
|
@@ -42,7 +42,7 @@ class OutputHelper
|
|
42
42
|
end
|
43
43
|
|
44
44
|
@oftocc.puts mailpath
|
45
|
-
@omlogtocc.puts "#{mailpath}\t#{mlog}"
|
45
|
+
@omlogtocc.puts "#{File.basename(mailpath)}\t#{mlog}"
|
46
46
|
end
|
47
47
|
|
48
48
|
def closetocc
|
data/lib/setup_mailcvt.rb
CHANGED
@@ -16,7 +16,7 @@ class SetupMailcvt
|
|
16
16
|
File.delete jobfile if File.exist?(jobfile)
|
17
17
|
|
18
18
|
newmaildir = File.join(Dir.home, 'Maildir/new')
|
19
|
-
File.open(jobfile, 'w') { |f| f.puts "
|
19
|
+
File.open(jobfile, 'w') { |f| f.puts "5 * * * * #{get_run_path} #{newmaildir} #{@output}" }
|
20
20
|
`crontab #{jobfile}`
|
21
21
|
File.delete jobfile
|
22
22
|
end
|
data/lib/to_cc_parser.rb
CHANGED
@@ -21,23 +21,28 @@ class ToCcParser
|
|
21
21
|
|
22
22
|
File.open(mlog, 'a') do |omlog|
|
23
23
|
File.foreach(mtocc) do |line|
|
24
|
-
|
24
|
+
cols = splitmlog(line)
|
25
|
+
next unless cols
|
25
26
|
|
26
|
-
|
27
|
-
parts = oldlog.split("\t")
|
28
|
-
next if parts.nil? or parts.length < 7
|
29
|
-
|
30
|
-
fn = parts[0]
|
27
|
+
fn = cols[0]
|
31
28
|
if @toccs.has_key?(fn)
|
32
29
|
tocc = @toccs[fn]
|
33
|
-
|
34
|
-
|
30
|
+
cols[4+1] = tocc[4]
|
31
|
+
cols[5+1] = tocc[5]
|
35
32
|
end
|
36
|
-
omlog.puts
|
33
|
+
omlog.puts cols[1..-1].join("\t")
|
37
34
|
end
|
38
35
|
end
|
39
36
|
end
|
40
37
|
|
38
|
+
def splitmlog(linehasn, colcount = 7)
|
39
|
+
return nil unless linehasn and linehasn.length >= colcount
|
40
|
+
cols = linehasn.split("\t")
|
41
|
+
return nil if cols.length < colcount
|
42
|
+
cols[-1] = cols[-1][0..-2]
|
43
|
+
cols
|
44
|
+
end
|
45
|
+
|
41
46
|
def parsetocc(grep)
|
42
47
|
@toccs = {}
|
43
48
|
lines = []
|
@@ -59,12 +64,13 @@ class ToCcParser
|
|
59
64
|
def convert(curfile, lines)
|
60
65
|
return if lines.length == 0
|
61
66
|
|
62
|
-
gm = GrepMail.new(curfile, lines,
|
63
|
-
|
67
|
+
gm = GrepMail.new(curfile, lines, 300)
|
68
|
+
cols = gm.tocols
|
64
69
|
if gm.istocc?
|
65
70
|
@fh.outputtocc2(curfile)
|
66
71
|
else
|
67
|
-
|
72
|
+
key = File.basename(curfile)
|
73
|
+
@toccs[key] = cols unless @toccs.has_key?(key)
|
68
74
|
end
|
69
75
|
end
|
70
76
|
end
|
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.1.
|
4
|
+
version: 0.1.44
|
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-07-
|
12
|
+
date: 2013-07-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -84,20 +84,20 @@ extra_rdoc_files:
|
|
84
84
|
- README.rdoc
|
85
85
|
- mailcvt.rdoc
|
86
86
|
files:
|
87
|
-
- bin/mailcvt
|
88
87
|
- bin/lock-runmailcvt
|
88
|
+
- bin/mailcvt
|
89
89
|
- bin/runmailcvt
|
90
|
-
-
|
91
|
-
- lib/mailcvt.rb
|
90
|
+
- bin/updatesize
|
92
91
|
- lib/big_mail_generator.rb
|
93
|
-
- lib/mail_parser.rb
|
94
|
-
- lib/line_converter.rb
|
95
92
|
- lib/grep_mail.rb
|
96
93
|
- lib/log_helper.rb
|
94
|
+
- lib/mail_cleaner.rb
|
95
|
+
- lib/mail_parser.rb
|
96
|
+
- lib/mailcvt.rb
|
97
97
|
- lib/output_helper.rb
|
98
98
|
- lib/setup_mailcvt.rb
|
99
|
-
- lib/mail_cleaner.rb
|
100
99
|
- lib/to_cc_parser.rb
|
100
|
+
- lib/mailcvt/version.rb
|
101
101
|
- README.rdoc
|
102
102
|
- mailcvt.rdoc
|
103
103
|
homepage: http://github.com/ryu-kahou/mailcvt
|
@@ -120,7 +120,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
120
120
|
version: '0'
|
121
121
|
segments:
|
122
122
|
- 0
|
123
|
-
hash:
|
123
|
+
hash: -4130757654178801639
|
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:
|
132
|
+
hash: -4130757654178801639
|
133
133
|
requirements: []
|
134
134
|
rubyforge_project:
|
135
135
|
rubygems_version: 1.8.25
|
data/lib/line_converter.rb
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
class LineConverter
|
4
|
-
@@hkeys = {
|
5
|
-
'D' => {key: 'Date:', begin: 5, id: 0},
|
6
|
-
'M' => {key: 'Message-ID:', begin: 11, id: 1},
|
7
|
-
'S' => {key: 'Subject:', begin: 8, id: 2},
|
8
|
-
'F' => {key: 'From:', begin: 5, id: 3},
|
9
|
-
'T' => {key: 'To:', begin: 3, id: 4}
|
10
|
-
}
|
11
|
-
ATTACH = 'Content-Disposition: attachment; filename="'
|
12
|
-
|
13
|
-
def initialize
|
14
|
-
@hvals = Array.new(5, "")
|
15
|
-
@attach = ""
|
16
|
-
end
|
17
|
-
|
18
|
-
def log
|
19
|
-
line = ""
|
20
|
-
@hvals.each {|v| line << "#{v}\t"}
|
21
|
-
line << @attach
|
22
|
-
end
|
23
|
-
|
24
|
-
def convert(line)
|
25
|
-
cap = line[0]
|
26
|
-
if not @hfinished
|
27
|
-
convertheader(cap, line)
|
28
|
-
else
|
29
|
-
convertbody(cap, line)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def convertheader(cap, line)
|
34
|
-
if cap == nil or cap == "\n" or cap == ''
|
35
|
-
@hfinished = true
|
36
|
-
return
|
37
|
-
end
|
38
|
-
|
39
|
-
if cap == "\t" or cap == ' '
|
40
|
-
@hvals[@hk[:id]] += "\a#{line.strip}" if @hk
|
41
|
-
else
|
42
|
-
if @@hkeys.has_key?(cap)
|
43
|
-
@hk = @@hkeys[cap]
|
44
|
-
@hvals[@hk[:id]] = line[@hk[:begin]..-1].strip if line.start_with?(@hk[:key])
|
45
|
-
else
|
46
|
-
@hk = nil
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def convertbody(cap, line)
|
52
|
-
if cap == 'C' and line.start_with?(ATTACH)
|
53
|
-
@attach << "\a" if not @attach.empty?
|
54
|
-
@attach << line[43..-3] # filename"\n
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|