devmail 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
@@ -0,0 +1,20 @@
1
+ Copyright 2011 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,3 @@
1
+ = Devmail
2
+
3
+ This project rocks and uses MIT-LICENSE.
@@ -0,0 +1,25 @@
1
+ # encoding: UTF-8
2
+ require 'rubygems'
3
+ begin
4
+ require 'bundler/setup'
5
+ rescue LoadError
6
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
7
+ end
8
+
9
+ require 'rake'
10
+ require 'rake/rdoctask'
11
+
12
+ require 'rspec/core'
13
+ require 'rspec/core/rake_task'
14
+
15
+ RSpec::Core::RakeTask.new(:spec)
16
+
17
+ task :default => :spec
18
+
19
+ Rake::RDocTask.new(:rdoc) do |rdoc|
20
+ rdoc.rdoc_dir = 'rdoc'
21
+ rdoc.title = 'Devmail'
22
+ rdoc.options << '--line-numbers' << '--inline-source'
23
+ rdoc.rdoc_files.include('README.rdoc')
24
+ rdoc.rdoc_files.include('lib/**/*.rb')
25
+ end
@@ -0,0 +1,36 @@
1
+ module Devmail
2
+ class DevelopmentMailsController < ApplicationController
3
+ respond_to :html, :xml, :json
4
+
5
+ layout "devmail/devmail"
6
+
7
+ def index
8
+ @mails = DevMail.all.desc(:created_at)
9
+
10
+ respond_with @mails
11
+ end
12
+
13
+ def show
14
+ @mail = DevMail.find(params[:id])
15
+
16
+ respond_with @mail
17
+ end
18
+
19
+ def destroy
20
+ @mail = DevMail.find(params[:id])
21
+ @mail.destroy
22
+
23
+ redirect_to development_mails_url
24
+ end
25
+
26
+ def clear
27
+ DevMail.destroy_all
28
+ redirect_to development_mails_url
29
+ end
30
+
31
+ def html_part
32
+ @mail = DevMail.find(params[:id])
33
+ render :text => @mail.html_part
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,29 @@
1
+ module Devmail
2
+ class DevMail
3
+ include Mongoid::Document
4
+ include Mongoid::Timestamps
5
+
6
+ field :from, :type => Array
7
+ field :to, :type => Array
8
+ field :cc, :type => Array
9
+ field :bcc, :type => Array
10
+ field :header
11
+ field :sender
12
+ field :subject
13
+ field :reply_to, :type => Array
14
+ field :text_part
15
+ field :html_part
16
+ field :multipart, :type => Boolean
17
+ field :content_transfer_encoding
18
+
19
+ field :serialized_mail
20
+
21
+ def mail
22
+ Mail::Message.from_yaml(self.serialized_mail)
23
+ end
24
+
25
+ def mail=(m)
26
+ self.serialized_mail = m.to_yaml
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,25 @@
1
+ <h1>Development e-mails captured:</h1>
2
+
3
+ <table>
4
+ <tr>
5
+ <th>Sent at</th>
6
+ <th>From</th>
7
+ <th>To</th>
8
+ <th>Subject</th>
9
+ <th></th>
10
+ </tr>
11
+ <% for mail in @mails do -%>
12
+ <tr>
13
+ <td><%= mail.created_at.in_time_zone %></td>
14
+ <td><%= mail.from.join(", ") %></td>
15
+ <td><%= mail.to.join(", ") %></td>
16
+ <td><%= mail.subject %></td>
17
+ <td><%= link_to "Details", development_mail_path(mail) %>,
18
+ <%= link_to "Delete", development_mail_path(mail), :confirm => 'Are you sure?', :method => :delete %>
19
+ </td>
20
+ </tr>
21
+ <% end -%>
22
+ </table>
23
+
24
+ <%= link_to "Clear", clear_development_mails_path,
25
+ :confirm => "Are you sure? This will remove all stored emails." %>
@@ -0,0 +1,21 @@
1
+ <h1>Development email</h1>
2
+
3
+ <p><b>Sent at:</b> <%= @mail.created_at.in_time_zone %></p>
4
+ <p><b>From:</b> <%= @mail.from.join(", ") %></p>
5
+ <p><b>To:</b> <%= @mail.to.join(", ") %></p>
6
+ <p><b>Subject:</b> <%= @mail.subject %></p>
7
+ <% if @mail.multipart? -%>
8
+ <p><b>Text part:</b><br />
9
+ <%= @mail.text_part.gsub(/\n/, "<br />").html_safe %>
10
+ </p>
11
+ <p>
12
+ <b><%= link_to "HTML part", html_part_development_mail(@mail) %></b>
13
+ </p>
14
+ <% else -%>
15
+ <p><b>Body:</b><br />
16
+ <%= @mail.text_part.gsub(/\n/, "<br />").html_safe %>
17
+ </p>
18
+ <% end -%>
19
+
20
+ <%= link_to "Back to list", development_mails_path %>
21
+ <%= link_to 'Delete', development_mail_path(@mail), :confirm => 'Are you sure?', :method => :delete %>
@@ -0,0 +1,25 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Development Emails</title>
5
+ <%= stylesheet_link_tag :all %>
6
+ <%= javascript_include_tag :defaults %>
7
+ <%= csrf_meta_tag %>
8
+ <style type="text/css">
9
+ table td, table th {
10
+ border: 1px solid #ccc;
11
+ padding: 5px 10px;
12
+ }
13
+ table {
14
+ border-collapse: collapse;
15
+ border-spacing: 0;
16
+ }
17
+ </style>
18
+ </head>
19
+ <body>
20
+
21
+ <%= yield %>
22
+
23
+ </body>
24
+ </html>
25
+
@@ -0,0 +1,2 @@
1
+ ActionMailer::Base.register_interceptor(Devmail::DevelopmentMailInterceptor) if Rails.env.development?
2
+
@@ -0,0 +1,6 @@
1
+ Rails.application.routes.draw do
2
+ resources :development_mails, :controller => 'devmail/development_mails', :only => [:index, :show, :destroy] do
3
+ get 'clear', :on => :collection
4
+ get 'html_part', :on => :member
5
+ end
6
+ end
@@ -0,0 +1,3 @@
1
+ module Devmail
2
+ require 'devmail/engine' if defined?(Rails)
3
+ end
@@ -0,0 +1,30 @@
1
+ module Devmail
2
+ class DevelopmentMailInterceptor
3
+ def self.delivering_email(message)
4
+ dm = DevMail.new
5
+
6
+ dm.from = message.from
7
+ dm.to = message.to
8
+ dm.cc = message.cc
9
+ dm.bcc = message.bcc
10
+ dm.sender = message.sender
11
+ dm.subject = message.subject
12
+ dm.reply_to = message.reply_to
13
+
14
+ dm.multipart = message.multipart?
15
+
16
+ if message.multipart?
17
+ dm.text_part = message.text_part.decoded
18
+ dm.html_part = message.html_part.decoded
19
+ else
20
+ dm.text_part = message.decoded
21
+ end
22
+
23
+ dm.mail = message
24
+
25
+ dm.save
26
+
27
+ message
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,11 @@
1
+ require "devmail"
2
+ require "rails"
3
+ require "mongoid"
4
+
5
+ module Devmail
6
+ require 'devmail/development_mail_interceptor.rb'
7
+
8
+ class Engine < Rails::Engine
9
+
10
+ end
11
+ end
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: devmail
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - "Grzesiek Ko\xC5\x82odziejczyk"
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-04-24 00:00:00 +02:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: rails
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: 3.0.0
25
+ type: :runtime
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: mongoid
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: "2.0"
36
+ type: :runtime
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: bson_ext
40
+ prerelease: false
41
+ requirement: &id003 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: "1.3"
47
+ type: :runtime
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
50
+ name: rspec-rails
51
+ prerelease: false
52
+ requirement: &id004 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: 2.5.0
58
+ type: :development
59
+ version_requirements: *id004
60
+ - !ruby/object:Gem::Dependency
61
+ name: capybara
62
+ prerelease: false
63
+ requirement: &id005 !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 0.4.0
69
+ type: :development
70
+ version_requirements: *id005
71
+ description: Stores all emails sent in development in a mongodb database and presents a clean interface for viewing them.
72
+ email:
73
+ - gkolodziejczyk@gmail.com
74
+ executables: []
75
+
76
+ extensions: []
77
+
78
+ extra_rdoc_files: []
79
+
80
+ files:
81
+ - app/controllers/devmail/development_mails_controller.rb
82
+ - app/models/devmail/dev_mail.rb
83
+ - app/views/devmail/development_mails/index.html.erb
84
+ - app/views/devmail/development_mails/show.html.erb
85
+ - app/views/layouts/devmail/devmail.html.erb
86
+ - lib/devmail/development_mail_interceptor.rb
87
+ - lib/devmail/engine.rb
88
+ - lib/devmail.rb
89
+ - config/initializers/development_mail_interceptor.rb
90
+ - config/routes.rb
91
+ - MIT-LICENSE
92
+ - Rakefile
93
+ - Gemfile
94
+ - README.rdoc
95
+ has_rdoc: true
96
+ homepage: https://github.com/grk/devmail/
97
+ licenses: []
98
+
99
+ post_install_message:
100
+ rdoc_options: []
101
+
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: "0"
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ none: false
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: "0"
116
+ requirements: []
117
+
118
+ rubyforge_project:
119
+ rubygems_version: 1.6.2
120
+ signing_key:
121
+ specification_version: 3
122
+ summary: Interceptor for emails sent in development for Rails 3
123
+ test_files: []
124
+