padrino-mailer 0.8.1 → 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -40,10 +40,11 @@ end
40
40
 
41
41
  begin
42
42
  require 'rcov/rcovtask'
43
- Rcov::RcovTask.new do |test|
44
- test.libs << 'test'
45
- test.pattern = 'test/**/test_*.rb'
46
- test.verbose = true
43
+ Rcov::RcovTask.new do |rcov|
44
+ rcov.libs << 'test'
45
+ rcov.pattern = 'test/**/test_*.rb'
46
+ rcov.verbose = true
47
+ rcov.rcov_opts << ['--exclude /Gems/1.8/gems/,padrino-core,padrino-cache,padrino-gen,padrino-helpers,padrino-admin']
47
48
  end
48
49
  rescue LoadError
49
50
  task :rcov do
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.8.1
1
+ 0.8.2
@@ -21,7 +21,7 @@ module Padrino
21
21
  # Returns the available mail fields when composing a message
22
22
  #
23
23
  def self.mail_fields
24
- [:to, :from, :subject, :type, :charset, :via, :attachments]
24
+ [:to, :cc, :bcc, :reply_to, :from, :subject, :type, :charset, :via, :attachments]
25
25
  end
26
26
 
27
27
  attr_accessor :mail_attributes
@@ -74,7 +74,7 @@ module Padrino
74
74
  # Returns true if a mail exists with the name being delivered
75
75
  #
76
76
  def self.respond_to?(method_sym, include_private = false)
77
- method_sym.to_s =~ /deliver_(.*)/ ? self.method_defined?($1) : super
77
+ method_sym.to_s =~ /deliver_(.*)/ ? self.method_defined?($1) : super(method_sym, include_private)
78
78
  end
79
79
 
80
80
  ##
@@ -82,7 +82,7 @@ module Padrino
82
82
  # being called i.e #deliver_birthday_message(22) invokes #birthday_message(22) to setup mail object
83
83
  #
84
84
  def self.method_missing(method_sym, *arguments, &block)
85
- method_sym.to_s =~ /deliver_(.*)/ ? self.deliver($1, *arguments) : super
85
+ method_sym.to_s =~ /deliver_(.*)/ ? self.deliver($1, *arguments) : super(method_sym, *arguments, &block)
86
86
  end
87
87
  end # Base
88
88
  end # Mailer
@@ -28,20 +28,36 @@ module Padrino
28
28
  end
29
29
 
30
30
  def build_tmail(options)
31
- mail = TMail::Mail.new
32
- mail.to = options[:to]
33
- mail.from = options[:from] || 'padrino@unknown'
34
- mail.subject = options[:subject]
35
- mail.body = options[:body] || ""
36
- mail.set_content_type 'text', options[:type] || 'plain', {'charset'=> options[:charset] || 'utf-8'}
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
31
+ logger.error options.inspect
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] || 'padrino@unknown'
37
+ mail.reply_to = options[:reply_to]
38
+ mail.subject = options[:subject]
39
+
40
+ if options[:attachments]
41
+ # If message has attachment, then body must be sent as a message part
42
+ # or it will not be interpreted correctly by client.
43
+ body = TMail::Mail.new
44
+ body.body = options[:body] || ""
45
+ body.content_type = options[:content_type] || "text/plain"
46
+ mail.parts.push body
47
+ (options[:attachments] || []).each do |name, body|
48
+ attachment = TMail::Mail.new
49
+ attachment.transfer_encoding = "base64"
50
+ attachment.body = Base64.encode64(body)
51
+ content_type = MIME::Types.type_for(name).to_s
52
+ attachment.content_type = content_type unless content_type == ""
53
+ attachment.set_content_disposition "attachment", "filename" => name
54
+ mail.parts.push attachment
55
+ end
56
+ else
57
+ mail.content_type = options[:content_type] || "text/plain"
58
+ mail.body = options[:body] || ""
44
59
  end
60
+ mail.charset = options[:charset] || "UTF-8" # charset must be set after setting content_type
45
61
  mail
46
62
  end
47
63
 
@@ -62,7 +78,7 @@ module Padrino
62
78
  end
63
79
 
64
80
  def transport_via_sendmail(tmail, options={})
65
- logger.debug "Sending email via sendmail: #{tmail}"
81
+ logger.debug "Sending email via sendmail:\n#{tmail}" if Kernel.respond_to?(:logger)
66
82
  IO.popen('-', 'w+') do |pipe|
67
83
  if pipe
68
84
  pipe.write(tmail.to_s)
@@ -73,7 +89,7 @@ module Padrino
73
89
  end
74
90
 
75
91
  def transport_via_smtp(tmail, options={:smtp => {}})
