email_spy 1.0.0

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.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in emailspy.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Kurtis Rainbolt-Greene
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
@@ -0,0 +1,35 @@
1
+ # email_spy
2
+
3
+ A simple gem that allows you to catch emails sent from your Rails app into your browser.
4
+
5
+ Based entirely on letter_opener, with bug fixes and real versioning.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'email_spy'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install emailspy
20
+
21
+ ## Usage
22
+
23
+ To start using email_spy simply add this line to your `config/environments/development.rb` file:
24
+
25
+ ``` ruby
26
+ config.action_mailer.delivery_method = :email_spy
27
+ ```
28
+
29
+ ## Contributing
30
+
31
+ 1. Fork it
32
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
33
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
34
+ 4. Push to the branch (`git push origin my-new-feature`)
35
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
data/email_spy.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/email_spy/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Kurtis Rainbolt-Greene"]
6
+ gem.email = ["kurtisrainboltgreene@gmail.com"]
7
+ gem.description = %q{Opens up your Rails emails}
8
+ gem.summary = gem.description
9
+ gem.homepage = "http://github.com/krainboltgreene/email_spy"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "email_spy"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = EmailSpy::VERSION
17
+
18
+ gem.add_dependency 'launchy'
19
+ gem.add_development_dependency 'rspec'
20
+ gem.add_development_dependency 'mail'
21
+ end
@@ -0,0 +1,22 @@
1
+ module EmailSpy
2
+ class DeliveryMethod
3
+ attr_accessor :settings
4
+
5
+ def initialize(options = {})
6
+ @settings = { location: File.join('.', 'email_spy') }
7
+ @settings.merge! options
8
+ end
9
+
10
+ def deliver!(email)
11
+ time = Time.now.to_i
12
+ hash = Digest::SHA1.hexdigest(email.encoded)[0..6]
13
+ location = File.join settings[:location], "#{time}_#{hash}"
14
+
15
+ messages = email.parts.map { |part| Message.new location, email, part }
16
+ messages << Message.new location, email if messages.empty?
17
+ messages.each &:render
18
+
19
+ Launchy.open URI.parse "file://#{messages.first.filepath}"
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,88 @@
1
+ <meta http-equiv="Content-Type" content="text/html; charset=<%= encoding %>">
2
+ <style type="text/css">
3
+ #message_headers {
4
+ position: relative;
5
+ top: 0px;
6
+ left: 0;
7
+ width: 100%;
8
+ height: 85px;
9
+ padding: 10px 0 0 0;
10
+ margin: 0;
11
+ margin-bottom:20px;
12
+ background: #fff;
13
+ font-size: 12px;
14
+ font-family: "Lucida Grande";
15
+ border-bottom: 1px solid #dedede;
16
+ overflow: hidden;
17
+ }
18
+
19
+ #message_headers dl {
20
+ margin: 0;
21
+ padding: 0;
22
+ }
23
+
24
+ #message_headers dt {
25
+ width: 60px;
26
+ padding: 1px;
27
+ float: left;
28
+ text-align: right;
29
+ font-weight: bold;
30
+ color: #7f7f7f;
31
+ }
32
+
33
+ #message_headers dd {
34
+ margin-left: 70px;
35
+ padding: 1px;
36
+ }
37
+
38
+ #message_headers p.alternate {
39
+ position: absolute;
40
+ top: 0;
41
+ right: 15px;
42
+ }
43
+
44
+ #message_headers p.alternate a {
45
+ color: #09c;
46
+ }
47
+
48
+ pre#message_body {
49
+ padding: 10px;
50
+ word-wrap: break-word;
51
+ }
52
+
53
+ body {
54
+ margin-top: 96px !important;
55
+ }
56
+ </style>
57
+
58
+ <div id="message_headers">
59
+ <dl>
60
+ <dt>From:</dt>
61
+ <dd><%= from %></dd>
62
+
63
+ <dt>Subject:</dt>
64
+ <dd><strong><%= mail.subject %></strong></dd>
65
+
66
+ <dt>Date:</dt>
67
+ <dd><%= Time.now.strftime("%b %e, %Y %I:%M:%S %p %Z") %></dd>
68
+
69
+ <dt>To:</dt>
70
+ <dd><%= mail.to.join ", " %></dd>
71
+ </dl>
72
+
73
+ <% if mail.multipart? %>
74
+ <p class="alternate">
75
+ <% if type == "plain" %>
76
+ <a href="rich.html">View HTML version</a>
77
+ <% else %>
78
+ <a href="plain.html">View plain text version</a>
79
+ <% end %>
80
+ </p>
81
+ <% end %>
82
+ </div>
83
+
84
+ <% if type == "plain" %>
85
+ <pre id="message_body"><%= CGI.escapeHTML(body) %></pre>
86
+ <% else %>
87
+ <%= body %>
88
+ <% end %>
@@ -0,0 +1,47 @@
1
+ module EmailSpy
2
+ class Message
3
+ attr_reader :email
4
+
5
+ def initialize(location, email, part = nil)
6
+ @location = location
7
+ @email = email
8
+ @part = part
9
+ end
10
+
11
+ def render
12
+ FileUtils.mkdir_p @location
13
+
14
+ File.open filepath, 'w' do |file|
15
+ file.write ERB.new(template).result binding
16
+ end
17
+ end
18
+
19
+ def template
20
+ File.read File.expand_path File.join("..", "message.html.erb"), __FILE__
21
+ end
22
+
23
+ def filepath
24
+ File.join @location, "#{type}.html"
25
+ end
26
+
27
+ def content_type
28
+ @part && @part.content_type || @email.content_type
29
+ end
30
+
31
+ def body
32
+ @body ||= (@part && @part.body || @email.body).to_s
33
+ end
34
+
35
+ def from
36
+ @from ||= @email.from.kind_of?(Array) && @email.from.join(", ") || @email.from
37
+ end
38
+
39
+ def type
40
+ content_type =~ /html/ ? "rich" : "plain"
41
+ end
42
+
43
+ def encoding
44
+ body.respond_to?(:encoding) ? body.encoding : "utf-8"
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,7 @@
1
+ module EmailSpy
2
+ class Railtie < Rails::Railtie
3
+ initializer "emailspy.add_delivery_method" do
4
+ ActionMailer::Base.add_delivery_method :email_spy, EmailSpy::DeliveryMethod, location: Rails.root.join("tmp", "email_spy")
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module EmailSpy
2
+ VERSION = "1.0.0"
3
+ end
data/lib/email_spy.rb ADDED
@@ -0,0 +1,8 @@
1
+ require "fileutils"
2
+ require "digest/sha1"
3
+ require "cgi"
4
+ require "launchy"
5
+
6
+ require_relative "email_spy/message"
7
+ require_relative "email_spy/delivery_method"
8
+ require_relative "email_spy/railtie" if defined? Rails
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: email_spy
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Kurtis Rainbolt-Greene
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: launchy
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: mail
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: Opens up your Rails emails
63
+ email:
64
+ - kurtisrainboltgreene@gmail.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - Gemfile
71
+ - LICENSE
72
+ - README.md
73
+ - Rakefile
74
+ - email_spy.gemspec
75
+ - lib/email_spy.rb
76
+ - lib/email_spy/delivery_method.rb
77
+ - lib/email_spy/message.html.erb
78
+ - lib/email_spy/message.rb
79
+ - lib/email_spy/railtie.rb
80
+ - lib/email_spy/version.rb
81
+ homepage: http://github.com/krainboltgreene/email_spy
82
+ licenses: []
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ! '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubyforge_project:
101
+ rubygems_version: 1.8.24
102
+ signing_key:
103
+ specification_version: 3
104
+ summary: Opens up your Rails emails
105
+ test_files: []