aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailer
diff options
context:
space:
mode:
authorJamis Buck <jamis@37signals.com>2005-07-31 08:26:32 +0000
committerJamis Buck <jamis@37signals.com>2005-07-31 08:26:32 +0000
commiteda17194700d4cdc0d863ae8c49a8e3dbbf1615c (patch)
tree25c9c585b49a30b6b2c7343a454f8d745bc616a5 /actionmailer
parentda874a4af817ebeb9421934b2a4e4e0032b1234d (diff)
downloadrails-eda17194700d4cdc0d863ae8c49a8e3dbbf1615c.tar.gz
rails-eda17194700d4cdc0d863ae8c49a8e3dbbf1615c.tar.bz2
rails-eda17194700d4cdc0d863ae8c49a8e3dbbf1615c.zip
ActionMailer::Base.deliver(email) had been accidentally removed, but was documented in the Rails book #1849
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1958 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionmailer')
-rw-r--r--actionmailer/CHANGELOG2
-rw-r--r--actionmailer/lib/action_mailer/base.rb60
-rwxr-xr-xactionmailer/test/mail_service_test.rb6
3 files changed, 43 insertions, 25 deletions
diff --git a/actionmailer/CHANGELOG b/actionmailer/CHANGELOG
index 4643de02b1..7ece8703f2 100644
--- a/actionmailer/CHANGELOG
+++ b/actionmailer/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* ActionMailer::Base.deliver(email) had been accidentally removed, but was documented in the Rails book #1849
+
* Fix problem with sendmail delivery where headers should be delimited by \n characters instead of \r\n, which confuses some mail readers #1742 [Kent Sibilev]
diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb
index f09255b229..b76be81d5b 100644
--- a/actionmailer/lib/action_mailer/base.rb
+++ b/actionmailer/lib/action_mailer/base.rb
@@ -160,6 +160,34 @@ module ActionMailer #:nodoc:
attr_reader :mail
+ class << self
+ def method_missing(method_symbol, *parameters)#:nodoc:
+ case method_symbol.id2name
+ when /^create_([_a-z]\w*)/ then new($1, *parameters).mail
+ when /^deliver_([_a-z]\w*)/ then new($1, *parameters).deliver!
+ when "new" then nil
+ else super
+ end
+ end
+
+ def receive(raw_email) #:nodoc:
+ logger.info "Received mail:\n #{raw_email}" unless logger.nil?
+ mail = TMail::Mail.parse(raw_email)
+ mail.base64_decode
+ new.receive(mail)
+ end
+
+ # Deliver the given mail object directly. This can be used to deliver
+ # a preconstructed mail object, like:
+ #
+ # email = MyMailer.create_some_mail(parameters)
+ # email.set_some_obscure_header "frobnicate"
+ # MyMailer.deliver(email)
+ def deliver(mail)
+ new.deliver!(mail)
+ end
+ end
+
# Instantiate a new mailer object. If +method_name+ is not +nil+, the mailer
# will be initialized according to the named method. If not, the mailer will
# remain uninitialized (useful when you only need to invoke the "receive"
@@ -223,19 +251,20 @@ module ActionMailer #:nodoc:
@mail = create_mail
end
- # Delivers the cached TMail::Mail object. If no TMail::Mail object has been
- # created (via the #create! method, for instance) this will fail.
- def deliver! #:nodoc:
- raise "no mail object available for delivery!" unless @mail
+ # Delivers a TMail::Mail object. By default, it delivers the cached mail
+ # object (from the #create! method). If no cached mail object exists, and
+ # no alternate has been given as the parameter, this will fail.
+ def deliver!(mail = @mail) #:nodoc:
+ raise "no mail object available for delivery!" unless mail
logger.info "Sent mail:\n #{mail.encoded}" unless logger.nil?
begin
- send("perform_delivery_#{delivery_method}", @mail) if perform_deliveries
+ send("perform_delivery_#{delivery_method}", mail) if perform_deliveries
rescue Object => e
raise e if raise_delivery_errors
end
- return @mail
+ return mail
end
private
@@ -334,24 +363,5 @@ module ActionMailer #:nodoc:
def perform_delivery_test(mail)
deliveries << mail
end
-
- class << self
- def method_missing(method_symbol, *parameters)#:nodoc:
- case method_symbol.id2name
- when /^create_([_a-z]\w*)/ then new($1, *parameters).mail
- when /^deliver_([_a-z]\w*)/ then new($1, *parameters).deliver!
- when "new" then nil
- else super
- end
- end
-
- def receive(raw_email)
- logger.info "Received mail:\n #{raw_email}" unless logger.nil?
- mail = TMail::Mail.parse(raw_email)
- mail.base64_decode
- new.receive(mail)
- end
-
- end
end
end
diff --git a/actionmailer/test/mail_service_test.rb b/actionmailer/test/mail_service_test.rb
index cd8c9539ca..1cabb06c53 100755
--- a/actionmailer/test/mail_service_test.rb
+++ b/actionmailer/test/mail_service_test.rb
@@ -668,5 +668,11 @@ EOF
assert_match(/:/, mail.cc_addrs.to_s)
assert_match(/:/, mail.bcc_addrs.to_s)
end
+
+ def test_deliver_with_mail_object
+ mail = TestMailer::create_headers_with_nonalpha_chars(@recipient)
+ assert_nothing_raised { TestMailer.deliver(mail) }
+ assert_equal 1, TestMailer.deliveries.length
+ end
end