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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/emailparser.rb +11 -7
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5e2190c9de315bdca71d4698ef17f0c8f661c516
4
- data.tar.gz: 5ce860b1920126fd6f09be564ad15f720d99c1ac
3
+ metadata.gz: 6998b2ac39dac58639b5ab2762e3a6fe22d59833
4
+ data.tar.gz: 3bc7226add2c80ce0215c92278c685a27daf0d7f
5
5
  SHA512:
6
- metadata.gz: 9bdb187b9330bb47b332b5c8431431819c43e40256019f801e3e431455e4e8dbc3db09fda5a92cfd6f5f91ea3a88a7d5e2f94d2f089737b5c57f9730952dd225
7
- data.tar.gz: ebb5ebef9df35b28d4ef30888d0c3807fad8b4385bb045ee961a8ed203dc3a5815e7fa8485092eeec1980c1198432db7a310be4fd97668ea8ab33d05dd8c5ccd
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, message_id)
139
+ def make_attachment_folder(attachments, source_hash)
139
140
  if (!attachments.empty?)
140
- puts "Creating attachments directory: " + message_id
141
- attachments_dir = @attachment_dir + message_id
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 "loading email: " + @message + "\n"
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, email.message_id)
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(email.message_id + "/" + filename)
251
- save_attachment(attachment, email.message_id, filename)
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.0
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-02 00:00:00.000000000 Z
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