emailparser 0.0.8 → 0.0.9
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 +161 -12
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8bfc0f9967600dabd2fc805e7707ffe6943cb8a
|
4
|
+
data.tar.gz: d0bf062f354ff6d935e774c77f0bf01da550783f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 12887b51a22db8eac462300c4f6ff54e43d05cc2439be2f2c94f05fbe6fbc82fe60989453958e21de5909339cb920e9bcfc9e0ec0c2deb921dd49bba77c36e7d
|
7
|
+
data.tar.gz: 1687ecc1d7e7ebbb922150b602bed4bdc4686a1ecaf5a3064ba497f05df3625ef94f3db9c8b6344e5058ed3fa94581287d2cf3d03cead8909ffa030e7e85d7d7
|
data/lib/emailparser.rb
CHANGED
@@ -7,6 +7,123 @@ class Emailparser
|
|
7
7
|
def initialize(message, out_dir, attachment_dir)
|
8
8
|
@message = message
|
9
9
|
@attachment_dir = out_dir + "/" + attachment_dir
|
10
|
+
@allowed_documents = [
|
11
|
+
'application/x-mobipocket-ebook',
|
12
|
+
'application/epub+zip',
|
13
|
+
'application/rtf',
|
14
|
+
'application/vnd.ms-works',
|
15
|
+
'application/msword',
|
16
|
+
'application/pdf',
|
17
|
+
'application/x-download',
|
18
|
+
'message/rfc822',
|
19
|
+
'text/x-log',
|
20
|
+
'text/scriptlet',
|
21
|
+
'text/plain',
|
22
|
+
'text/iuls',
|
23
|
+
'text/plain',
|
24
|
+
'text/richtext',
|
25
|
+
'text/x-setext',
|
26
|
+
'text/x-component',
|
27
|
+
'text/webviewhtml',
|
28
|
+
'text/h323',
|
29
|
+
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
30
|
+
'application/vnd.oasis.opendocument.text',
|
31
|
+
'application/vnd.oasis.opendocument.text-template',
|
32
|
+
'application/vnd.sun.xml.writer',
|
33
|
+
'application/vnd.sun.xml.writer.template',
|
34
|
+
'application/vnd.sun.xml.writer.global',
|
35
|
+
'application/vnd.stardivision.writer',
|
36
|
+
'application/vnd.stardivision.writer-global',
|
37
|
+
'application/x-starwriter'
|
38
|
+
]
|
39
|
+
@allowed_spreadsheets = [
|
40
|
+
'application/excel',
|
41
|
+
'application/msexcel',
|
42
|
+
'application/vnd.ms-excel',
|
43
|
+
'application/vnd.msexcel',
|
44
|
+
'application/csv',
|
45
|
+
'application/x-csv',
|
46
|
+
'text/tab-separated-values',
|
47
|
+
'text/x-comma-separated-values',
|
48
|
+
'text/comma-separated-values',
|
49
|
+
'text/csv',
|
50
|
+
'text/x-csv',
|
51
|
+
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
52
|
+
'application/vnd.oasis.opendocument.spreadsheet',
|
53
|
+
'application/vnd.oasis.opendocument.spreadsheet-template',
|
54
|
+
'application/vnd.sun.xml.calc',
|
55
|
+
'application/vnd.sun.xml.calc.template',
|
56
|
+
'application/vnd.stardivision.calc',
|
57
|
+
'application/x-starcalc'
|
58
|
+
]
|
59
|
+
@allowed_audio = [
|
60
|
+
'audio/amr',
|
61
|
+
'audio/mp3',
|
62
|
+
'audio/midi',
|
63
|
+
'audio/mid',
|
64
|
+
'audio/mpeg',
|
65
|
+
'audio/basic',
|
66
|
+
'audio/x-aiff',
|
67
|
+
'audio/x-pn-realaudio',
|
68
|
+
'audio/x-pn-realaudio',
|
69
|
+
'audio/mid',
|
70
|
+
'audio/basic',
|
71
|
+
'audio/x-wav',
|
72
|
+
'audio/x-mpegurl',
|
73
|
+
'audio/wave',
|
74
|
+
'audio/wav',
|
75
|
+
'audio/mp4a-latm'
|
76
|
+
]
|
77
|
+
@allowed_contacts = [
|
78
|
+
'text/directory',
|
79
|
+
'text/x-vcard',
|
80
|
+
'text/x-ms-contact'
|
81
|
+
]
|
82
|
+
@allowed_images = [
|
83
|
+
'image/png',
|
84
|
+
'image/jpeg',
|
85
|
+
'image/cis-cod',
|
86
|
+
'image/ief',
|
87
|
+
'image/pipeg',
|
88
|
+
'image/tiff',
|
89
|
+
'image/x-cmx',
|
90
|
+
'image/x-cmu-raster',
|
91
|
+
'image/x-rgb',
|
92
|
+
'image/x-icon',
|
93
|
+
'image/x-xbitmap',
|
94
|
+
'image/x-xpixmap',
|
95
|
+
'image/x-xwindowdump',
|
96
|
+
'image/x-portable-anymap',
|
97
|
+
'image/x-portable-graymap',
|
98
|
+
'image/x-portable-pixmap',
|
99
|
+
'image/x-portable-bitmap',
|
100
|
+
'image/svg+xml',
|
101
|
+
'application/x-photoshop',
|
102
|
+
'application/postscript'
|
103
|
+
]
|
104
|
+
@allowed_slideshows = [
|
105
|
+
'application/powerpoint',
|
106
|
+
'application/vnd.ms-powerpoint',
|
107
|
+
'application/vnd.oasis.opendocument.presentation',
|
108
|
+
'application/vnd.oasis.opendocument.presentation-template',
|
109
|
+
'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
110
|
+
'application/vnd.sun.xml.impress',
|
111
|
+
'application/vnd.sun.xml.impress.template',
|
112
|
+
'application/vnd.stardivision.impress',
|
113
|
+
'application/vnd.stardivision.impress-packed',
|
114
|
+
'application/x-starimpress'
|
115
|
+
]
|
116
|
+
@allowed_videos = [
|
117
|
+
'video/quicktime',
|
118
|
+
'video/x-sgi-movie',
|
119
|
+
'video/mpeg',
|
120
|
+
'video/x-la-asf',
|
121
|
+
'video/x-ms-asf',
|
122
|
+
'video/x-msvideo',
|
123
|
+
'video/mp4',
|
124
|
+
'video/mp2',
|
125
|
+
'video/avi'
|
126
|
+
]
|
10
127
|
end
|
11
128
|
|
12
129
|
# Voodoo to fix nasty encoded strings
|
@@ -18,6 +135,17 @@ class Emailparser
|
|
18
135
|
end
|
19
136
|
end
|
20
137
|
|
138
|
+
def save_attachment(attachment, filename)
|
139
|
+
puts " - found attachment " + filename + "\n"
|
140
|
+
begin
|
141
|
+
File.open(@attachment_dir + filename, "w+b", 0644) do |f|
|
142
|
+
f.write attachment.body.decoded
|
143
|
+
end
|
144
|
+
rescue => e
|
145
|
+
puts "Unable to save data for #{filename} because #{e.message}"
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
21
149
|
# Accepts a message
|
22
150
|
def parse_message
|
23
151
|
|
@@ -65,7 +193,7 @@ class Emailparser
|
|
65
193
|
|
66
194
|
# Check for Multipart
|
67
195
|
if email.multipart?
|
68
|
-
puts "- is
|
196
|
+
puts " - is multipart\n"
|
69
197
|
if email.text_part
|
70
198
|
body_plain = fix_encode(email.text_part.body.decoded)
|
71
199
|
end
|
@@ -73,24 +201,45 @@ class Emailparser
|
|
73
201
|
body_html = fix_encode(email.html_part.body.decoded)
|
74
202
|
end
|
75
203
|
else
|
76
|
-
puts "- is single part
|
204
|
+
puts " - is single part\n"
|
77
205
|
body_plain = fix_encode(email.body.decoded)
|
78
206
|
body_html = fix_encode(email.body.decoded)
|
79
207
|
end
|
80
208
|
|
81
209
|
# Handle Attachments
|
82
210
|
email.attachments.each do | attachment |
|
83
|
-
|
84
|
-
|
211
|
+
attachment_save = false
|
212
|
+
filename = fix_encode(attachment.filename)
|
213
|
+
mime_type, remaining = attachment.content_type.split(';', 2)
|
214
|
+
puts " - Attachment mime: " + mime_type
|
215
|
+
# Check Allowed Mime Types
|
216
|
+
if (@allowed_documents.include? mime_type)
|
217
|
+
puts " - Attachment is: document"
|
218
|
+
attachment_save = true
|
219
|
+
elsif (@allowed_spreadsheets.include? mime_type)
|
220
|
+
puts " - Attachment is: spreadsheet"
|
221
|
+
attachment_save = true
|
222
|
+
elsif (@allowed_audio.include? mime_type)
|
223
|
+
puts " - Attachment is: audio"
|
224
|
+
attachment_save = true
|
225
|
+
elsif (@allowed_contacts.include? mime_type)
|
226
|
+
puts " - Attachment is: contact"
|
227
|
+
attachment_save = true
|
228
|
+
elsif (@allowed_images.include? mime_type)
|
229
|
+
puts " - Attachment is: image"
|
230
|
+
attachment_save = true
|
231
|
+
elsif (@allowed_slideshows.include? mime_type)
|
232
|
+
puts " - Attachment is: slideshow"
|
233
|
+
attachment_save = true
|
234
|
+
elsif (@allowed_videos.include? mime_type)
|
235
|
+
puts " - Attachment is: video"
|
236
|
+
attachment_save = true
|
237
|
+
end
|
238
|
+
|
239
|
+
# Process Attachment
|
240
|
+
if (attachment_save == true)
|
85
241
|
attachments.push(filename)
|
86
|
-
|
87
|
-
begin
|
88
|
-
File.open(@attachment_dir + filename, "w+b", 0644) do |f|
|
89
|
-
f.write attachment.body.decoded
|
90
|
-
end
|
91
|
-
rescue => e
|
92
|
-
puts "Unable to save data for #{filename} because #{e.message}"
|
93
|
-
end
|
242
|
+
save_attachment(attachment, filename)
|
94
243
|
end
|
95
244
|
end
|
96
245
|
|
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
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.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brennan Novak
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-02 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description: Parses a signle email file to JSON
|
13
|
+
description: Parses a signle email file to JSON with attachments
|
14
14
|
email: hi@brennannovak.com
|
15
15
|
executables: []
|
16
16
|
extensions: []
|
@@ -37,8 +37,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
37
37
|
version: '0'
|
38
38
|
requirements: []
|
39
39
|
rubyforge_project:
|
40
|
-
rubygems_version: 2.
|
40
|
+
rubygems_version: 2.5.1
|
41
41
|
signing_key:
|
42
42
|
specification_version: 4
|
43
|
-
summary: Parses a single email file to JSON
|
43
|
+
summary: Parses a single email file to JSON with attachments
|
44
44
|
test_files: []
|