eml2html 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +17 -0
- data/Gemfile +3 -0
- data/LICENSE +22 -0
- data/LICENSE.txt +22 -0
- data/README.md +4 -0
- data/Rakefile +1 -0
- data/bin/eml2html +33 -0
- data/eml2html.gemspec +22 -0
- data/lib/eml2html/converter.rb +96 -0
- data/lib/eml2html/version.rb +3 -0
- data/lib/eml2html.rb +2 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZDJkZmQ0OGM1YzQzMDllZTI4MzY2ZTBlNzg5MmZmMGU3ZTUwNDkyMQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZDJhYzlkMGEzMTUxNTk2ZjRjZThkYTczYjVkOWIzOGVmNmE1NTE5Yg==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
YjM2ZmQyNDc4NjI2NDgzMWJkMDFiN2Y0YzY2NDQxOTI2YWY3NTJjYWZmOWYz
|
10
|
+
OTM0YTViNzUyOTFjODBiZjUzYzEyZTU0NDg1OTFhYjFmYTQwMTEyOGRkMzFi
|
11
|
+
YTU3NGNhNTM1YTRjNmFiYjRkNTE4N2FiZjNhN2M2OTA4MTRlNWM=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MDI3ZjkzNzMwMGQ4YTNlYzFmMDRhZTU5YzI4NDc5ZDM4NWY5ZGYyZjEyOTVh
|
14
|
+
YzcwOTIyNDg2Y2I3Y2M3MDI0ZDBmMDIzNTc3YTBlOGM0NWY0OTFiNjIzOTFm
|
15
|
+
MjA2NjM0YjBhZDI2YzQ1ODY0MmY2ZDkzZjNhOWY1NTI5NTNjMDk=
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Bartek Bułat
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Bartłomiej Bułat
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/eml2html
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'eml2html'
|
4
|
+
|
5
|
+
class CLI
|
6
|
+
USAGE = <<-CONTENT
|
7
|
+
Usage:
|
8
|
+
eml2html filename.eml
|
9
|
+
CONTENT
|
10
|
+
|
11
|
+
def initialize(args)
|
12
|
+
if args.length < 1
|
13
|
+
puts USAGE
|
14
|
+
exit
|
15
|
+
end
|
16
|
+
|
17
|
+
filename = args.shift
|
18
|
+
|
19
|
+
unless File.exists?(filename)
|
20
|
+
puts "File '#{filename}' doesn't exist!"
|
21
|
+
exit
|
22
|
+
end
|
23
|
+
|
24
|
+
@converter = Eml2Html::Converter.new(filename)
|
25
|
+
end
|
26
|
+
|
27
|
+
def run!
|
28
|
+
@converter.save_files!
|
29
|
+
puts "Done!"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
CLI.new(ARGV).run!
|
data/eml2html.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'eml2html/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "eml2html"
|
8
|
+
spec.version = Eml2Html::VERSION
|
9
|
+
spec.authors = ["Bartłomiej Bułat"]
|
10
|
+
spec.email = ["bartek.bulat@gmail.com"]
|
11
|
+
spec.description = %q{eml2html executable for unpacking .eml files into html and attachments}
|
12
|
+
spec.summary = %q{eml2html executable for unpacking .eml files into html and attachments}
|
13
|
+
spec.homepage = "https://github.com/barthez/eml2html"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = ['eml2html']
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'mail'
|
2
|
+
require 'zip'
|
3
|
+
|
4
|
+
module Eml2Html
|
5
|
+
class Attachment
|
6
|
+
attr_reader :cid, :name, :content
|
7
|
+
def initialize(cid, name, content)
|
8
|
+
@cid, @name, @content = cid, name, content
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class Converter
|
13
|
+
def initialize(message)
|
14
|
+
@message = Mail.read(message)
|
15
|
+
@basename = File.basename(message, '.eml')
|
16
|
+
read_attachments
|
17
|
+
end
|
18
|
+
|
19
|
+
def save_files!
|
20
|
+
[:txt, :html, :zip].each do |ext|
|
21
|
+
send(:"save_#{ext}")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def save_txt
|
26
|
+
print "Saving #{filename(:txt)}..."
|
27
|
+
File.write(filename(:txt), text_body)
|
28
|
+
puts "done."
|
29
|
+
end
|
30
|
+
|
31
|
+
def save_html
|
32
|
+
print "Saving #{filename(:html)}..."
|
33
|
+
File.write(filename(:html), html_body)
|
34
|
+
puts "done."
|
35
|
+
end
|
36
|
+
|
37
|
+
def save_zip(options = {})
|
38
|
+
print "Saving #{filename(:zip)}..."
|
39
|
+
Zip::File.open(filename(:zip), Zip::File::CREATE) do |zipfile|
|
40
|
+
if options[:include_html]
|
41
|
+
zipfile.get_output_stream(filename(:html)) do |out|
|
42
|
+
out << html_body
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
if options[:include_text]
|
47
|
+
zipfile.get_output_stream(filename(:txt)) do |out|
|
48
|
+
out << text_body
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
each_attachment do |name, content|
|
53
|
+
zipfile.get_output_stream(name) do |out|
|
54
|
+
out << content
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
puts "done."
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def filename(ext = nil)
|
64
|
+
[@basename, ext].compact.join('.')
|
65
|
+
end
|
66
|
+
|
67
|
+
def text_body
|
68
|
+
@message.text_part.body.to_s
|
69
|
+
end
|
70
|
+
|
71
|
+
def html_body
|
72
|
+
replace_images_src(@message.html_part.body.to_s)
|
73
|
+
end
|
74
|
+
|
75
|
+
def each_attachment
|
76
|
+
@attachments.each do |a|
|
77
|
+
yield a.name, a.content
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def read_attachments
|
82
|
+
@attachments = @message.parts.map do |part|
|
83
|
+
next if part.multipart?
|
84
|
+
name = part['Content-Type'].to_s.split('; ').last[/^filename="(.*)"$/, 1]
|
85
|
+
Attachment.new(part.cid, name, part.body.to_s)
|
86
|
+
end.compact
|
87
|
+
end
|
88
|
+
|
89
|
+
def replace_images_src(html)
|
90
|
+
html.gsub(/(?<=src=['"])(cid:)([^'"]+)(?=['"])/) do |match|
|
91
|
+
cid = match.sub(/^cid:/, '')
|
92
|
+
@attachments.find{|a| a.cid == cid}.name
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
data/lib/eml2html.rb
ADDED
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: eml2html
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bartłomiej Bułat
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: eml2html executable for unpacking .eml files into html and attachments
|
42
|
+
email:
|
43
|
+
- bartek.bulat@gmail.com
|
44
|
+
executables:
|
45
|
+
- eml2html
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- .gitignore
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE
|
52
|
+
- LICENSE.txt
|
53
|
+
- README.md
|
54
|
+
- Rakefile
|
55
|
+
- bin/eml2html
|
56
|
+
- eml2html.gemspec
|
57
|
+
- lib/eml2html.rb
|
58
|
+
- lib/eml2html/converter.rb
|
59
|
+
- lib/eml2html/version.rb
|
60
|
+
homepage: https://github.com/barthez/eml2html
|
61
|
+
licenses:
|
62
|
+
- MIT
|
63
|
+
metadata: {}
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ! '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
requirements: []
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 2.4.4
|
81
|
+
signing_key:
|
82
|
+
specification_version: 4
|
83
|
+
summary: eml2html executable for unpacking .eml files into html and attachments
|
84
|
+
test_files: []
|