76
- logger.debug "Sending email via smtp: #{tmail}"
92
+ logger.debug "Sending email via smtp:\n#{tmail}" if Kernel.respond_to?(:logger)
77
93
  default_options = {:smtp => { :host => 'localhost', :port => '25', :domain => 'localhost.localdomain' }}
78
94
  o = default_options[:smtp].merge(options[:smtp])
79
95
  smtp = Net::SMTP.new(o[:host], o[:port])
@@ -36,18 +36,27 @@ module Padrino
36
36
  end
37
37
 
38
38
  protected
39
+ ##
39
40
  # Returns the delivery method to use for this mail object
41
+ #
42
+ # ==== Examples
43
+ #
40
44
  # @mo.delivery_method => :smtp || :sendmail
45
+ #
41
46
  def delivery_method
42
47
  @mail_attributes[:via] || (@smtp_settings.present? ? :smtp : :sendmail)
43
48
  end
44
49
 
50
+ ##
45
51
  # Returns true if the mail object is going to be delivered using smtp
52
+ #
46
53
  def using_smtp?
47
54
  delivery_method.to_s =~ /smtp/
48
55
  end
49
56
 
57
+ ##
50
58
  # Performs the actual email sending
59
+ #
51
60
  def send_mail(delivery_attributes)
52
61
  Delivery.mail(delivery_attributes) && true
53
62
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{padrino-mailer}
8
- s.version = "0.8.1"
8
+ s.version = "0.8.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Padrino Team", "Nathan Esquenazi", "Davide D'Agostino", "Arthur Chiu"]
12
- s.date = %q{2010-02-14}
12
+ s.date = %q{2010-02-17}
13
13
  s.description = %q{Mailer system for padrino allowing easy delivery of application emails}
