emailparser 0.1.0 → 0.1.1
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 +11 -7
- 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: 6998b2ac39dac58639b5ab2762e3a6fe22d59833
|
4
|
+
data.tar.gz: 3bc7226add2c80ce0215c92278c685a27daf0d7f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4bb0c91d61172d5d2e85a4a5abeaef32450719976da8c051622553d943eea11bc69bc89de8e59a2bb3e46fb3da5190c0a02202bf58be4c7436550b9300a13790
|
7
|
+
data.tar.gz: 48d7dcf90f4c4ecb96ea981405ac92a531fe7c1a666bb673cfed970177c4929dcd63a710ec4a2faa5733f44a73241d712cb09b5c8eb935ced5439d8f69a01d91
|
data/lib/emailparser.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'pry'
|
2
2
|
require 'json'
|
3
3
|
require 'mail'
|
4
|
+
require 'digest'
|
4
5
|
|
5
6
|
class Emailparser
|
6
7
|
|
@@ -135,10 +136,10 @@ class Emailparser
|
|
135
136
|
end
|
136
137
|
end
|
137
138
|
|
138
|
-
def make_attachment_folder(attachments,
|
139
|
+
def make_attachment_folder(attachments, source_hash)
|
139
140
|
if (!attachments.empty?)
|
140
|
-
puts "Creating attachments directory: " +
|
141
|
-
attachments_dir = @attachment_dir +
|
141
|
+
puts "Creating attachments directory: " + source_hash
|
142
|
+
attachments_dir = @attachment_dir + source_hash
|
142
143
|
Dir.mkdir(attachments_dir) if !Dir.exist?(attachments_dir)
|
143
144
|
end
|
144
145
|
end
|
@@ -157,7 +158,9 @@ class Emailparser
|
|
157
158
|
# Accepts a message
|
158
159
|
def parse_message
|
159
160
|
|
160
|
-
puts "
|
161
|
+
puts "Loading email: " + @message + "\n"
|
162
|
+
source_hash = Digest::MD5.hexdigest(File.read(@message))
|
163
|
+
puts "Hash of email: " + source_hash
|
161
164
|
|
162
165
|
email = Mail.read(@message)
|
163
166
|
|
@@ -215,7 +218,7 @@ class Emailparser
|
|
215
218
|
end
|
216
219
|
|
217
220
|
# Handle Attachments
|
218
|
-
make_attachment_folder(email.attachments,
|
221
|
+
make_attachment_folder(email.attachments, source_hash)
|
219
222
|
email.attachments.each do | attachment |
|
220
223
|
attachment_save = false
|
221
224
|
filename = fix_encode(attachment.filename)
|
@@ -247,14 +250,15 @@ class Emailparser
|
|
247
250
|
|
248
251
|
# Process Attachment
|
249
252
|
if (attachment_save == true)
|
250
|
-
attachments.push(
|
251
|
-
save_attachment(attachment,
|
253
|
+
attachments.push(source_hash + "/" + filename)
|
254
|
+
save_attachment(attachment, source_hash, filename)
|
252
255
|
end
|
253
256
|
end
|
254
257
|
|
255
258
|
# Structure Data
|
256
259
|
email_data = {
|
257
260
|
source_file: source_file,
|
261
|
+
source_hash: source_hash,
|
258
262
|
message_id: email.message_id,
|
259
263
|
date: email.date,
|
260
264
|
sender: email.from,
|
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.1
|
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-09 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
|