emailparser 0.0.2 → 0.0.3
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 +22 -26
- 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: 2304c0a691076eebca5e22a948876c6881a1f619
|
4
|
+
data.tar.gz: 9ba2f781c48904b04f40a24c70066ad83699be16
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cbe613caba954c78837194e3cd2211149831cd64e9dcec5bbe79f2a1e7bf91b6d86deea89a6d37b311201debbc893e1f72612e92b9a732f1b81d1e26ba9b8179
|
7
|
+
data.tar.gz: 12f1b7217beb86246ef5373924acf2551288fc85acf075228684769ed597f290426aa834d4ffea1212fc0f7830ddda6ecd280b9a8653cfec36b83dbca7a05f58
|
data/lib/emailparser.rb
CHANGED
@@ -4,9 +4,9 @@ require 'mail'
|
|
4
4
|
|
5
5
|
class Emailparser
|
6
6
|
|
7
|
-
def initialize(message, attachment_dir)
|
7
|
+
def initialize(message, out_dir, attachment_dir)
|
8
8
|
@message = message
|
9
|
-
@attachment_dir = attachment_dir
|
9
|
+
@attachment_dir = out_dir + "/" + attachment_dir
|
10
10
|
end
|
11
11
|
|
12
12
|
# Voodoo to fix nasty encoded strings
|
@@ -21,13 +21,19 @@ class Emailparser
|
|
21
21
|
# Accepts a message
|
22
22
|
def parse_message
|
23
23
|
|
24
|
-
|
24
|
+
puts "loading email: " + @message
|
25
25
|
|
26
26
|
email = Mail.read(@message)
|
27
27
|
|
28
28
|
# Defaults
|
29
29
|
source_file = @message.split("/").last
|
30
|
+
|
31
|
+
# Addresses
|
32
|
+
email_to = email.to.to_a
|
33
|
+
recipients = email_to.concat(email.cc.to_a)
|
34
|
+
addresses = recipients + email.from.to_a
|
30
35
|
|
36
|
+
# Subject
|
31
37
|
if email.subject
|
32
38
|
subject = fix_encode(email.subject)
|
33
39
|
else
|
@@ -40,26 +46,12 @@ class Emailparser
|
|
40
46
|
|
41
47
|
# Check for Multipart
|
42
48
|
if email.multipart?
|
43
|
-
|
44
|
-
# Parse Parts
|
45
|
-
email.parts.map do |part|
|
46
|
-
if (part.content_type.start_with?('text/plain'))
|
47
|
-
body_plain = fix_encode(part.body.decoded)
|
48
|
-
elsif (part.content_type.start_with?('text/html'))
|
49
|
-
body_html = fix_encode(part.body.decoded)
|
50
|
-
elsif (part.content_type.start_with?('multipart/alternative'))
|
51
|
-
print "has multipart/alternative\n"
|
52
|
-
else
|
53
|
-
print "has part: " + part.content_type + "\n"
|
54
|
-
end
|
55
|
-
print "-------------------------------------------------------\n"
|
56
|
-
end
|
57
|
-
|
49
|
+
puts "is a multipart email"
|
58
50
|
body_plain = fix_encode(email.text_part.body.decoded)
|
59
51
|
body_html = fix_encode(email.html_part.body.decoded)
|
60
52
|
|
61
53
|
else
|
62
|
-
|
54
|
+
puts "is single part email"
|
63
55
|
body_plain = fix_encode(email.body.decoded)
|
64
56
|
body_html = fix_encode(email.body.decoded)
|
65
57
|
end
|
@@ -70,13 +62,13 @@ class Emailparser
|
|
70
62
|
filename = fix_encode(attachment.filename)
|
71
63
|
attachments.push(filename)
|
72
64
|
print "found attachment " + filename + "\n"
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
65
|
+
begin
|
66
|
+
File.open(@attachment_dir + filename, "w+b", 0644) do |f|
|
67
|
+
f.write attachment.body.decoded
|
68
|
+
end
|
69
|
+
rescue => e
|
70
|
+
puts "Unable to save data for #{filename} because #{e.message}"
|
71
|
+
end
|
80
72
|
end
|
81
73
|
end
|
82
74
|
|
@@ -84,9 +76,13 @@ class Emailparser
|
|
84
76
|
email_data = {
|
85
77
|
source_file: source_file,
|
86
78
|
message_id: email.message_id,
|
79
|
+
date: email.date,
|
80
|
+
sender: email.from,
|
87
81
|
from: email.from,
|
88
82
|
to: email.to,
|
89
83
|
cc: email.cc,
|
84
|
+
recipients: recipients,
|
85
|
+
addresses: addresses,
|
90
86
|
subject: subject,
|
91
87
|
body_plain: body_plain,
|
92
88
|
body_html: body_html,
|
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.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brennan Novak
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-28 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Parses a signle email file to JSON
|
14
14
|
email: hi@brennannovak.com
|