14
14
  s.email = %q{padrinorb@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -49,7 +49,7 @@ Gem::Specification.new do |s|
49
49
 
50
50
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
51
51
  s.add_runtime_dependency(%q<sinatra>, [">= 0.9.2"])
52
- s.add_runtime_dependency(%q<padrino-core>, ["= 0.8.1"])
52
+ s.add_runtime_dependency(%q<padrino-core>, ["= 0.8.2"])
53
53
  s.add_runtime_dependency(%q<tilt>, [">= 0.2"])
54
54
  s.add_runtime_dependency(%q<tmail>, [">= 1.2"])
55
55
  s.add_development_dependency(%q<shoulda>, [">= 2.10.3"])
@@ -59,7 +59,7 @@ Gem::Specification.new do |s|
59
59
  s.add_development_dependency(%q<webrat>, [">= 0.5.1"])
60
60
  else
61
61
  s.add_dependency(%q<sinatra>, [">= 0.9.2"])
62
- s.add_dependency(%q<padrino-core>, ["= 0.8.1"])
62
+ s.add_dependency(%q<padrino-core>, ["= 0.8.2"])
63
63
  s.add_dependency(%q<tilt>, [">= 0.2"])
64
64
  s.add_dependency(%q<tmail>, [">= 1.2"])
65
65
  s.add_dependency(%q<shoulda>, [">= 2.10.3"])
@@ -70,7 +70,7 @@ Gem::Specification.new do |s|
70
70
  end
71
71
  else
72
72
  s.add_dependency(%q<sinatra>, [">= 0.9.2"])
73
- s.add_dependency(%q<padrino-core>, ["= 0.8.1"])
73
+ s.add_dependency(%q<padrino-core>, ["= 0.8.2"])
74
74
  s.add_dependency(%q<tilt>, [">= 0.2"])
75
75
  s.add_dependency(%q<tmail>, [">= 1.2"])
76
76
  s.add_dependency(%q<shoulda>, [">= 2.10.3"])
@@ -2,20 +2,20 @@ require File.dirname(__FILE__) + '/helper'
2
2
 
3
3
  class TestMailObject < Test::Unit::TestCase
4
4
  include Padrino::Mailer
5
-
5
+
6
6
  context 'for #deliver method' do
7
7
  should "send mail with attributes default to sendmail no smtp" do
8
- mail_object = Padrino::Mailer::MailObject.new({:to => "test@john.com", :from => "sender@sent.com", :body => "Hello"}, {})
8
+ mail_object = Padrino::Mailer::MailObject.new(:to => "test@john.com", :from => "sender@sent.com", :body => "Hello")
9
9
  Delivery.expects(:mail).with(:to => "test@john.com", :from => "sender@sent.com", :body => "Hello", :via => :sendmail)
10
10
  mail_object.deliver
11
11
  end
12
-
12
+
13
13
  should "send mail with attributes default to smtp if set" do
14
14
  mail_object = Padrino::Mailer::MailObject.new({:to => "test@john.com", :body => "Hello"}, { :host => 'smtp.gmail.com' })
15
15
  Delivery.expects(:mail).with(:to => "test@john.com", :body => "Hello", :via => :smtp, :smtp => { :host => 'smtp.gmail.com' })
16
16
  mail_object.deliver
17
17
  end
18
-
18
+
19
19
  should "send mail with attributes use sendmail if explicit" do
20
20
  mail_object = Padrino::Mailer::MailObject.new({:to => "test@john.com", :via => :sendmail }, { :host => 'smtp.gmail.com' })
21
21
  Delivery.expects(:mail).with(:to => "test@john.com", :via => :sendmail)
@@ -3,7 +3,10 @@ require File.dirname(__FILE__) + '/helper'
3
3
  class DemoMailer < Padrino::Mailer::Base
4
4
  def sample_mail
5
5
  from 'test@default.com'
6
+ cc 'foo@bar.com'
7
+ bcc 'bar@foo.com'
6
8
  to 'test@test.com'
9
+ reply_to 'foobar@foobar.com'
7
10
  body "Hello world!"
8
11
  via :sendmail
9
12
  end
@@ -17,7 +20,7 @@ end
17
20
 
18
21
  class TestMailerBase < Test::Unit::TestCase
19
22
  include Padrino::Mailer
20
-
23
+
21
24
  context 'for defining email attributes' do
22
25
  DemoMailer.mail_fields.each do |field|
23
26
  should "support setting '#{field}' attribute" do
@@ -26,27 +29,28 @@ class TestMailerBase < Test::Unit::TestCase
26
29
  assert_equal({ field => "some_value" }, demo_mailer.mail_attributes)
27
30
  end
28
31
  end
29
-
32
+
30
33
  should "allow defining text body" do
31
34
  demo_mailer = DemoMailer.new(:sample_mail)
32
35
  demo_mailer.body("Hello world!")
33
36
  assert_equal({ :body => "Hello world!" }, demo_mailer.mail_attributes)
34
37
  end
35
38
  end
36
-
39
+
37
40
  context 'for retrieving template path' do
38
41
  should "return correct path" do
39
42
  demo_mailer = DemoMailer.new(:sample_mail)
40
43
  assert_match %r{demo_mailer/sample_mail.erb}, demo_mailer.template_path
41
44
  end
42
45
  end
43
-
46
+
44
47
  context 'for #deliver class method' do
45
48
  should "perform the email delivery for sendmail" do
46
- Delivery.expects(:mail).with(:from => 'test@default.com', :to => 'test@test.com', :body => "Hello world!", :via => :sendmail)
49
+ Delivery.expects(:mail).with(:from => 'test@default.com', :to => 'test@test.com', :body => "Hello world!", :via => :sendmail,
50
+ :cc => 'foo@bar.com', :bcc => 'bar@foo.com', :reply_to => 'foobar@foobar.com')
47
51
  DemoMailer.deliver(:sample_mail)
48
52
  end
49
-
53
+
50
54
  should "perform the email delivery for smtp" do
51
55
  DemoMailer.smtp_settings = { :host => 'smtp.arcadic.com' }
52
56
  Delivery.expects(:mail).with(:from => 'test@default.com', :to => 'test@test.com',
@@ -54,25 +58,25 @@ class TestMailerBase < Test::Unit::TestCase
54
58
  DemoMailer.deliver(:sample_mail_smtp)
55
59
  end
56
60
  end
57
-
61
+
58
62
  context 'for #respond_to? class method' do
59
63
  should "respond as true for any delivery method calls for mails that exist" do
60
64
  assert DemoMailer.respond_to?(:deliver_sample_mail)
61
65
  end
62
-
66
+
63
67
  should "respond as false for any delivery method calls for mails that don't exist" do
64
68
  assert_equal false, DemoMailer.respond_to?(:deliver_faker_mail)
65
69
  end
66
-
70
+
67
71
  should "respond as true for any non-delivery methods that exist" do
68
72
  assert DemoMailer.respond_to?(:inspect)
69
73
  end
70
-
74
+
71
75
  should "respond as false for any non-delivery methods that don't exist" do
72
76
  assert_equal false, DemoMailer.respond_to?(:fake_method)
73
77
  end
74
78
  end
75
-
79
+
76
80
  context 'for #method_missing dynamic delivery' do
77
81
  should 'invoke deliver method with appropriate parameters' do
78
82
  DemoMailer.expects(:deliver).with("example_name", "test", 5)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: padrino-mailer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Padrino Team
@@ -12,7 +12,7 @@ autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
14
 
15
- date: 2010-02-14 00:00:00 +01:00
15
+ date: 2010-02-17 00:00:00 +01:00
16
16
  default_executable:
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
@@ -33,7 +33,7 @@ dependencies:
33
33
  requirements:
34
34
  - - "="
35
35
  - !ruby/object:Gem::Version
36
- version: 0.8.1
36
+ version: 0.8.2
37
37
  version:
38
38
  - !ruby/object:Gem::Dependency
39
39
  name: tilt