mailcvt 0.2.16 → 0.2.17
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/mailcvt +9 -0
- data/lib/encoded_word.rb +79 -0
- data/lib/mailcvt.rb +2 -1
- data/lib/mailcvt/version.rb +1 -1
- metadata +5 -4
data/bin/mailcvt
CHANGED
@@ -119,6 +119,15 @@ command :setup do |c|
|
|
119
119
|
end
|
120
120
|
end
|
121
121
|
|
122
|
+
command :decode do |c|
|
123
|
+
c.action do |global_options,options,args|
|
124
|
+
err = "decode usage: mailcvt decode [mailcvt-output]"
|
125
|
+
raise err unless args.length == 1
|
126
|
+
mi = Decoder.new(args[0])
|
127
|
+
mi.decode
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
122
131
|
pre do |global,command,options,args|
|
123
132
|
# Pre logic here
|
124
133
|
# Return true to proceed; false to abort and not call the
|
data/lib/encoded_word.rb
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'base64'
|
3
|
+
require 'date'
|
4
|
+
|
5
|
+
class EncodedWord
|
6
|
+
def initialize(inputdir)
|
7
|
+
@inputdir = inputdir
|
8
|
+
end
|
9
|
+
|
10
|
+
def decode
|
11
|
+
Dir.glob(File.join(@inputdir, '**/*.mlog')).select do |f|
|
12
|
+
puts f
|
13
|
+
File.open(f + '.plain', 'w') do |out|
|
14
|
+
File.readlines(f).each do |line|
|
15
|
+
parts = line.split("\t")
|
16
|
+
newparts = []
|
17
|
+
newparts << format_date(parts[0]) #date
|
18
|
+
newparts << parts[1] #message-id
|
19
|
+
newparts << decode_subject(parts[2]) #subject
|
20
|
+
newparts << trim_email(parts[3]) #from
|
21
|
+
newparts << trim_email(parts[4]) #to
|
22
|
+
newparts << trim_email(parts[5]) #cc
|
23
|
+
newparts << decode_attachments(parts[6]) unless parts.length == 6 #attachment
|
24
|
+
out.puts newparts.join("\t")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def format_date(engdate)
|
31
|
+
dt = DateTime.parse(engdate)
|
32
|
+
dt = dt.new_offset('+0900')
|
33
|
+
dt.strftime("%Y/%m/%d %H:%M:%S")
|
34
|
+
end
|
35
|
+
|
36
|
+
def decode_subject(sub)
|
37
|
+
one = sub.gsub("\a", '')
|
38
|
+
mime_decode(one)
|
39
|
+
end
|
40
|
+
|
41
|
+
def trim_emails(emails)
|
42
|
+
parts = emails.split("\a")
|
43
|
+
newparts = []
|
44
|
+
parts.each do |p|
|
45
|
+
newparts << trim_email(p)
|
46
|
+
end
|
47
|
+
newparts.join("\a")
|
48
|
+
end
|
49
|
+
|
50
|
+
def trim_email(email)
|
51
|
+
pos1 = email.index('<')
|
52
|
+
if pos1
|
53
|
+
pos1 += 1
|
54
|
+
pos2 = email.index('>', pos1)
|
55
|
+
return email[pos1...pos2]
|
56
|
+
end
|
57
|
+
email.strip
|
58
|
+
end
|
59
|
+
|
60
|
+
def decode_attachments(attachments)
|
61
|
+
parts = attachments.split("\a")
|
62
|
+
newparts = []
|
63
|
+
parts.each do |p|
|
64
|
+
newparts << mime_decode(p)
|
65
|
+
end
|
66
|
+
newparts.join("\a")
|
67
|
+
end
|
68
|
+
|
69
|
+
def mime_decode(input, out_charset = 'utf-8')
|
70
|
+
ret = input.sub!(/=\?([A-Za-z0-9_-]+)\?([BQbq])\?([^\?]+)\?=/) {
|
71
|
+
charset = $1
|
72
|
+
enc = $2.upcase
|
73
|
+
word = $3
|
74
|
+
word = word.unpack({ "B"=>"m*", "Q"=>"M*" }[enc]).first
|
75
|
+
word.encode(out_charset, charset, :undef=>:replace, :invalid=>:replace)
|
76
|
+
}
|
77
|
+
return ret ? mime_decode(input) : input
|
78
|
+
end
|
79
|
+
end
|
data/lib/mailcvt.rb
CHANGED
data/lib/mailcvt/version.rb
CHANGED
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.17
|
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-10-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -90,6 +90,7 @@ files:
|
|
90
90
|
- bin/updatesize
|
91
91
|
- lib/base_parser.rb
|
92
92
|
- lib/big_mail_generator.rb
|
93
|
+
- lib/encoded_word.rb
|
93
94
|
- lib/grep_mail.rb
|
94
95
|
- lib/log_helper.rb
|
95
96
|
- lib/mail_cleaner.rb
|
@@ -122,7 +123,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
122
123
|
version: '0'
|
123
124
|
segments:
|
124
125
|
- 0
|
125
|
-
hash: -
|
126
|
+
hash: -1188711788048111200
|
126
127
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
128
|
none: false
|
128
129
|
requirements:
|
@@ -131,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
131
132
|
version: '0'
|
132
133
|
segments:
|
133
134
|
- 0
|
134
|
-
hash: -
|
135
|
+
hash: -1188711788048111200
|
135
136
|
requirements: []
|
136
137
|
rubyforge_project:
|
137
138
|
rubygems_version: 1.8.25
|