letter-opener-1.4.1/ 0000755 0001750 0001750 00000000000 12607234452 014435 5 ustar abhijith abhijith letter-opener-1.4.1/metadata.yml 0000644 0001750 0001750 00000004640 12607234452 016744 0 ustar abhijith abhijith --- !ruby/object:Gem::Specification name: letter_opener version: !ruby/object:Gem::Version version: 1.4.1 platform: ruby authors: - Ryan Bates autorequire: bindir: bin cert_chain: [] date: 2015-05-24 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency name: launchy requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '2.2' type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '2.2' - !ruby/object:Gem::Dependency name: rspec requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: 2.14.0 type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: 2.14.0 - !ruby/object:Gem::Dependency name: mail requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: 2.6.0 type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: 2.6.0 description: When mail is sent from your application, Letter Opener will open a preview in the browser instead of sending. email: ryan@railscasts.com executables: [] extensions: [] extra_rdoc_files: [] files: - CHANGELOG.md - Gemfile - LICENSE - README.rdoc - Rakefile - letter_opener.gemspec - lib/letter_opener.rb - lib/letter_opener/delivery_method.rb - lib/letter_opener/message.html.erb - lib/letter_opener/message.rb - lib/letter_opener/railtie.rb - spec/letter_opener/delivery_method_spec.rb - spec/letter_opener/message_spec.rb - spec/spec_helper.rb homepage: http://github.com/ryanb/letter_opener licenses: [] metadata: {} post_install_message: rdoc_options: [] require_paths: - lib required_ruby_version: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' required_rubygems_version: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: 1.3.4 requirements: [] rubyforge_project: letter_opener rubygems_version: 2.4.6 signing_key: specification_version: 4 summary: Preview mail in browser instead of sending. test_files: [] letter-opener-1.4.1/Gemfile 0000644 0001750 0001750 00000000061 12607234452 015725 0 ustar abhijith abhijith source "http://rubygems.org" gemspec gem "rake" letter-opener-1.4.1/Rakefile 0000644 0001750 0001750 00000000264 12607234452 016104 0 ustar abhijith abhijith require 'bundler' Bundler::GemHelper.install_tasks require 'rspec/core/rake_task' desc "Run RSpec" RSpec::Core::RakeTask.new do |t| t.verbose = false end task :default => :spec letter-opener-1.4.1/lib/ 0000755 0001750 0001750 00000000000 12607234452 015203 5 ustar abhijith abhijith letter-opener-1.4.1/lib/letter_opener/ 0000755 0001750 0001750 00000000000 12607234452 020052 5 ustar abhijith abhijith letter-opener-1.4.1/lib/letter_opener/delivery_method.rb 0000644 0001750 0001750 00000001507 12607234452 023565 0 ustar abhijith abhijith begin require 'mail/check_delivery_params' rescue LoadError => e end module LetterOpener class DeliveryMethod include Mail::CheckDeliveryParams if defined?(Mail::CheckDeliveryParams) class InvalidOption < StandardError; end attr_accessor :settings def initialize(options = {}) raise InvalidOption, "A location option is required when using the Letter Opener delivery method" if options[:location].nil? self.settings = options end def deliver!(mail) check_delivery_params(mail) if respond_to?(:check_delivery_params) location = File.join(settings[:location], "#{Time.now.to_i}_#{Digest::SHA1.hexdigest(mail.encoded)[0..6]}") messages = Message.rendered_messages(location, mail) Launchy.open("file:///#{URI.parse(URI.escape(messages.first.filepath))}") end end end letter-opener-1.4.1/lib/letter_opener/message.rb 0000644 0001750 0001750 00000005166 12607234452 022033 0 ustar abhijith abhijith require "erb" module LetterOpener class Message attr_reader :mail def self.rendered_messages(location, mail) messages = [] messages << new(location, mail, mail.html_part) if mail.html_part messages << new(location, mail, mail.text_part) if mail.text_part messages << new(location, mail) if messages.empty? messages.each(&:render) messages.sort end def initialize(location, mail, part = nil) @location = location @mail = mail @part = part @attachments = [] end def render FileUtils.mkdir_p(@location) if mail.attachments.any? attachments_dir = File.join(@location, 'attachments') FileUtils.mkdir_p(attachments_dir) mail.attachments.each do |attachment| filename = attachment.filename.gsub(/[^\w.]/, '_') path = File.join(attachments_dir, filename) unless File.exists?(path) # true if other parts have already been rendered File.open(path, 'wb') { |f| f.write(attachment.body.raw_source) } end @attachments << [attachment.filename, "attachments/#{URI.escape(filename)}"] end end File.open(filepath, 'w') do |f| f.write ERB.new(template).result(binding) end end def template File.read(File.expand_path("../message.html.erb", __FILE__)) end def filepath File.join(@location, "#{type}.html") end def content_type @part && @part.content_type || @mail.content_type end def body @body ||= begin body = (@part || @mail).decoded mail.attachments.each do |attachment| body.gsub!(attachment.url, "attachments/#{attachment.filename}") end body end end def from @from ||= Array(@mail['from']).join(", ") end def sender @sender ||= Array(@mail['sender']).join(", ") end def to @to ||= Array(@mail['to']).join(", ") end def cc @cc ||= Array(@mail['cc']).join(", ") end def bcc @bcc ||= Array(@mail['bcc']).join(", ") end def reply_to @reply_to ||= Array(@mail['reply-to']).join(", ") end def type content_type =~ /html/ ? "rich" : "plain" end def encoding body.respond_to?(:encoding) ? body.encoding : "utf-8" end def auto_link(text) text.gsub(URI.regexp(%W[https http])) do |link| "#{ link }" end end def h(content) CGI.escapeHTML(content) end def <=>(other) order = %w[rich plain] order.index(type) <=> order.index(other.type) end end end letter-opener-1.4.1/lib/letter_opener/message.html.erb 0000644 0001750 0001750 00000006111 12607234452 023132 0 ustar abhijith abhijith
<% if mail.subject %><% if type == "plain" && mail.html_part %> View HTML version <% elsif type == "rich" && mail.text_part %> View plain text version <% end %>
<% end %><%= auto_link(h(body)) %><% else %> <% end %>
}[http://travis-ci.org/ryanb/letter_opener]
Preview email in the default browser instead of sending it. This means you do not need to set up email delivery in your development environment, and you no longer need to worry about accidentally sending a test email to someone else's address.
== Rails Setup
First add the gem to your development environment and run the +bundle+ command to install it.
gem "letter_opener", :group => :development
Then set the delivery method in config/environments/development.rb
config.action_mailer.delivery_method = :letter_opener
Now any email will pop up in your browser instead of being sent. The messages are stored in tmp/letter_opener.
==== For Rails 2.3.x support
There is a fork that add support for Rails 2.3.x, in order to use that or just check it out you should go to https://github.com/cavi21/letter_opener
== Non Rails Setup
If you aren't using Rails, this can be easily set up with the Mail gem. Just set the delivery method when configuring Mail and specify a location.
require "letter_opener"
Mail.defaults do
delivery_method LetterOpener::DeliveryMethod, :location => File.expand_path('../tmp/letter_opener', __FILE__)
end
The method is similar if you're using the Pony gem:
require "letter_opener"
Pony.options = {
:via => LetterOpener::DeliveryMethod,
:via_options => {:location => File.expand_path('../tmp/letter_opener', __FILE__)}
}
Alternatively, if you are using ActionMailer directly (without Rails) you will need to add the delivery method.
require "letter_opener"
ActionMailer::Base.add_delivery_method :letter_opener, LetterOpener::DeliveryMethod, :location => File.expand_path('../tmp/letter_opener', __FILE__)
ActionMailer::Base.delivery_method = :letter_opener
== Remote Alternatives
Letter Opener uses {Launchy}[https://github.com/copiousfreetime/launchy] to open sent mail in the browser. This assumes the Ruby process is running on the local development machine. If you are using a separate staging server or VM this will not work. In that case consider using {Mailtrap}[http://mailtrap.io/] or {MailCatcher}[http://mailcatcher.me/].
In order to keep this project simple, I don't have plans to turn it into a Rails engine with an interface for browsing the sent mail but there is a {gem you can use for that}[https://github.com/fgrehm/letter_opener_web].
== Development & Feedback
Questions or problems? Please use the {issue tracker}[https://github.com/ryanb/letter_opener/issues]. If you would like to contribute to this project, fork this repository and run +bundle+ and +rake+ to run the tests. Pull requests appreciated.
Special thanks to the {mail_view}[https://github.com/37signals/mail_view/] gem for inspiring this project and for their mail template. Also thanks to {Vasiliy Ermolovich}[https://github.com/nashby] for helping manage this project.
letter-opener-1.4.1/LICENSE 0000644 0001750 0001750 00000002036 12607234452 015443 0 ustar abhijith abhijith Copyright (c) 2012 Ryan Bates
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
letter-opener-1.4.1/CHANGELOG.md 0000644 0001750 0001750 00000006112 12607234452 016246 0 ustar abhijith abhijith ## 1.4.1 ##
* Stop base tag appearing in plain-text previews. (thanks [Coby Chapple](https://github.com/cobyism))
## 1.4.0 ##
* Add base tag to the iframe so links work with X-Frame-Options set to SAMEORIGIN. (thanks [Jason Tokoph](https://github.com/jtokoph))
* Check delivery params before rendering an email to match SMTP behaviour.
## 1.3.0 ##
* Fix message body encoding is observed correctly in QP CTE. (thanks [Mark Dodwell](https://github.com/mkdynamic))
* Remove fixed width on the mail content. (thanks [weexpectedTHIS](https://github.com/weexpectedTHIS))
* Render email content in the iframe. Fixes [#98](https://github.com/ryanb/letter_opener/issues/98). (thanks [Jacob Maine](https://github.com/mainej))
## 1.2.0 ##
* Fix auto_link() which in some cases would return an empty tag for plain text messages. (thanks [Kevin McPhillips](https://github.com/kmcphillips))
* Update styles. (thanks [Adam Doppelt](https://github.com/gurgeous))
## 1.1.2 ##
* Show formatted display names in html template (thanks [ClaireMcGinty](https://github.com/ClaireMcGinty))
* Use `file:///` uri scheme to fix Launchy on Windows.
## 1.1.1 ##
* Handle cc and bcc as array of emails. (thanks [jordandcarter](https://github.com/jordandcarter))
* Use `file://` uri scheme since Launcy can't open escaped URL without it. (thanks [Adrian2112](https://github.com/Adrian2112))
* Update Launchy dependency to `~> 2.2` (thanks [JeanMertz](https://github.com/JeanMertz))
* Change all nonword chars in filename of attachment to underscore so
it can be saved on all platforms. (thanks [phallstrom](https://github.com/phallstrom))
## 1.1.0 ##
* Update Launchy dependency to `~> 2.2.0` (thanks [webdevotion](https://github.com/webdevotion))
* Handle `sender` field (thanks [sjtipton](https://github.com/sjtipton))
* Show subject only if it's present (thanks [jadehyper](https://github.com/jadehyper))
* Show subject as title of web page (thanks [statique](https://github.com/statique))
## 1.0.0 ##
* Attachment Support (thanks [David Cornu](https://github.com/davidcornu))
* Escape HTML in subject and other fields
* Raise an exception if the :location option is not present instead of using a default
* Open rich version by default (thanks [Damir](https://github.com/sidonath))
* Override margin on dt and dd elements in CSS (thanks [Edgars Beigarts](https://github.com/ebeigarts))
* Autolink URLs in plain version (thanks [Matt Burke](https://github.com/spraints))
## 0.1.0 ##
* From and To show name and Email when specified
* Fix bug when letter_opener couldn't open email in Windows
* Handle spaces in the application path (thanks [Mike Boone](https://github.com/boone))
* As letter_opener doesn't work with Launchy < 2.0.4 let's depend on >= 2.0.4 (thanks [Samnang Chhun](https://github.com/samnang))
* Handle `reply_to` field (thanks [Wes Gibbs](https://github.com/wgibbs))
* Set the charset in email preview (thanks [Bruno Michel](https://github.com/nono))
## 0.0.2 ##
* Fixing launchy requirement (thanks [Bruno Michel](https://github.com/nono))
## 0.0.1 ##
* Initial relase
letter-opener-1.4.1/letter_opener.gemspec 0000644 0001750 0001750 00000001333 12607234452 020651 0 ustar abhijith abhijith Gem::Specification.new do |s|
s.name = "letter_opener"
s.version = "1.4.1"
s.author = "Ryan Bates"
s.email = "ryan@railscasts.com"
s.homepage = "http://github.com/ryanb/letter_opener"
s.summary = "Preview mail in browser instead of sending."
s.description = "When mail is sent from your application, Letter Opener will open a preview in the browser instead of sending."
s.files = Dir["{lib,spec}/**/*", "[A-Z]*"] - ["Gemfile.lock"]
s.require_path = "lib"
s.add_dependency 'launchy', '~> 2.2'
s.add_development_dependency 'rspec', '~> 2.14.0'
s.add_development_dependency 'mail', '~> 2.6.0'
s.rubyforge_project = s.name
s.required_rubygems_version = ">= 1.3.4"
end
letter-opener-1.4.1/spec/ 0000755 0001750 0001750 00000000000 12607234452 015367 5 ustar abhijith abhijith letter-opener-1.4.1/spec/letter_opener/ 0000755 0001750 0001750 00000000000 12607234452 020236 5 ustar abhijith abhijith letter-opener-1.4.1/spec/letter_opener/delivery_method_spec.rb 0000644 0001750 0001750 00000020731 12607234452 024763 0 ustar abhijith abhijith require "spec_helper"
describe LetterOpener::DeliveryMethod do
let(:location) { File.expand_path('../../../tmp/letter_opener', __FILE__) }
let(:plain_file) { Dir["#{location}/*/plain.html"].first }
let(:plain) { CGI.unescape_html(File.read(plain_file)) }
before do
Launchy.stub(:open)
FileUtils.rm_rf(location)
context = self
Mail.defaults do
delivery_method LetterOpener::DeliveryMethod, :location => context.location
end
end
it 'raises an exception if no location passed' do
expect { LetterOpener::DeliveryMethod.new }.to raise_exception(LetterOpener::DeliveryMethod::InvalidOption)
expect { LetterOpener::DeliveryMethod.new(location: "foo") }.to_not raise_exception
end
context 'integration' do
before do
Launchy.unstub(:open)
ENV['LAUNCHY_DRY_RUN'] = 'true'
end
context 'normal location path' do
it 'opens email' do
expect($stdout).to receive(:puts)
expect {
Mail.deliver do
to 'Bar bar@example.com'
from 'Foo foo@example.com'
body 'World! http://example.com'
end
}.not_to raise_error
end
end
context 'with spaces in location path' do
let(:location) { File.expand_path('../../../tmp/letter_opener with space', __FILE__) }
it 'opens email' do
expect($stdout).to receive(:puts)
expect {
Mail.deliver do
to 'Bar bar@example.com'
from 'Foo foo@example.com'
body 'World! http://example.com'
end
}.not_to raise_error
end
end
end
context 'content' do
context 'plain' do
before do
expect(Launchy).to receive(:open)
Mail.deliver do
from 'Foo