pony 0.3 → 0.4

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/Rakefile CHANGED
@@ -29,7 +29,7 @@ require 'rake/clean'
29
29
  require 'rake/gempackagetask'
30
30
  require 'fileutils'
31
31
 
32
- version = "0.3"
32
+ version = "0.4"
33
33
  name = "pony"
34
34
 
35
35
  spec = Gem::Specification.new do |s|
@@ -37,9 +37,9 @@ spec = Gem::Specification.new do |s|
37
37
  s.version = version
38
38
  s.summary = "Send email in one command: Pony.mail(:to => 'someone@example.com', :body => 'hello')"
39
39
  s.description = "Send email in one command: Pony.mail(:to => 'someone@example.com', :body => 'hello')"
40
- s.author = "Adam Wiggins"
41
- s.email = "adam@heroku.com"
42
- s.homepage = "http://github.com/adamwiggins/pony"
40
+ s.author = "Adam Wiggins, maint: Ben Prew"
41
+ s.email = "ben.prew@gmail.com"
42
+ s.homepage = "http://github.com/benprew/pony"
43
43
  s.rubyforge_project = "pony"
44
44
 
45
45
  s.platform = Gem::Platform::RUBY
@@ -1,5 +1,10 @@
1
1
  require 'rubygems'
2
2
  require 'net/smtp'
3
+ begin
4
+ require 'smtp_tls'
5
+ rescue LoadError
6
+ end
7
+ require 'base64'
3
8
  begin
4
9
  require 'tmail'
5
10
  rescue LoadError
@@ -24,10 +29,19 @@ module Pony
24
29
 
25
30
  def self.build_tmail(options)
26
31
  mail = TMail::Mail.new
32
+ mail.content_type = options[:content_type] if options[:content_type]
27
33
  mail.to = options[:to]
28
34
  mail.from = options[:from] || 'pony@unknown'
29
35
  mail.subject = options[:subject]
30
36
  mail.body = options[:body] || ""
37
+ (options[:attachments] || []).each do |name, body|
38
+ attachment = TMail::Mail.new
39
+ attachment.transfer_encoding = "base64"
40
+ attachment.body = Base64.encode64(body)
41
+ # attachment.set_content_type # TODO: if necessary
42
+ attachment.set_content_disposition "attachment", "filename" => name
43
+ mail.parts.push attachment
44
+ end
31
45
  mail
32
46
  end
33
47
 
@@ -61,6 +75,10 @@ module Pony
61
75
  default_options = {:smtp => { :host => 'localhost', :port => '25', :domain => 'localhost.localdomain' }}
62
76
  o = default_options[:smtp].merge(options[:smtp])
63
77
  smtp = Net::SMTP.new(o[:host], o[:port])
78
+ if o[:tls]
79
+ raise "You may need: gem install smtp_tls" unless smtp.respond_to?(:enable_starttls)
80
+ smtp.enable_starttls
81
+ end
64
82
  if o.include?(:auth)
65
83
  smtp.start(o[:domain], o[:user], o[:password], o[:auth])
66
84
  else
@@ -43,6 +43,21 @@ describe Pony do
43
43
  it "body" do
44
44
  Pony.build_tmail(:body => 'What do you know, Joe?').body.should == 'What do you know, Joe?'
45
45
  end
46
+
47
+ it "content_type" do
48
+ Pony.build_tmail(:content_type => 'text/html').content_type.should == 'text/html'
49
+ end
50
+
51
+ it "attachments" do
52
+ tmail = Pony.build_tmail(:attachments => {"foo.txt" => "content of foo.txt"})
53
+ tmail.should have(1).parts
54
+ tmail.parts.first.to_s.should == <<-PART
55
+ Content-Transfer-Encoding: Base64
56
+ Content-Disposition: attachment; filename=foo.txt
57
+
58
+ Y29udGVudCBvZiBmb28udHh0
59
+ PART
60
+ end
46
61
  end
47
62
 
