pony 0.4 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,79 @@
1
+ = Pony, the express way to send email in Ruby
2
+
3
+ == Overview
4
+
5
+ Ruby no longer has to be jealous of PHP's mail() function, which can send an email in a single command.
6
+
7
+ Pony.mail(:to => 'you@example.com', :from => 'me@example.com', :subject => 'hi', :body => 'Hello there.')
8
+ Pony.mail(:to => 'you@example.com', :from => 'me@example.com', :subject => 'hi', :body => '<h1>Hello there!</h1>', :content_type => 'text/html')
9
+ Pony.mail(:to => 'you@example.com', :cc => 'him@example.com', :from => 'me@example.com', :subject => 'hi', :body => 'Howdy')
10
+
11
+ Any option key may be omitted except for :to.
12
+
13
+
14
+ == Transport
15
+
16
+ Pony uses /usr/sbin/sendmail to send mail if it is available, otherwise it uses SMTP to localhost.
17
+
18
+ This can be over-ridden if you specify a via option
19
+
20
+ Pony.mail(:to => 'you@example.com', :via => :smtp) # sends via SMTP
21
+
22
+ Pony.mail(:to => 'you@example.com', :via => :sendmail) # sends via sendmail
23
+
24
+ You can also specify options for SMTP:
25
+
26
+ Pony.mail(:to => 'you@example.com', :via => :smtp, :smtp => {
27
+ :host => 'smtp.yourserver.com',
28
+ :port => '25',
29
+ :user => 'user',
30
+ :pass => 'pass',
31
+ :auth => :plain # :plain, :login, :cram_md5, no auth by default
32
+ :domain => "localhost.localdomain" # the HELO domain provided by the client to the server
33
+ }
34
+
35
+ == TLS/SSL
36
+
37
+ With smtp transport it also possible to use TLS/SSL:
38
+
39
+ Pony.mail(:to => 'you@example.com', :via => :smtp, :smtp => {
40
+ :host => 'smtp.gmail.com',
41
+ :port => '587',
42
+ :tls => true,
43
+ :user => 'user',
44
+ :pass => 'pass',
45
+ :auth => :plain # :plain, :login, :cram_md5, no auth by default
46
+ :domain => "localhost.localdomain" # the HELO domain provided by the client to the server
47
+ })
48
+
49
+ == Attachments
50
+
51
+ You can attach a file or two with the :attachments option:
52
+
53
+ Pony.mail(..., :attachments => {"foo.zip" => File.read("path/to/foo.zip"), "hello.txt" => "hello!"})
54
+
55
+ 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
+
57
+ == Meta
58
+
59
+ Maintained by Ben Prew
60
+
61
+ Written by Adam Wiggins
62
+
63
+ Patches contributed by: Mathieu Martin, Arun Thampi, Thomas Hurst, Stephen
64
+ Celis, Othmane Benkirane, Neil Mock, Hiroshi Saito, and Nickolas Means
65
+
66
+ Released under the MIT License: http://www.opensource.org/licenses/mit-license.php
67
+
68
+ http://github.com/benprew/pony
69
+
70
+ == Releases
71
+
72
+ 0.4.1
73
+ * Add :cc capability
74
+ * fix bug: resolve body not displaying when attachments sent
75
+
76
+ 0.4
77
+ * Implemented file attachments option
78
+ * use TLS if :tls => true
79
+
data/Rakefile CHANGED
@@ -29,29 +29,7 @@ require 'rake/clean'
29
29
  require 'rake/gempackagetask'
30
30
  require 'fileutils'
31
31
 
32
- version = "0.4"
33
- name = "pony"
34
-
35
- spec = Gem::Specification.new do |s|
36
- s.name = name
37
- s.version = version
38
- s.summary = "Send email in one command: Pony.mail(:to => 'someone@example.com', :body => 'hello')"
39
- s.description = "Send email in one command: Pony.mail(:to => 'someone@example.com', :body => 'hello')"
40
- s.author = "Adam Wiggins, maint: Ben Prew"
41
- s.email = "ben.prew@gmail.com"
42
- s.homepage = "http://github.com/benprew/pony"
43
- s.rubyforge_project = "pony"
44
-
45
- s.platform = Gem::Platform::RUBY
46
- s.has_rdoc = false
47
-
48
- s.files = %w(Rakefile) + Dir.glob("{lib,spec}/**/*")
49
-
50
- s.require_path = "lib"
51
- s.add_dependency( 'tmail', '~> 1.0' )
52
- end
53
-
54
- Rake::GemPackageTask.new(spec) do |p|
32
+ Rake::GemPackageTask.new(eval File.read('pony.gemspec')) do |p|
55
33
  p.need_tar = true if RUBY_PLATFORM !~ /mswin/
56
34
  end
57
35
 
@@ -1,5 +1,6 @@
1
1
  require 'rubygems'
2
2
  require 'net/smtp'
3
+ require 'mime/types'
3
4
  begin
4
5
  require 'smtp_tls'
5
6
  rescue LoadError
@@ -31,16 +32,28 @@ module Pony
31
32
  mail = TMail::Mail.new
32
33
  mail.content_type = options[:content_type] if options[:content_type]
33
34
  mail.to = options[:to]
35
+ mail.cc = options[:cc] || ''
34
36
  mail.from = options[:from] || 'pony@unknown'
35
37
  mail.subject = options[:subject]
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
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] || ""
44
57
  end
