emailparser 0.1.3 → 0.1.4
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.
- checksums.yaml +4 -4
- data/lib/emailparser.rb +31 -16
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 78bbec2213ee625bdf2c016f60fbe671d2419673
|
4
|
+
data.tar.gz: 2e87bb0f3fb9695e72dd92e8075891259a5d1392
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 58a964d41185c31d3b34002a382acc7e5e067fe649182a8c9990bf5bcd53bd5590631467587da25956575df4b5510b8193c68ed6ca80aa803d924f4eba641adb
|
7
|
+
data.tar.gz: e5a696ac3795db7d0e6ae80c1c196d516506d12b3f6184b78446c9cbe58a3c4c41d7b05f095e209abc4fc0626f87372f4c873751050111ff2552e709dbc5d781
|
data/lib/emailparser.rb
CHANGED
@@ -128,17 +128,23 @@ class Emailparser
|
|
128
128
|
end
|
129
129
|
|
130
130
|
# Voodoo to fix nasty encoded strings
|
131
|
-
def fix_encode(
|
132
|
-
if
|
133
|
-
|
131
|
+
def fix_encode(text)
|
132
|
+
if text.is_a?(String)
|
133
|
+
return text.unpack('C*').pack('U*')
|
134
|
+
elsif text.is_a?(Array)
|
135
|
+
fixed = []
|
136
|
+
text.each do | item |
|
137
|
+
fixed.push(item.unpack('C*').pack('U*'))
|
138
|
+
end
|
139
|
+
return fixed
|
134
140
|
else
|
135
|
-
|
141
|
+
return text
|
136
142
|
end
|
137
143
|
end
|
138
144
|
|
139
145
|
def make_attachment_folder(attachments, source_hash)
|
140
146
|
if (!attachments.empty?)
|
141
|
-
puts "Creating
|
147
|
+
puts "Creating sub-directory: " + source_hash
|
142
148
|
attachments_dir = @attachment_dir + source_hash
|
143
149
|
Dir.mkdir(attachments_dir) if !Dir.exist?(attachments_dir)
|
144
150
|
end
|
@@ -160,28 +166,34 @@ class Emailparser
|
|
160
166
|
|
161
167
|
puts "Loading email: " + @message + "\n"
|
162
168
|
source_hash = Digest::SHA256.hexdigest(File.read(@message))
|
163
|
-
puts "Hash
|
169
|
+
puts "SHA256 Hash: " + source_hash
|
164
170
|
|
165
171
|
email = Mail.read(@message)
|
166
172
|
|
167
173
|
# Defaults
|
168
174
|
source_file = @message.split("/").last
|
175
|
+
|
176
|
+
if email.message_id.nil?
|
177
|
+
message_id = ""
|
178
|
+
else
|
179
|
+
message_id = fix_encode(email.message_id)
|
180
|
+
end
|
169
181
|
|
170
182
|
# Addresses
|
171
183
|
begin
|
172
184
|
email_to = email.to.to_a
|
173
185
|
rescue
|
174
|
-
email_to = [email.to.gsub("<", "").gsub(">", "")]
|
186
|
+
email_to = fix_encode([email.to.gsub("<", "").gsub(">", "")])
|
175
187
|
end
|
176
188
|
begin
|
177
189
|
email_cc = email.cc.to_a
|
178
190
|
rescue
|
179
|
-
email_cc = [email.cc.gsub("<", "").gsub(">", "")]
|
191
|
+
email_cc = fix_encode([email.cc.gsub("<", "").gsub(">", "")])
|
180
192
|
end
|
181
193
|
begin
|
182
194
|
email_from = email.from.to_a
|
183
195
|
rescue
|
184
|
-
email_from = [email.from.gsub("<", "").gsub(">", "")]
|
196
|
+
email_from = fix_encode([email.from.gsub("<", "").gsub(">", "")])
|
185
197
|
end
|
186
198
|
begin
|
187
199
|
recipients = email_to.concat(email_cc)
|
@@ -213,8 +225,11 @@ class Emailparser
|
|
213
225
|
end
|
214
226
|
else
|
215
227
|
puts " - is single part\n"
|
216
|
-
|
217
|
-
|
228
|
+
if email.content_type.start_with?('text/html')
|
229
|
+
body_html = fix_encode(email.body.decoded)
|
230
|
+
else
|
231
|
+
body_plain = fix_encode(email.body.decoded)
|
232
|
+
end
|
218
233
|
end
|
219
234
|
|
220
235
|
# Handle Attachments
|
@@ -259,12 +274,12 @@ class Emailparser
|
|
259
274
|
email_data = {
|
260
275
|
source_file: source_file,
|
261
276
|
source_hash: source_hash,
|
262
|
-
message_id:
|
277
|
+
message_id: message_id,
|
263
278
|
date: email.date,
|
264
|
-
sender:
|
265
|
-
from:
|
266
|
-
to:
|
267
|
-
cc:
|
279
|
+
sender: email_from,
|
280
|
+
from: email_from,
|
281
|
+
to: email_to,
|
282
|
+
cc: email_cc,
|
268
283
|
recipients: recipients,
|
269
284
|
addresses: addresses,
|
270
285
|
subject: subject,
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: emailparser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brennan Novak
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-10 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Parses a signle email file to JSON with attachments
|
14
14
|
email: hi@brennannovak.com
|