48
63
  describe "transport" do
@@ -85,6 +100,12 @@ describe Pony do
85
100
  Pony.transport_via_smtp(mock('tmail', :to => 'to', :from => 'from', :to_s => 'message'), o)
86
101
  end
87
102
 
103
+ it "enable starttls when tls option is true" do
104
+ o = { :smtp => { :user => 'user', :password => 'password', :auth => 'plain', :tls => true}}
105
+ @smtp.should_receive(:enable_starttls)
106
+ Pony.transport_via_smtp(mock('tmail', :to => 'to', :from => 'from', :to_s => 'message'), o)
107
+ end
108
+
88
109
  it "starts the job" do
89
110
  @smtp.should_receive(:start)
90
111
  Pony.transport_via_smtp(mock('tmail', :to => 'to', :from => 'from', :to_s => 'message'))
@@ -0,0 +1,145 @@
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 "from" do
32
+ Pony.build_tmail(:from => 'joe@example.com').from.should == [ 'joe@example.com' ]
33
+ end
34
+
35
+ it "from (default)" do
36
+ Pony.build_tmail({}).from.should == [ 'pony@unknown' ]
37
+ end
38
+
39
+ it "subject" do
40
+ Pony.build_tmail(:subject => 'hello').subject.should == 'hello'
41
+ end
42
+
43
+ it "body" do
44
+ Pony.build_tmail(:body => 'What do you know, Joe?').body.should == 'What do you know, Joe?'
45
+ end
46
+
47
+ <<<<<<< HEAD:spec/pony_spec.rb
48
+ it "content_type" do
49
+ Pony.build_tmail(:content_type => 'text/html').content_type.should == 'text/html'
50
+ end
51
+ =======
52
+ it "attachments" do
53
+ tmail = Pony.build_tmail(:attachments => {"foo.txt" => "content of foo.txt"})
54
+ tmail.should have(1).parts
55
+ tmail.parts.first.to_s.should == <<-PART
56
+ Content-Transfer-Encoding: Base64
57
+ Content-Disposition: attachment; filename=foo.txt
58
+
59
+ Y29udGVudCBvZiBmb28udHh0
60
+ PART
61
+ end
62
+ >>>>>>> c01d11243041d1897c67221bb92cdd5ff3fd6c0c:spec/pony_spec.rb
63
+ end
64
+
65
+ describe "transport" do
66
+ it "transports via the sendmail binary if it exists" do
67
+ File.stub!(:executable?).and_return(true)
68
+ Pony.should_receive(:transport_via_sendmail).with(:tmail)
69
+ Pony.transport(:tmail)
70
+ end
71
+
72
+ it "transports via smtp if no sendmail binary" do
73
+ Pony.stub!(:sendmail_binary).and_return('/does/not/exist')
74
+ Pony.should_receive(:transport_via_smtp).with(:tmail)
75
+ Pony.transport(:tmail)
76
+ end
77
+
78
+ it "transports mail via /usr/sbin/sendmail binary" do
79
+ pipe = mock('sendmail pipe')
80
+ IO.should_receive(:popen).with('-',"w+").and_yield(pipe)
81
+ pipe.should_receive(:write).with('message')
82
+ Pony.transport_via_sendmail(mock('tmail', :to => 'to', :from => 'from', :to_s => 'message'))
83
+ end
84
+
85
+ describe "SMTP transport" do
86
+ before do
87
+ @smtp = mock('net::smtp object')
88
+ @smtp.stub!(:start)
89
+ @smtp.stub!(:send_message)
90
+ @smtp.stub!(:finish)
91
+ Net::SMTP.stub!(:new).and_return(@smtp)
92
+ end
93
+
94
+ it "defaults to localhost as the SMTP server" do
95
+ Net::SMTP.should_receive(:new).with('localhost', '25').and_return(@smtp)
96
+ Pony.transport_via_smtp(mock('tmail', :to => 'to', :from => 'from', :to_s => 'message'))
97
+ end
98
+
99
+ it "uses SMTP authorization when auth key is provided" do
100
+ o = { :smtp => { :user => 'user', :password => 'password', :auth => 'plain'}}
101
+ @smtp.should_receive(:start).with('localhost.localdomain', 'user', 'password', 'plain')
102
+ Pony.transport_via_smtp(mock('tmail', :to => 'to', :from => 'from', :to_s => 'message'), o)
103
+ end
104
+
105
+ it "enable starttls when tls option is true" do
106
+ o = { :smtp => { :user => 'user', :password => 'password', :auth => 'plain', :tls => true}}
107
+ @smtp.should_receive(:enable_starttls)
108
+ Pony.transport_via_smtp(mock('tmail', :to => 'to', :from => 'from', :to_s => 'message'), o)
109
+ end
110
+
111
+ it "starts the job" do
112
+ @smtp.should_receive(:start)
113
+ Pony.transport_via_smtp(mock('tmail', :to => 'to', :from => 'from', :to_s => 'message'))
114
+ end
115
+
116
+ it "sends a tmail message" do
117
+ @smtp.should_receive(:send_message)
118
+ Pony.transport_via_smtp(mock('tmail', :to => 'to', :from => 'from', :to_s => 'message'))
119
+ end
120
+
121
+ it "finishes the job" do
122
+ @smtp.should_receive(:finish)
123
+ Pony.transport_via_smtp(mock('tmail', :to => 'to', :from => 'from', :to_s => 'message'))
124
+ end
125
+
126
+ end
127
+ end
128
+
129
+ describe ":via option should over-ride the default transport mechanism" do
130
+ it "should send via sendmail if :via => sendmail" do
131
+ Pony.should_receive(:transport_via_sendmail)
132
+ Pony.mail(:to => 'joe@example.com', :via => :sendmail)
133
+ end
134
+
135
+ it "should send via smtp if :via => smtp" do
136
+ Pony.should_receive(:transport_via_smtp)
137
+ Pony.mail(:to => 'joe@example.com', :via => :smtp)
138
+ end
139
+
140
+ it "should raise an error if via is neither smtp nor sendmail" do
141
+ lambda { Pony.mail(:to => 'joe@plumber.com', :via => :pigeon) }.should raise_error(ArgumentError)
142
+ end
143
+ end
144
+
145
+ end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pony
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.3"
4
+ version: "0.4"
5
5
  platform: ruby
