virtual_mails 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d5d26d2fd3ed677c7b53e7d907649c40bc866a00
4
+ data.tar.gz: b127a4f9851b1ebecbc6131a1faf2e3616cb6cd7
5
+ SHA512:
6
+ metadata.gz: 067343ad4497d109a3c2eba53c80b329e099c1e458b76d6a27d09d3ea908cc3f3a67b6d5a8a8d0c5ade03403893f70eaf33e56dca0087bbcf9710a4aac058e52
7
+ data.tar.gz: e1e47339f0e8c587b4495d11d0a179a69ba9623bc13e69d66988708ee47297f1f3df561f003ca889fa9f2fb0da0cbdd42b86e78feaa909b748968cc4a68e4be9
data/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # v0.1.1 / 2015-09-16
2
+
3
+ Fixed namespace bug.
4
+
5
+ # v0.1.0 / 2015-09-15
6
+
7
+ Create project
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Chen Yi-Cyuan
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # Virtual Mails
2
+
3
+ [![Build Status](https://api.travis-ci.org/emn178/virtual_mails.png)](https://travis-ci.org/emn178/virtual_mails)
4
+ [![Coverage Status](https://coveralls.io/repos/emn178/virtual_mails/badge.svg?branch=master)](https://coveralls.io/r/emn178/virtual_mails?branch=master)
5
+
6
+ An rails plugin that provides a virtual mail box and action mailer delivery method. You can send mail to this virtual mail box instead of real email service in development environment, and you can preview the emails in this virtual mail box in web page.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'virtual_mails', group: :development
14
+ ```
15
+ Make sure you have:
16
+ ```ruby
17
+ gem 'jquery-rails'
18
+ ```
19
+
20
+ And then execute:
21
+
22
+ bundle
23
+
24
+ ### Route
25
+ Add virtual mail box route in your `config/route.rb`
26
+ ```Ruby
27
+ mount VirtualMails::Engine => "/virtual_mails" if Rails.env.development?
28
+ ```
29
+
30
+ ### Delivery Method
31
+ Set up delivery method of action mailer in your `config/environments/developmnet.rb`
32
+ ```Ruby
33
+ config.action_mailer.delivery_method = :virtual
34
+ ```
35
+
36
+ ## Usage
37
+ Now, you can go to http://localhost:3000/virtual_mails and check the emails!
38
+
39
+ ## License
40
+
41
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
42
+
43
+ ## Contact
44
+ The project's website is located at https://github.com/emn178/virtual_mails
45
+ Author: emn178@gmail.com
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,19 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require_tree .
16
+
17
+ function resizeIframe(iframe) {
18
+ iframe.style.height = iframe.contentWindow.document.body.scrollHeight + 'px';
19
+ }
@@ -0,0 +1,117 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
16
+
17
+ /* http://meyerweb.com/eric/tools/css/reset/
18
+ v2.0 | 20110126
19
+ License: none (public domain)
20
+ */
21
+
22
+ html, body, div, span, applet, object, iframe,
23
+ h1, h2, h3, h4, h5, h6, p, blockquote, pre,
24
+ a, abbr, acronym, address, big, cite, code,
25
+ del, dfn, em, img, ins, kbd, q, s, samp,
26
+ small, strike, strong, sub, sup, tt, var,
27
+ b, u, i, center,
28
+ dl, dt, dd, ol, ul, li,
29
+ fieldset, form, label, legend,
30
+ table, caption, tbody, tfoot, thead, tr, th, td,
31
+ article, aside, canvas, details, embed,
32
+ figure, figcaption, footer, header, hgroup,
33
+ menu, nav, output, ruby, section, summary,
34
+ time, mark, audio, video {
35
+ margin: 0;
36
+ padding: 0;
37
+ border: 0;
38
+ font-size: 100%;
39
+ font: inherit;
40
+ vertical-align: baseline;
41
+ }
42
+ /* HTML5 display-role reset for older browsers */
43
+ article, aside, details, figcaption, figure,
44
+ footer, header, hgroup, menu, nav, section {
45
+ display: block;
46
+ }
47
+ body {
48
+ line-height: 1;
49
+ }
50
+ ol, ul {
51
+ list-style: none;
52
+ }
53
+ blockquote, q {
54
+ quotes: none;
55
+ }
56
+ blockquote:before, blockquote:after,
57
+ q:before, q:after {
58
+ content: '';
59
+ content: none;
60
+ }
61
+ table {
62
+ border-collapse: collapse;
63
+ border-spacing: 0;
64
+ }
65
+
66
+ body {
67
+ font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
68
+ font-size: 14px;
69
+ line-height: 1.42857143;
70
+ color: #333;
71
+ margin: 0 20px;
72
+ }
73
+
74
+ h2 {
75
+ font-size: 30px;
76
+ margin-top: 20px;
77
+ margin-bottom: 10px;
78
+ font-family: inherit;
79
+ font-weight: 500;
80
+ line-height: 1.1;
81
+ }
82
+
83
+ table {
84
+ border: 1px solid #ddd;
85
+ width: 100%;
86
+ max-width: 100%;
87
+ border-spacing: 0;
88
+ border-collapse: collapse;
89
+ }
90
+
91
+ tr:nth-of-type(odd) {
92
+ background-color: #f9f9f9;
93
+ }
94
+
95
+ tr:first-child>th {
96
+ border-top: 0;
97
+ }
98
+
99
+ th, td {
100
+ border-bottom-width: 2px;
101
+ border: 1px solid #ddd;
102
+ vertical-align: bottom;
103
+ border-bottom: 2px solid #ddd;
104
+ padding: 8px;
105
+ line-height: 1.42857143;
106
+ vertical-align: top;
107
+ border-top: 1px solid #ddd;
108
+ }
109
+
110
+ a {
111
+ text-decoration: none;
112
+ color: #007CFF;
113
+ }
114
+
115
+ iframe {
116
+ width: 100%;
117
+ }
@@ -0,0 +1,2 @@
1
+ class VirtualMails::ApplicationController < ActionController::Base
2
+ end
@@ -0,0 +1,27 @@
1
+ module VirtualMails
2
+ class EmailsController < VirtualMails::ApplicationController
3
+ before_action :find_mail, :only => [:show, :raw]
4
+
5
+ def index
6
+ @emails = Email.all
7
+ end
8
+
9
+ def show
10
+ end
11
+
12
+ def raw
13
+ render :plain => @email.raw
14
+ end
15
+
16
+ def clear
17
+ Email.clear
18
+ redirect_to emails_path
19
+ end
20
+
21
+ private
22
+
23
+ def find_mail
24
+ @email = Email.find(params[:id])
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,4 @@
1
+ module VirtualMails
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,80 @@
1
+ module VirtualMails
2
+ class Email
3
+ include ActionView::Helpers::TagHelper
4
+
5
+ attr_accessor :message
6
+ delegate :subject, :date, to: :message
7
+
8
+ def initialize(message)
9
+ @message = message
10
+ end
11
+
12
+ def id
13
+ @message.message_id.split('@')[0]
14
+ end
15
+
16
+ def from
17
+ @message.header.fields.find{|f| f.name == "From"}.value
18
+ end
19
+
20
+ def to
21
+ addresses = @message.header.fields.find{|f| f.name == "To"}.address_list.addresses
22
+ address = addresses[0].to_s
23
+ count = addresses.length
24
+ count > 1 ? address + ", ...#{count - 1} more" : address
25
+ end
26
+
27
+ def list_to
28
+ @message.header.fields.find{|f| f.name == "To"}.value
29
+ end
30
+
31
+ def body
32
+ html || plain
33
+ end
34
+
35
+ def body_tag
36
+ html_tag || plain_tag
37
+ end
38
+
39
+ def raw
40
+ @message.to_s
41
+ end
42
+
43
+ def self.all
44
+ emails = Rails.cache.fetch(CacheKey) do
45
+ emails = []
46
+ end
47
+ emails
48
+ end
49
+
50
+ def self.find(id)
51
+ mail = all.find { |mail| mail.id == id }
52
+ raise ActiveRecord::RecordNotFound if mail.nil?
53
+ mail
54
+ end
55
+
56
+ def self.clear
57
+ Rails.cache.delete(CacheKey)
58
+ end
59
+
60
+ private
61
+
62
+ def html
63
+ @message.html_part ? @message.html_part.body.decoded : nil
64
+ end
65
+
66
+ def html_tag
67
+ content = html
68
+ content_tag :iframe, '', :srcdoc => content, :onload => 'resizeIframe(this)' unless content.nil?
69
+ end
70
+
71
+ def plain
72
+ @message.multipart? ? (@message.text_part ? @message.text_part.body.decoded : nil) : @message.body.decoded
73
+ end
74
+
75
+ def plain_tag
76
+ content = plain
77
+ content_tag :pre, content unless content.nil?
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,17 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2
+ <html>
3
+ <head>
4
+ <title>
5
+ Virtual Mail Box
6
+ </title>
7
+ <%= stylesheet_link_tag "virtual_mails/application", media: "all", "data-turbolinks-track" => true %>
8
+ <%= javascript_include_tag "virtual_mails/application", "data-turbolinks-track" => true %>
9
+ <%= csrf_meta_tags %>
10
+ </head>
11
+ <body>
12
+ <h2>
13
+ <%= link_to 'Virtual Mail Box', emails_path %>
14
+ </h2>
15
+ <%= yield %>
16
+ </body>
17
+ </html>
@@ -0,0 +1,31 @@
1
+ <%= link_to 'Clear', clear_emails_path, :method => :delete, :data => {:confirm => "Are you sure?"} %>
2
+ <table>
3
+ <colgroup>
4
+ <col width="250px"></col>
5
+ <col width="300px"></col>
6
+ <col></col>
7
+ <col width="200px"></col>
8
+ </colgroup>
9
+ <tr>
10
+ <th>From</th>
11
+ <th>To</th>
12
+ <th>Subject</th>
13
+ <th>Date</th>
14
+ </tr>
15
+ <% @emails.each do |email| %>
16
+ <tr>
17
+ <td>
18
+ <%= email.from %>
19
+ </td>
20
+ <td>
21
+ <%= email.to %>
22
+ </td>
23
+ <td>
24
+ <%= link_to email.subject, email_path(:id => email.id) %>
25
+ </td>
26
+ <td>
27
+ <%= email.date %>
28
+ </td>
29
+ </tr>
30
+ <% end %>
31
+ </table>
@@ -0,0 +1,37 @@
1
+ <table>
2
+ <tr>
3
+ <th>Subject</th>
4
+ <td>
5
+ <%= @email.subject %>
6
+ <%= link_to '(Raw)', raw_email_path(:id => @email.id), :target => 'raw' %>
7
+ </td>
8
+ </tr>
9
+ <tr>
10
+ <th>From</th>
11
+ <td>
12
+ <%= @email.from %>
13
+ </td>
14
+ </tr>
15
+ <tr>
16
+ <th>Date</th>
17
+ <td>
18
+ <%= @email.from %>
19
+ </td>
20
+ </tr>
21
+ <tr>
22
+ <th>To</th>
23
+ <td>
24
+ <%= @email.list_to %>
25
+ </td>
26
+ </tr>
27
+ <tr>
28
+ <th colspan="2">
29
+ Body
30
+ </th>
31
+ </tr>
32
+ <tr>
33
+ <td colspan="2">
34
+ <%= @email.body_tag %>
35
+ </td>
36
+ </tr>
37
+ </table>
data/config/routes.rb ADDED
@@ -0,0 +1,10 @@
1
+ VirtualMails::Engine.routes.draw do
2
+ resources :emails, :path => '/', :only => [:index, :show] do
3
+ member do
4
+ get 'raw'
5
+ end
6
+ collection do
7
+ delete 'clear'
8
+ end
9
+ end
10
+ end
data/config/spring.rb ADDED
@@ -0,0 +1 @@
1
+ Spring.application_root = './spec/dummy'
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :virtual_mails do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,8 @@
1
+ require "virtual_mails/engine"
2
+ require "virtual_mails/mailer"
3
+
4
+ module VirtualMails
5
+ CacheKey = 'virtual_mails'
6
+
7
+ ActionMailer::Base.add_delivery_method :virtual, Mailer
8
+ end
@@ -0,0 +1,5 @@
1
+ module VirtualMails
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace VirtualMails
4
+ end
5
+ end
@@ -0,0 +1,15 @@
1
+ module VirtualMails
2
+ class Mailer
3
+ attr_accessor :settings
4
+
5
+ def initialize(settings)
6
+ self.settings = settings
7
+ end
8
+
9
+ def deliver!(mail)
10
+ mails = Email.all
11
+ mails << Email.new(mail)
12
+ Rails.cache.write(CacheKey, mails)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module VirtualMails
2
+ VERSION = "0.1.1"
3
+ end
metadata ADDED
@@ -0,0 +1,164 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: virtual_mails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Chen Yi-Cyuan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 4.2.3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 4.2.3
27
+ - !ruby/object:Gem::Dependency
28
+ name: jquery-rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: sqlite3
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.10'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.10'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec-rails
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec-its
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: An rails plugin that provides a virtual mail box and action mailer delivery
112
+ method.
113
+ email:
114
+ - emn178@gmail.com
115
+ executables: []
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - CHANGELOG.md
120
+ - LICENSE.txt
121
+ - README.md
122
+ - Rakefile
123
+ - app/assets/javascripts/virtual_mails/application.js
124
+ - app/assets/stylesheets/virtual_mails/application.css
125
+ - app/controllers/virtual_mails/application_controller.rb
126
+ - app/controllers/virtual_mails/emails_controller.rb
127
+ - app/helpers/virtual_mails/application_helper.rb
128
+ - app/models/virtual_mails/email.rb
129
+ - app/views/layouts/virtual_mails/application.erb
130
+ - app/views/virtual_mails/emails/index.html.erb
131
+ - app/views/virtual_mails/emails/show.html.erb
132
+ - config/routes.rb
133
+ - config/spring.rb
134
+ - lib/tasks/virtual_mails_tasks.rake
135
+ - lib/virtual_mails.rb
136
+ - lib/virtual_mails/engine.rb
137
+ - lib/virtual_mails/mailer.rb
138
+ - lib/virtual_mails/version.rb
139
+ homepage: https://github.com/emn178/virtual_mails
140
+ licenses:
141
+ - MIT
142
+ metadata: {}
143
+ post_install_message:
144
+ rdoc_options: []
145
+ require_paths:
146
+ - lib
147
+ required_ruby_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ required_rubygems_version: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ requirements: []
158
+ rubyforge_project:
159
+ rubygems_version: 2.4.5
160
+ signing_key:
161
+ specification_version: 4
162
+ summary: An rails plugin that provides a virtual mail box and action mailer delivery
163
+ method.
164
+ test_files: []