45
58
  mail
46
59
  end
@@ -66,7 +79,7 @@ module Pony
66
79
  if pipe
67
80
  pipe.write(tmail.to_s)
68
81
  else
69
- exec(sendmail_binary, *tmail.to)
82
+ exec(sendmail_binary, "-t")
70
83
  end
71
84
  end
72
85
  end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{pony}
5
+ s.version = "0.4.1"
6
+
7
+ s.description = "Send email in one command: Pony.mail(:to => 'someone@example.com', :body => 'hello')"
8
+ s.summary = s.description
9
+ s.authors = ["Adam Wiggins", "maint: Ben Prew"]
10
+ s.email = %q{ben.prew@gmail.com}
11
+ s.homepage = %q{http://github.com/benprew/pony}
12
+ s.rubyforge_project = "pony"
13
+
14
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
15
+ s.files = ["README.rdoc", "Rakefile", "pony.gemspec" ] + Dir.glob("{lib,spec}/**/*")
16
+ s.has_rdoc = false
17
+ s.rdoc_options = ["--inline-source", "--charset=UTF-8"]
18
+ s.require_paths = ["lib"]
19
+ s.rubygems_version = %q{1.3.1}
20
+ s.add_dependency( 'tmail', '~> 1.0' )
21
+ s.add_dependency('mime-types', '>= 1.16')
22
+ s.platform = Gem::Platform::RUBY
23
+ end
@@ -28,6 +28,10 @@ describe Pony do
28
28
  Pony.build_tmail(:to => 'joe@example.com').to.should == [ 'joe@example.com' ]
29
29
  end
30
30
 
31
+ it "cc" do
32
+ Pony.build_tmail(:cc => 'joe@example.com').cc.should == [ 'joe@example.com' ]
33
+ end
34
+
31
35
  it "from" do
32
36
  Pony.build_tmail(:from => 'joe@example.com').from.should == [ 'joe@example.com' ]
33
37
  end
@@ -50,14 +54,29 @@ describe Pony do
50
54
 
51
55
  it "attachments" do
52
56
  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
57
+ tmail.should have(2).parts
58
+ tmail.parts.first.to_s.should == "Content-Type: text/plain\n\n"
59
+ tmail.parts.last.to_s.should == <<-PART
60
+ Content-Type: text/plain
55
61
  Content-Transfer-Encoding: Base64
56
62
  Content-Disposition: attachment; filename=foo.txt
57
63
 
58
64
  Y29udGVudCBvZiBmb28udHh0
59
65
  PART
60
66
  end
67
+
68
+ it "suggests mime-type" do
69
+ tmail = Pony.build_tmail(:attachments => {"foo.pdf" => "content of foo.pdf"})
70
+ tmail.should have(2).parts
71
+ tmail.parts.first.to_s.should == "Content-Type: text/plain\n\n"
72
+ tmail.parts.last.to_s.should == <<-PART
73
+ Content-Type: application/pdf
74
+ Content-Transfer-Encoding: Base64
75
+ Content-Disposition: attachment; filename=foo.pdf
76
+
77
+ Y29udGVudCBvZiBmb28ucGRm
78
+ PART
79
+ end
61
80
  end
62
81
 
63
82
  describe "transport" do
metadata CHANGED
@@ -1,15 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pony
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.4"
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
- - "Adam Wiggins, maint: Ben Prew"
7
+ - Adam Wiggins
8
+ - "maint: Ben Prew"
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
12
 
12
- date: 2009-11-13 00:00:00 -08:00
13
+ date: 2009-11-18 00:00:00 -08:00
13
14
  default_executable:
14
15
  dependencies:
15
16
  - !ruby/object:Gem::Dependency
@@ -22,6 +23,16 @@ dependencies:
22
23
  - !ruby/object:Gem::Version
23
24
  version: "1.0"
24
25
  version:
26
+ - !ruby/object:Gem::Dependency
27
+ name: mime-types
28
+ type: :runtime
29
+ version_requirement:
30
+ version_requirements: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: "1.16"
35
+ version:
25
36
  description: "Send email in one command: Pony.mail(:to => 'someone@example.com', :body => 'hello')"
26
37
  email: ben.prew@gmail.com
27
38
  executables: []
@@ -31,18 +42,20 @@ extensions: []
31
42
  extra_rdoc_files: []
32
43
 
33
44
  files:
45
+ - README.rdoc
34
46
  - Rakefile
47
+ - pony.gemspec
35
48
  - lib/pony.rb
36
49
  - spec/base.rb
37
50
  - spec/pony_spec.rb
38
- - spec/pony_spec.rb.orig
39
51
  has_rdoc: true
40
52
  homepage: http://github.com/benprew/pony
41
53
  licenses: []
42
54
 
43
55
  post_install_message:
44
- rdoc_options: []
45
-
56
+ rdoc_options:
57
+ - --inline-source
58
+ - --charset=UTF-8
46
59
  require_paths:
47
60
  - lib
48
61
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -1,145 +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 "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