6
6
  authors:
7
- - Adam Wiggins
7
+ - "Adam Wiggins, maint: Ben Prew"
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-02-17 00:00:00 -08:00
12
+ date: 2009-11-13 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -23,7 +23,7 @@ dependencies:
23
23
  version: "1.0"
24
24
  version:
25
25
  description: "Send email in one command: Pony.mail(:to => 'someone@example.com', :body => 'hello')"
26
- email: adam@heroku.com
26
+ email: ben.prew@gmail.com
27
27
  executables: []
28
28
 
29
29
  extensions: []
@@ -35,8 +35,11 @@ files:
35
35
  - lib/pony.rb
36
36
  - spec/base.rb
37
37
  - spec/pony_spec.rb
38
- has_rdoc: false
39
- homepage: http://github.com/adamwiggins/pony
38
+ - spec/pony_spec.rb.orig
39
+ has_rdoc: true
40
+ homepage: http://github.com/benprew/pony
41
+ licenses: []
42
+
40
43
  post_install_message:
41
44
  rdoc_options: []
42
45
 
@@ -57,9 +60,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
57
60
  requirements: []
58
61
 
59
62
  rubyforge_project: pony
60
- rubygems_version: 1.3.1
63
+ rubygems_version: 1.3.5
61
64
  signing_key:
62
- specification_version: 2
65
+ specification_version: 3
63
66
  summary: "Send email in one command: Pony.mail(:to => 'someone@example.com', :body => 'hello')"
64
67
  test_files: []
65
68