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 %>
<%= h mail.subject %>
<% end %>
<% if type == "plain" %>
<%= auto_link(h(body)) %>
<% else %>
<% end %>
letter-opener-1.4.1/lib/letter_opener/railtie.rb 0000644 0001750 0001750 00000000510 12607234452 022024 0 ustar abhijith abhijith module LetterOpener
class Railtie < Rails::Railtie
initializer "letter_opener.add_delivery_method" do
ActiveSupport.on_load :action_mailer do
ActionMailer::Base.add_delivery_method :letter_opener, LetterOpener::DeliveryMethod, :location => Rails.root.join("tmp", "letter_opener")
end
end
end
end
letter-opener-1.4.1/lib/letter_opener.rb 0000644 0001750 0001750 00000000323 12607234452 020375 0 ustar abhijith abhijith require "fileutils"
require "digest/sha1"
require "cgi"
require "uri"
require "launchy"
require "letter_opener/message"
require "letter_opener/delivery_method"
require "letter_opener/railtie" if defined? Rails
letter-opener-1.4.1/README.rdoc 0000644 0001750 0001750 00000005647 12607234452 016257 0 ustar abhijith abhijith = Letter Opener {
}[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 '
sender 'Baz '
reply_to 'No Reply '
to 'Bar '
cc 'Qux '
bcc 'Qux '
subject 'Hello'
body 'World! http://example.com'
end
end
it 'creates plain html document' do
expect(File.exist?(plain_file)).to be_true
end
it 'saves From field' do
expect(plain).to include("Foo ")
end
it 'saves Sender field' do
expect(plain).to include("Baz ")
end
it 'saves Reply-to field' do
expect(plain).to include("No Reply ")
end
it 'saves To field' do
expect(plain).to include("Bar ")
end
it 'saves Subject field' do
expect(plain).to include("Hello")
end
it 'saves Body with autolink' do
expect(plain).to include('World! http://example.com')
end
end
context 'multipart' do
let(:rich_file) { Dir["#{location}/*/rich.html"].first }
let(:rich) { CGI.unescape_html(File.read(rich_file)) }
before do
expect(Launchy).to receive(:open)
Mail.deliver do
from 'foo@example.com'
to 'bar@example.com'
subject 'Many parts with '
text_part do
body 'This is text'
end
html_part do
content_type 'text/html; charset=UTF-8'
body 'This is HTML
'
end
end
end
it 'creates plain html document' do
expect(File.exist?(plain_file)).to be_true
end
it 'creates rich html document' do
expect(File.exist?(rich_file)).to be_true
end
it 'shows link to rich html version' do
expect(plain).to include("View HTML version")
end
it 'saves text part' do
expect(plain).to include("This is text")
end
it 'saves html part' do
expect(rich).to include("This is HTML
")
end
it 'saves escaped Subject field' do
expect(plain).to include("Many parts with ")
end
it 'shows subject as title' do
expect(rich).to include("Many parts with ")
end
end
end
context 'document with spaces in name' do
let(:location) { File.expand_path('../../../tmp/letter_opener with space', __FILE__) }
before do
expect(Launchy).to receive(:open)
Mail.deliver do
from 'Foo '
to 'bar@example.com'
subject 'Hello'
body 'World!'
end
end
it 'creates plain html document' do
File.exist?(plain_file)
end
it 'saves From filed' do
expect(plain).to include("Foo ")
end
end
context 'using deliver! method' do
before do
expect(Launchy).to receive(:open)
Mail.new do
from 'foo@example.com'
to 'bar@example.com'
subject 'Hello'
body 'World!'
end.deliver!
end
it 'creates plain html document' do
expect(File.exist?(plain_file)).to be_true
end
it 'saves From field' do
expect(plain).to include("foo@example.com")
end
it 'saves To field' do
expect(plain).to include("bar@example.com")
end
it 'saves Subject field' do
expect(plain).to include("Hello")
end
it 'saves Body field' do
expect(plain).to include("World!")
end
end
context 'attachments in plain text mail' do
before do
Mail.deliver do
from 'foo@example.com'
to 'bar@example.com'
subject 'With attachments'
text_part do
body 'This is text'
end
attachments[File.basename(__FILE__)] = File.read(__FILE__)
end
end
it 'creates attachments dir with attachment' do
attachment = Dir["#{location}/*/attachments/#{File.basename(__FILE__)}"].first
expect(File.exists?(attachment)).to be_true
end
it 'saves attachment name' do
plain = File.read(Dir["#{location}/*/plain.html"].first)
expect(plain).to include(File.basename(__FILE__))
end
end
context 'attachments in rich mail' do
let(:url) { mail.attachments[0].url }
let!(:mail) do
Mail.deliver do
from 'foo@example.com'
to 'bar@example.com'
subject 'With attachments'
attachments[File.basename(__FILE__)] = File.read(__FILE__)
url = attachments[0].url
html_part do
content_type 'text/html; charset=UTF-8'
body "Here's an image:
"
end
end
end
it 'creates attachments dir with attachment' do
attachment = Dir["#{location}/*/attachments/#{File.basename(__FILE__)}"].first
expect(File.exists?(attachment)).to be_true
end
it 'replaces inline attachment urls' do
text = File.read(Dir["#{location}/*/rich.html"].first)
expect(mail.parts[0].body).to include(url)
expect(text).to_not include(url)
expect(text).to include("attachments/#{File.basename(__FILE__)}")
end
end
context 'attachments with non-word characters in the filename' do
before do
Mail.deliver do
from 'foo@example.com'
to 'bar@example.com'
subject 'With attachments'
text_part do
body 'This is text'
end
attachments['non word:chars/used,01.txt'] = File.read(__FILE__)
end
end
it 'creates attachments dir with attachment' do
attachment = Dir["#{location}/*/attachments/non_word_chars_used_01.txt"].first
expect(File.exists?(attachment)).to be_true
end
it 'saves attachment name' do
plain = File.read(Dir["#{location}/*/plain.html"].first)
expect(plain).to include('non_word_chars_used_01.txt')
end
end
context 'subjectless mail' do
before do
expect(Launchy).to receive(:open)
Mail.deliver do
from 'Foo foo@example.com'
reply_to 'No Reply no-reply@example.com'
to 'Bar bar@example.com'
body 'World! http://example.com'
end
end
it 'creates plain html document' do
expect(File.exist?(plain_file)).to be_true
end
end
context 'delivery params' do
it 'raises an exception if delivery params are not valid' do
expect(Launchy).not_to receive(:open)
expect {
Mail.deliver do
from 'Foo foo@example.com'
reply_to 'No Reply no-reply@example.com'
body 'World! http://example.com'
end
}.to raise_exception(ArgumentError)
end
end
end
letter-opener-1.4.1/spec/letter_opener/message_spec.rb 0000644 0001750 0001750 00000016567 12607234452 023240 0 ustar abhijith abhijith # encoding: utf-8
require 'spec_helper'
describe LetterOpener::Message do
let(:location) { File.expand_path('../../../tmp/letter_opener', __FILE__) }
def mail(options={}, &blk)
Mail.new(options, &blk)
end
describe '#reply_to' do
it 'handles one email as a string' do
mail = mail(:reply_to => 'test@example.com')
message = described_class.new(location, mail)
expect(message.reply_to).to eq('test@example.com')
end
it 'handles one email with display names' do
mail = mail(:reply_to => 'test ')
message = described_class.new(location, mail)
expect(message.reply_to).to eq('test ')
end
it 'handles array of emails' do
mail = mail(:reply_to => ['test1@example.com', 'test2@example.com'])
message = described_class.new(location, mail)
expect(message.reply_to).to eq('test1@example.com, test2@example.com')
end
it 'handles array of emails with display names' do
mail = mail(:reply_to => ['test1 ', 'test2 '])
message = described_class.new(location, mail)
expect(message.reply_to).to eq('test1 , test2 ')
end
end
describe '#to' do
it 'handles one email as a string' do
mail = mail(:to => 'test@example.com')
message = described_class.new(location, mail)
expect(message.to).to eq('test@example.com')
end
it 'handles one email with display names' do
mail = mail(:to => 'test ')
message = described_class.new(location, mail)
expect(message.to).to eq('test ')
end
it 'handles array of emails' do
mail = mail(:to => ['test1@example.com', 'test2@example.com'])
message = described_class.new(location, mail)
expect(message.to).to eq('test1@example.com, test2@example.com')
end
it 'handles array of emails with display names' do
mail = mail(:to => ['test1 ', 'test2 '])
message = described_class.new(location, mail)
expect(message.to).to eq('test1 , test2 ')
end
end
describe '#cc' do
it 'handles one cc email as a string' do
mail = mail(:cc => 'test@example.com')
message = described_class.new(location, mail)
expect(message.cc).to eq('test@example.com')
end
it 'handles one cc email with display name' do
mail = mail(:cc => ['test ', 'test2 '])
message = described_class.new(location, mail)
expect(message.cc).to eq('test , test2 ')
end
it 'handles array of cc emails' do
mail = mail(:cc => ['test1@example.com', 'test2@example.com'])
message = described_class.new(location, mail)
expect(message.cc).to eq('test1@example.com, test2@example.com')
end
it 'handles array of cc emails with display names' do
mail = mail(:cc => ['test ', 'test2 '])
message = described_class.new(location, mail)
expect(message.cc).to eq('test , test2 ')
end
end
describe '#bcc' do
it 'handles one bcc email as a string' do
mail = mail(:bcc => 'test@example.com')
message = described_class.new(location, mail)
expect(message.bcc).to eq('test@example.com')
end
it 'handles one bcc email with display name' do
mail = mail(:bcc => ['test ', 'test2 '])
message = described_class.new(location, mail)
expect(message.bcc).to eq('test , test2 ')
end
it 'handles array of bcc emails' do
mail = mail(:bcc => ['test1@example.com', 'test2@example.com'])
message = described_class.new(location, mail)
expect(message.bcc).to eq('test1@example.com, test2@example.com')
end
it 'handles array of bcc emails with display names' do
mail = mail(:bcc => ['test ', 'test2 '])
message = described_class.new(location, mail)
expect(message.bcc).to eq('test , test2 ')
end
end
describe '#sender' do
it 'handles one email as a string' do
mail = mail(:sender => 'sender@example.com')
message = described_class.new(location, mail)
expect(message.sender).to eq('sender@example.com')
end
it 'handles one email as a string with display name' do
mail = mail(:sender => 'test ')
message = described_class.new(location, mail)
expect(message.sender).to eq('test ')
end
it 'handles array of emails' do
mail = mail(:sender => ['sender1@example.com', 'sender2@example.com'])
message = described_class.new(location, mail)
expect(message.sender).to eq('sender1@example.com, sender2@example.com')
end
it 'handles array of emails with display names' do
mail = mail(:sender => ['test ', 'test2 '])
message = described_class.new(location, mail)
expect(message.sender).to eq('test , test2 ')
end
end
describe '#<=>' do
it 'sorts rich type before plain type' do
plain = described_class.new(location, double(content_type: 'text/plain'))
rich = described_class.new(location, double(content_type: 'text/html'))
expect([plain, rich].sort).to eq([rich, plain])
end
end
describe '#auto_link' do
let(:message){ described_class.new(location, mail) }
it 'does not modify unlinkable text' do
text = 'the quick brown fox jumped over the lazy dog'
expect(message.auto_link(text)).to eq(text)
end
it 'adds links for http' do
raw = "Link to http://localhost:3000/example/path path"
linked = "Link to http://localhost:3000/example/path path"
expect(message.auto_link(raw)).to eq(linked)
end
end
describe '#body' do
it 'handles UTF-8 charset body correctly, with QP CTE, for a non-multipart message' do
mail = mail(:sender => 'sender@example.com') do
content_type "text/html; charset=UTF-8"
content_transfer_encoding 'quoted-printable'
body "☃"
end
message = described_class.new(location, mail)
expect(message.body.encoding.name).to eq('UTF-8')
end
it 'handles UTF-8 charset HTML part body correctly, with QP CTE, for a multipart message' do
mail = mail(:sender => 'sender@example.com') do
html_part do
content_type "text/html; charset=UTF-8"
content_transfer_encoding 'quoted-printable'
body "☃"
end
end
message = described_class.new(location, mail, mail.html_part)
expect(message.body.encoding.name).to eq('UTF-8')
end
it 'handles UTF-8 charset text part body correctly, with QP CTE, for a multipart message' do
mail = mail(:sender => 'sender@example.com') do
text_part do
content_type "text/plain; charset=UTF-8"
content_transfer_encoding 'quoted-printable'
body "☃"
end
end
message = described_class.new(location, mail, mail.text_part)
expect(message.body.encoding.name).to eq('UTF-8')
end
end
end
letter-opener-1.4.1/spec/spec_helper.rb 0000644 0001750 0001750 00000000347 12607234452 020211 0 ustar abhijith abhijith require 'rubygems'
require 'bundler/setup'
Bundler.require(:default)
require "mail"
RSpec.configure do |config|
config.treat_symbols_as_metadata_keys_with_true_values = true
config.run_all_when_everything_filtered = true
end