pony 0.9 → 0.9.1
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/README.rdoc +19 -2
- data/lib/pony.rb +4 -0
- data/pony.gemspec +1 -1
- data/spec/pony_spec.rb +27 -19
- metadata +26 -15
- data/lib/pony.rb.orig +0 -109
- data/spec/pony_spec.rb.orig +0 -230
data/README.rdoc
CHANGED
@@ -54,6 +54,15 @@ You can attach a file or two with the :attachments option:
|
|
54
54
|
|
55
55
|
Note: An attachment's mime-type is set based on the filename (as dictated by the ruby gem mime-types). So 'foo.pdf' has a mime-type of 'application/pdf'
|
56
56
|
|
57
|
+
== Custom Headers
|
58
|
+
|
59
|
+
Pony allows you to specify custom mail headers
|
60
|
+
Pony.mail(
|
61
|
+
:to => 'me@example.com',
|
62
|
+
:headers => { "List-ID" => "...", "X-My-Custom-Header" => "what a cool custom header" }
|
63
|
+
)
|
64
|
+
|
65
|
+
|
57
66
|
== List Of Options
|
58
67
|
|
59
68
|
Options passed pretty much directly to Tmail
|
@@ -65,6 +74,8 @@ Options passed pretty much directly to Tmail
|
|
65
74
|
subject
|
66
75
|
charset
|
67
76
|
attachments # see Attachments section above
|
77
|
+
headers # see Custom headers section above
|
78
|
+
message_id
|
68
79
|
|
69
80
|
Other options
|
70
81
|
via # :smtp or :sendmail, see Transport section above
|
@@ -84,8 +95,9 @@ Maintained by Ben Prew
|
|
84
95
|
|
85
96
|
Written by Adam Wiggins
|
86
97
|
|
87
|
-
Patches contributed by: Mathieu Martin, Arun Thampi, Thomas Hurst,
|
88
|
-
Celis, Othmane Benkirane, Neil Mock, Hiroshi Saito, Jesse
|
98
|
+
Patches contributed by: Mathieu Martin, Arun Thampi, Thomas Hurst,
|
99
|
+
Stephen Celis, Othmane Benkirane, Neil Mock, Hiroshi Saito, Jesse
|
100
|
+
Cooke, Nickolas Means, and Rick Olson
|
89
101
|
|
90
102
|
Released under the MIT License: http://www.opensource.org/licenses/mit-license.php
|
91
103
|
|
@@ -95,6 +107,11 @@ mailing list: ponyrb@googlegroups.com
|
|
95
107
|
|
96
108
|
== Releases
|
97
109
|
|
110
|
+
0.9.1
|
111
|
+
* provide the ability to set custom mail headers with something like:
|
112
|
+
Pony.mail(:headers => {"List-ID" => "..."})
|
113
|
+
* provide the ability to set the Message-Id from Pony.mail
|
114
|
+
|
98
115
|
0.9
|
99
116
|
* merge in kalins fixes to use tmail.destinations instead of trying to parse tmail.to, tmail.cc and tmail.bcc. New specs to test functionality
|
100
117
|
|
data/lib/pony.rb
CHANGED
@@ -35,6 +35,7 @@ module Pony
|
|
35
35
|
mail.bcc = options[:bcc]
|
36
36
|
mail.from = options[:from] || 'pony@unknown'
|
37
37
|
mail.subject = options[:subject]
|
38
|
+
mail.message_id = options[:message_id]
|
38
39
|
if options[:attachments]
|
39
40
|
# If message has attachment, then body must be sent as a message part
|
40
41
|
# or it will not be interpreted correctly by client.
|
@@ -55,6 +56,9 @@ module Pony
|
|
55
56
|
mail.content_type = options[:content_type] || "text/plain"
|
56
57
|
mail.body = options[:body] || ""
|
57
58
|
end
|
59
|
+
(options[:headers] ||= {}).each do |key, value|
|
60
|
+
mail[key] = value
|
61
|
+
end
|
58
62
|
mail.charset = options[:charset] # charset must be set after setting content_type
|
59
63
|
mail
|
60
64
|
end
|
data/pony.gemspec
CHANGED
data/spec/pony_spec.rb
CHANGED
@@ -56,7 +56,7 @@ describe Pony do
|
|
56
56
|
Pony.build_tmail(:bcc => 'joe@example.com').bcc.should == [ 'joe@example.com' ]
|
57
57
|
end
|
58
58
|
|
59
|
-
|
59
|
+
it "bcc with multiple recipients" do
|
60
60
|
Pony.build_tmail(:bcc => 'joe@example.com, friedrich@example.com').bcc.should == [ 'joe@example.com', 'friedrich@example.com' ]
|
61
61
|
end
|
62
62
|
|
@@ -85,6 +85,14 @@ describe Pony do
|
|
85
85
|
Pony.build_tmail(:content_type => 'text/html').content_type.should == 'text/html'
|
86
86
|
end
|
87
87
|
|
88
|
+
it "message_id" do
|
89
|
+
Pony.build_tmail(:message_id => '<abc@def.com>').message_id.should == '<abc@def.com>'
|
90
|
+
end
|
91
|
+
|
92
|
+
it "custom headers" do
|
93
|
+
Pony.build_tmail(:headers => {"List-ID" => "<abc@def.com>"})['List-ID'].to_s.should == '<abc@def.com>'
|
94
|
+
end
|
95
|
+
|
88
96
|
it "attachments" do
|
89
97
|
tmail = Pony.build_tmail(:attachments => {"foo.txt" => "content of foo.txt"})
|
90
98
|
tmail.should have(2).parts
|
@@ -141,27 +149,27 @@ Y29udGVudCBvZiBmb28ucGRm
|
|
141
149
|
Net::SMTP.stub!(:new).and_return(@smtp)
|
142
150
|
end
|
143
151
|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
152
|
+
it "passes cc and bcc as the list of recipients" do
|
153
|
+
@smtp.should_receive(:send_message).with("message", ['from'], ['to', 'cc', 'bcc'])
|
154
|
+
Pony.transport_via_smtp(mock('tmail', :to => ['to'], :cc => ['cc'], :from => ['from'], :to_s => 'message', :bcc => ['bcc'], :destinations => ['to', 'cc', 'bcc']))
|
155
|
+
@smtp.should_receive(:send_message).with("message", 'from', ['to', 'cc'])
|
156
|
+
Pony.transport_via_smtp(mock('tmail', :to => 'to', :cc => 'cc', :from => 'from', :to_s => 'message', :bcc => nil, :destinations => ['to', 'cc']))
|
157
|
+
end
|
150
158
|
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
159
|
+
it "only pass cc as the list of recipients" do
|
160
|
+
@smtp.should_receive(:send_message).with("message", ['from'], ['to', 'cc' ])
|
161
|
+
Pony.transport_via_smtp(mock('tmail', :to => ['to'], :cc => ['cc'], :from => ['from'], :to_s => 'message', :bcc => nil, :destinations => ['to', 'cc']))
|
162
|
+
end
|
155
163
|
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
164
|
+
it "only pass bcc as the list of recipients" do
|
165
|
+
@smtp.should_receive(:send_message).with("message", ['from'], ['to', 'bcc' ])
|
166
|
+
Pony.transport_via_smtp(mock('tmail', :to => ['to'], :cc => nil, :from => ['from'], :to_s => 'message', :bcc => ['bcc'], :destinations => ['to', 'bcc']))
|
167
|
+
end
|
160
168
|
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
169
|
+
it "passes cc and bcc as the list of recipients when there are a few of them" do
|
170
|
+
@smtp.should_receive(:send_message).with("message", ['from'], ['to', 'to2', 'cc', 'bcc', 'bcc2', 'bcc3'])
|
171
|
+
Pony.transport_via_smtp(mock('tmail', :to => ['to', 'to2'], :cc => ['cc'], :from => ['from'], :to_s => 'message', :bcc => ['bcc', 'bcc2', 'bcc3'], :destinations => ['to', 'to2', 'cc', 'bcc', 'bcc2', 'bcc3']))
|
172
|
+
end
|
165
173
|
|
166
174
|
it "defaults to localhost as the SMTP server" do
|
167
175
|
Net::SMTP.should_receive(:new).with('localhost', '25').and_return(@smtp)
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pony
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 9
|
8
|
+
- 1
|
9
|
+
version: 0.9.1
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Adam Wiggins
|
@@ -10,29 +15,35 @@ autorequire:
|
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
17
|
|
13
|
-
date: 2010-
|
18
|
+
date: 2010-04-15 00:00:00 -07:00
|
14
19
|
default_executable:
|
15
20
|
dependencies:
|
16
21
|
- !ruby/object:Gem::Dependency
|
17
22
|
name: tmail
|
18
|
-
|
19
|
-
|
20
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
21
25
|
requirements:
|
22
26
|
- - ~>
|
23
27
|
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 1
|
30
|
+
- 0
|
24
31
|
version: "1.0"
|
25
|
-
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
26
34
|
- !ruby/object:Gem::Dependency
|
27
35
|
name: mime-types
|
28
|
-
|
29
|
-
|
30
|
-
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
31
38
|
requirements:
|
32
39
|
- - ">="
|
33
40
|
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 1
|
43
|
+
- 16
|
34
44
|
version: "1.16"
|
35
|
-
|
45
|
+
type: :runtime
|
46
|
+
version_requirements: *id002
|
36
47
|
description: "Send email in one command: Pony.mail(:to => 'someone@example.com', :body => 'hello')"
|
37
48
|
email: ben.prew@gmail.com
|
38
49
|
executables: []
|
@@ -46,9 +57,7 @@ files:
|
|
46
57
|
- Rakefile
|
47
58
|
- pony.gemspec
|
48
59
|
- lib/pony.rb
|
49
|
-
- lib/pony.rb.orig
|
50
60
|
- spec/base.rb
|
51
|
-
- spec/pony_spec.rb.orig
|
52
61
|
- spec/pony_spec.rb
|
53
62
|
has_rdoc: true
|
54
63
|
homepage: http://github.com/benprew/pony
|
@@ -64,18 +73,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
64
73
|
requirements:
|
65
74
|
- - ">="
|
66
75
|
- !ruby/object:Gem::Version
|
76
|
+
segments:
|
77
|
+
- 0
|
67
78
|
version: "0"
|
68
|
-
version:
|
69
79
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
80
|
requirements:
|
71
81
|
- - ">="
|
72
82
|
- !ruby/object:Gem::Version
|
83
|
+
segments:
|
84
|
+
- 0
|
73
85
|
version: "0"
|
74
|
-
version:
|
75
86
|
requirements: []
|
76
87
|
|
77
88
|
rubyforge_project: pony
|
78
|
-
rubygems_version: 1.3.
|
89
|
+
rubygems_version: 1.3.6
|
79
90
|
signing_key:
|
80
91
|
specification_version: 3
|
81
92
|
summary: "Send email in one command: Pony.mail(:to => 'someone@example.com', :body => 'hello')"
|
data/lib/pony.rb.orig
DELETED
@@ -1,109 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'net/smtp'
|
3
|
-
require 'mime/types'
|
4
|
-
begin
|
5
|
-
require 'smtp_tls'
|
6
|
-
rescue LoadError
|
7
|
-
end
|
8
|
-
require 'base64'
|
9
|
-
begin
|
10
|
-
require 'tmail'
|
11
|
-
rescue LoadError
|
12
|
-
require 'actionmailer'
|
13
|
-
end
|
14
|
-
|
15
|
-
module Pony
|
16
|
-
def self.mail(options)
|
17
|
-
raise(ArgumentError, ":to is required") unless options[:to]
|
18
|
-
|
19
|
-
via = options.delete(:via)
|
20
|
-
if via.nil?
|
21
|
-
transport build_tmail(options)
|
22
|
-
else
|
23
|
-
if via_options.include?(via.to_s)
|
24
|
-
send("transport_via_#{via}", build_tmail(options), options)
|
25
|
-
else
|
26
|
-
raise(ArgumentError, ":via must be either smtp or sendmail")
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def self.build_tmail(options)
|
32
|
-
mail = TMail::Mail.new
|
33
|
-
mail.to = options[:to]
|
34
|
-
mail.cc = options[:cc]
|
35
|
-
mail.bcc = options[:bcc]
|
36
|
-
mail.from = options[:from] || 'pony@unknown'
|
37
|
-
mail.subject = options[:subject]
|
38
|
-
if options[:attachments]
|
39
|
-
# If message has attachment, then body must be sent as a message part
|
40
|
-
# or it will not be interpreted correctly by client.
|
41
|
-
body = TMail::Mail.new
|
42
|
-
body.body = options[:body] || ""
|
43
|
-
body.content_type = options[:content_type] || "text/plain"
|
44
|
-
mail.parts.push body
|
45
|
-
(options[:attachments] || []).each do |name, body|
|
46
|
-
attachment = TMail::Mail.new
|
47
|
-
attachment.transfer_encoding = "base64"
|
48
|
-
attachment.body = Base64.encode64(body)
|
49
|
-
content_type = MIME::Types.type_for(name).to_s
|
50
|
-
attachment.content_type = content_type unless content_type == ""
|
51
|
-
attachment.set_content_disposition "attachment", "filename" => name
|
52
|
-
mail.parts.push attachment
|
53
|
-
end
|
54
|
-
else
|
55
|
-
mail.content_type = options[:content_type] || "text/plain"
|
56
|
-
mail.body = options[:body] || ""
|
57
|
-
end
|
58
|
-
mail.charset = options[:charset] # charset must be set after setting content_type
|
59
|
-
mail
|
60
|
-
end
|
61
|
-
|
62
|
-
def self.sendmail_binary
|
63
|
-
sendmail = `which sendmail`.chomp
|
64
|
-
sendmail.empty? ? '/usr/sbin/sendmail' : sendmail
|
65
|
-
end
|
66
|
-
|
67
|
-
def self.transport(tmail)
|
68
|
-
if File.executable? sendmail_binary
|
69
|
-
transport_via_sendmail(tmail)
|
70
|
-
else
|
71
|
-
transport_via_smtp(tmail)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
def self.via_options
|
76
|
-
%w(sendmail smtp)
|
77
|
-
end
|
78
|
-
|
79
|
-
def self.transport_via_sendmail(tmail, options={})
|
80
|
-
IO.popen('-', 'w+') do |pipe|
|
81
|
-
if pipe
|
82
|
-
pipe.write(tmail.to_s)
|
83
|
-
else
|
84
|
-
exec(sendmail_binary, "-t")
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
def self.transport_via_smtp(tmail, options={:smtp => {}})
|
90
|
-
default_options = {:smtp => { :host => 'localhost', :port => '25', :domain => 'localhost.localdomain' }}
|
91
|
-
o = default_options[:smtp].merge(options[:smtp])
|
92
|
-
smtp = Net::SMTP.new(o[:host], o[:port])
|
93
|
-
if o[:tls]
|
94
|
-
raise "You may need: gem install smtp_tls" unless smtp.respond_to?(:enable_starttls)
|
95
|
-
smtp.enable_starttls
|
96
|
-
end
|
97
|
-
if o.include?(:auth)
|
98
|
-
smtp.start(o[:domain], o[:user], o[:password], o[:auth])
|
99
|
-
else
|
100
|
-
smtp.start(o[:domain])
|
101
|
-
end
|
102
|
-
<<<<<<< HEAD:lib/pony.rb
|
103
|
-
smtp.send_message tmail.to_s, tmail.from, tmail.destinations
|
104
|
-
=======
|
105
|
-
smtp.send_message tmail.to_s, tmail.from, [ tmail.to, tmail.cc, tmail.bcc ].select { |i| i && i != '' }
|
106
|
-
>>>>>>> 1cf0f8805e7196bc7237590437191efc6badec7e:lib/pony.rb
|
107
|
-
smtp.finish
|
108
|
-
end
|
109
|
-
end
|
data/spec/pony_spec.rb.orig
DELETED
@@ -1,230 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/base'
|
2
|
-
|
3
|
-
describe Pony do
|
4
|
-
it "sends mail" do
|
5
|
-
Pony.should_receive(:transport) do |tmail|
|
6
|
-
tmail.to.should == [ 'joe@example.com' ]
|
7
|
-
tmail.from.should == [ 'sender@example.com' ]
|
8
|
-
tmail.subject.should == 'hi'
|
9
|
-
tmail.body.should == 'Hello, Joe.'
|
10
|
-
end
|
11
|
-
Pony.mail(:to => 'joe@example.com', :from => 'sender@example.com', :subject => 'hi', :body => 'Hello, Joe.')
|
12
|
-
end
|
13
|
-
|
14
|
-
it "requires :to param" do
|
15
|
-
Pony.stub!(:transport)
|
16
|
-
lambda { Pony.mail({}) }.should raise_error(ArgumentError)
|
17
|
-
end
|
18
|
-
|
19
|
-
it "doesn't require any other param" do
|
20
|
-
Pony.stub!(:transport)
|
21
|
-
lambda { Pony.mail(:to => 'joe@example.com') }.should_not raise_error
|
22
|
-
end
|
23
|
-
|
24
|
-
####################
|
25
|
-
|
26
|
-
describe "builds a TMail object with field:" do
|
27
|
-
it "to" do
|
28
|
-
Pony.build_tmail(:to => 'joe@example.com').to.should == [ 'joe@example.com' ]
|
29
|
-
end
|
30
|
-
|
31
|
-
it "to with multiple recipients" do
|
32
|
-
Pony.build_tmail(:to => 'joe@example.com, friedrich@example.com').to.should == [ 'joe@example.com', 'friedrich@example.com' ]
|
33
|
-
end
|
34
|
-
|
35
|
-
it "to with multiple recipients and names" do
|
36
|
-
Pony.build_tmail(:to => 'joe@example.com, "Friedrich Hayek" <friedrich@example.com>').to.should == [ 'joe@example.com', 'friedrich@example.com' ]
|
37
|
-
end
|
38
|
-
|
39
|
-
it "to with multiple recipients and names in an array" do
|
40
|
-
Pony.build_tmail(:to => ['joe@example.com', '"Friedrich Hayek" <friedrich@example.com>']).to.should == [ 'joe@example.com', 'friedrich@example.com' ]
|
41
|
-
end
|
42
|
-
|
43
|
-
it "cc" do
|
44
|
-
Pony.build_tmail(:cc => 'joe@example.com').cc.should == [ 'joe@example.com' ]
|
45
|
-
end
|
46
|
-
|
47
|
-
it "cc with multiple recipients" do
|
48
|
-
Pony.build_tmail(:cc => 'joe@example.com, friedrich@example.com').cc.should == [ 'joe@example.com', 'friedrich@example.com' ]
|
49
|
-
end
|
50
|
-
|
51
|
-
it "from" do
|
52
|
-
Pony.build_tmail(:from => 'joe@example.com').from.should == [ 'joe@example.com' ]
|
53
|
-
end
|
54
|
-
|
55
|
-
it "bcc" do
|
56
|
-
Pony.build_tmail(:bcc => 'joe@example.com').bcc.should == [ 'joe@example.com' ]
|
57
|
-
end
|
58
|
-
|
59
|
-
it "bcc with multiple recipients" do
|
60
|
-
Pony.build_tmail(:bcc => 'joe@example.com, friedrich@example.com').bcc.should == [ 'joe@example.com', 'friedrich@example.com' ]
|
61
|
-
end
|
62
|
-
|
63
|
-
it "charset" do
|
64
|
-
Pony.build_tmail(:charset => 'UTF-8').charset.should == 'UTF-8'
|
65
|
-
end
|
66
|
-
|
67
|
-
it "default charset" do
|
68
|
-
Pony.build_tmail(:body => 'body').charset.should == nil
|
69
|
-
Pony.build_tmail(:body => 'body', :content_type => 'text/html').charset.should == nil
|
70
|
-
end
|
71
|
-
|
72
|
-
it "from (default)" do
|
73
|
-
Pony.build_tmail({}).from.should == [ 'pony@unknown' ]
|
74
|
-
end
|
75
|
-
|
76
|
-
it "subject" do
|
77
|
-
Pony.build_tmail(:subject => 'hello').subject.should == 'hello'
|
78
|
-
end
|
79
|
-
|
80
|
-
it "body" do
|
81
|
-
Pony.build_tmail(:body => 'What do you know, Joe?').body.should == 'What do you know, Joe?'
|
82
|
-
end
|
83
|
-
|
84
|
-
it "content_type" do
|
85
|
-
Pony.build_tmail(:content_type => 'text/html').content_type.should == 'text/html'
|
86
|
-
end
|
87
|
-
|
88
|
-
it "attachments" do
|
89
|
-
tmail = Pony.build_tmail(:attachments => {"foo.txt" => "content of foo.txt"})
|
90
|
-
tmail.should have(2).parts
|
91
|
-
tmail.parts.first.to_s.should == "Content-Type: text/plain\n\n"
|
92
|
-
tmail.parts.last.to_s.should == <<-PART
|
93
|
-
Content-Type: text/plain
|
94
|
-
Content-Transfer-Encoding: Base64
|
95
|
-
Content-Disposition: attachment; filename=foo.txt
|
96
|
-
|
97
|
-
Y29udGVudCBvZiBmb28udHh0
|
98
|
-
PART
|
99
|
-
end
|
100
|
-
|
101
|
-
it "suggests mime-type" do
|
102
|
-
tmail = Pony.build_tmail(:attachments => {"foo.pdf" => "content of foo.pdf"})
|
103
|
-
tmail.should have(2).parts
|
104
|
-
tmail.parts.first.to_s.should == "Content-Type: text/plain\n\n"
|
105
|
-
tmail.parts.last.to_s.should == <<-PART
|
106
|
-
Content-Type: application/pdf
|
107
|
-
Content-Transfer-Encoding: Base64
|
108
|
-
Content-Disposition: attachment; filename=foo.pdf
|
109
|
-
|
110
|
-
Y29udGVudCBvZiBmb28ucGRm
|
111
|
-
PART
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
describe "transport" do
|
116
|
-
it "transports via the sendmail binary if it exists" do
|
117
|
-
File.stub!(:executable?).and_return(true)
|
118
|
-
Pony.should_receive(:transport_via_sendmail).with(:tmail)
|
119
|
-
Pony.transport(:tmail)
|
120
|
-
end
|
121
|
-
|
122
|
-
it "transports via smtp if no sendmail binary" do
|
123
|
-
Pony.stub!(:sendmail_binary).and_return('/does/not/exist')
|
124
|
-
Pony.should_receive(:transport_via_smtp).with(:tmail)
|
125
|
-
Pony.transport(:tmail)
|
126
|
-
end
|
127
|
-
|
128
|
-
it "transports mail via /usr/sbin/sendmail binary" do
|
129
|
-
pipe = mock('sendmail pipe')
|
130
|
-
IO.should_receive(:popen).with('-',"w+").and_yield(pipe)
|
131
|
-
pipe.should_receive(:write).with('message')
|
132
|
-
Pony.transport_via_sendmail(mock('tmail', :to => ['to'], :from => ['from'], :to_s => 'message'))
|
133
|
-
end
|
134
|
-
|
135
|
-
describe "SMTP transport" do
|
136
|
-
before do
|
137
|
-
@smtp = mock('net::smtp object')
|
138
|
-
@smtp.stub!(:start)
|
139
|
-
@smtp.stub!(:send_message)
|
140
|
-
@smtp.stub!(:finish)
|
141
|
-
Net::SMTP.stub!(:new).and_return(@smtp)
|
142
|
-
end
|
143
|
-
|
144
|
-
it "passes cc and bcc as the list of recipients" do
|
145
|
-
<<<<<<< HEAD:spec/pony_spec.rb
|
146
|
-
@smtp.should_receive(:send_message).with("message", ['from'], ['to', 'cc', 'bcc'])
|
147
|
-
Pony.transport_via_smtp(mock('tmail', :to => ['to'], :cc => ['cc'], :from => ['from'], :to_s => 'message', :bcc => ['bcc'], :destinations => ['to', 'cc', 'bcc']))
|
148
|
-
=======
|
149
|
-
@smtp.should_receive(:send_message).with("message", 'from', ['to', 'cc', 'bcc'])
|
150
|
-
Pony.transport_via_smtp(mock('tmail', :to => 'to', :cc => 'cc', :from => 'from', :to_s => 'message', :bcc => 'bcc'))
|
151
|
-
|
152
|
-
@smtp.should_receive(:send_message).with("message", 'from', ['to', 'cc'])
|
153
|
-
Pony.transport_via_smtp(mock('tmail', :to => 'to', :cc => 'cc', :from => 'from', :to_s => 'message', :bcc => nil))
|
154
|
-
>>>>>>> 1cf0f8805e7196bc7237590437191efc6badec7e:spec/pony_spec.rb
|
155
|
-
end
|
156
|
-
|
157
|
-
it "only pass cc as the list of recipients" do
|
158
|
-
@smtp.should_receive(:send_message).with("message", ['from'], ['to', 'cc' ])
|
159
|
-
Pony.transport_via_smtp(mock('tmail', :to => ['to'], :cc => ['cc'], :from => ['from'], :to_s => 'message', :bcc => nil, :destinations => ['to', 'cc']))
|
160
|
-
end
|
161
|
-
|
162
|
-
it "only pass bcc as the list of recipients" do
|
163
|
-
@smtp.should_receive(:send_message).with("message", ['from'], ['to', 'bcc' ])
|
164
|
-
Pony.transport_via_smtp(mock('tmail', :to => ['to'], :cc => nil, :from => ['from'], :to_s => 'message', :bcc => ['bcc'], :destinations => ['to', 'bcc']))
|
165
|
-
end
|
166
|
-
|
167
|
-
it "passes cc and bcc as the list of recipients when there are a few of them" do
|
168
|
-
@smtp.should_receive(:send_message).with("message", ['from'], ['to', 'to2', 'cc', 'bcc', 'bcc2', 'bcc3'])
|
169
|
-
Pony.transport_via_smtp(mock('tmail', :to => ['to', 'to2'], :cc => ['cc'], :from => ['from'], :to_s => 'message', :bcc => ['bcc', 'bcc2', 'bcc3'], :destinations => ['to', 'to2', 'cc', 'bcc', 'bcc2', 'bcc3']))
|
170
|
-
end
|
171
|
-
|
172
|
-
it "defaults to localhost as the SMTP server" do
|
173
|
-
Net::SMTP.should_receive(:new).with('localhost', '25').and_return(@smtp)
|
174
|
-
Pony.transport_via_smtp(mock('tmail', :to => ['to'], :from => ['from'], :to_s => 'message', :cc => nil, :bcc => nil, :destinations => ['to']))
|
175
|
-
end
|
176
|
-
|
177
|
-
it "uses SMTP authorization when auth key is provided" do
|
178
|
-
o = { :smtp => { :user => 'user', :password => 'password', :auth => 'plain'}}
|
179
|
-
@smtp.should_receive(:start).with('localhost.localdomain', 'user', 'password', 'plain')
|
180
|
-
Pony.transport_via_smtp(mock('tmail', :to => ['to'], :from => ['from'], :to_s => 'message', :cc => nil, :bcc => nil, :destinations => ['to']), o)
|
181
|
-
end
|
182
|
-
|
183
|
-
it "enable starttls when tls option is true" do
|
184
|
-
o = { :smtp => { :user => 'user', :password => 'password', :auth => 'plain', :tls => true}}
|
185
|
-
@smtp.should_receive(:enable_starttls)
|
186
|
-
Pony.transport_via_smtp(mock('tmail', :to => ['to'], :from => ['from'], :to_s => 'message', :cc => nil, :bcc => nil, :destinations => ['to']), o)
|
187
|
-
end
|
188
|
-
|
189
|
-
it "starts the job" do
|
190
|
-
@smtp.should_receive(:start)
|
191
|
-
Pony.transport_via_smtp(mock('tmail', :to => ['to'], :from => ['from'], :to_s => 'message', :cc => nil, :bcc => nil, :destinations => ['to']))
|
192
|
-
end
|
193
|
-
|
194
|
-
it "sends a tmail message" do
|
195
|
-
@smtp.should_receive(:send_message)
|
196
|
-
Pony.transport_via_smtp(mock('tmail', :to => ['to'], :from => ['from'], :to_s => 'message', :cc => nil, :bcc => nil, :destinations => ['to']))
|
197
|
-
end
|
198
|
-
|
199
|
-
it "finishes the job" do
|
200
|
-
@smtp.should_receive(:finish)
|
201
|
-
Pony.transport_via_smtp(mock('tmail', :to => ['to'], :from => ['from'], :to_s => 'message', :cc => nil, :bcc => nil, :destinations => ['to']))
|
202
|
-
end
|
203
|
-
|
204
|
-
end
|
205
|
-
end
|
206
|
-
|
207
|
-
describe ":via option should over-ride the default transport mechanism" do
|
208
|
-
it "should send via sendmail if :via => sendmail" do
|
209
|
-
Pony.should_receive(:transport_via_sendmail)
|
210
|
-
Pony.mail(:to => 'joe@example.com', :via => :sendmail)
|
211
|
-
end
|
212
|
-
|
213
|
-
it "should send via smtp if :via => smtp" do
|
214
|
-
Pony.should_receive(:transport_via_smtp)
|
215
|
-
Pony.mail(:to => 'joe@example.com', :via => :smtp)
|
216
|
-
end
|
217
|
-
|
218
|
-
it "should raise an error if via is neither smtp nor sendmail" do
|
219
|
-
lambda { Pony.mail(:to => 'joe@plumber.com', :via => :pigeon) }.should raise_error(ArgumentError)
|
220
|
-
end
|
221
|
-
end
|
222
|
-
|
223
|
-
describe "sendmail binary location" do
|
224
|
-
it "should default to /usr/sbin/sendmail if not in path" do
|
225
|
-
Pony.stub!(:'`').and_return('')
|
226
|
-
Pony.sendmail_binary.should == '/usr/sbin/sendmail'
|
227
|
-
end
|
228
|
-
end
|
229
|
-
|
230
|
-
end
|