diff options
author | Hongli Lai (Phusion) <hongli@phusion.nl> | 2008-12-03 19:30:35 +0100 |
---|---|---|
committer | Hongli Lai (Phusion) <hongli@phusion.nl> | 2008-12-03 19:30:35 +0100 |
commit | ccb96f2297e8783165cba764e9b5d51e1a15ff87 (patch) | |
tree | 3229e6fdddc42054615514d843c555e341003033 /actionmailer/lib/action_mailer | |
parent | fb2325e35855d62abd2c76ce03feaa3ca7992e4f (diff) | |
parent | 761a633a9c0a45d76ef3ed10da97e3696c3ded79 (diff) | |
download | rails-ccb96f2297e8783165cba764e9b5d51e1a15ff87.tar.gz rails-ccb96f2297e8783165cba764e9b5d51e1a15ff87.tar.bz2 rails-ccb96f2297e8783165cba764e9b5d51e1a15ff87.zip |
Merge commit 'origin/master' into savepoints
Conflicts:
activerecord/lib/active_record/fixtures.rb
activerecord/test/cases/defaults_test.rb
Diffstat (limited to 'actionmailer/lib/action_mailer')
-rw-r--r-- | actionmailer/lib/action_mailer/base.rb | 61 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/helpers.rb | 2 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/mail_helper.rb | 2 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/part.rb | 10 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/part_container.rb | 6 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/quoting.rb | 2 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/test_case.rb | 2 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/test_helper.rb | 1 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/utils.rb | 1 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/vendor.rb | 14 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/vendor/text_format.rb | 10 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/vendor/tmail.rb | 17 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/version.rb | 2 |
13 files changed, 75 insertions, 55 deletions
diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index 043f56ba17..730dd2d7aa 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -1,9 +1,3 @@ -require 'action_mailer/adv_attr_accessor' -require 'action_mailer/part' -require 'action_mailer/part_container' -require 'action_mailer/utils' -require 'tmail/net' - module ActionMailer #:nodoc: # Action Mailer allows you to send email from your application using a mailer model and views. # @@ -245,7 +239,7 @@ module ActionMailer #:nodoc: # and appear last in the mime encoded message. You can also pick a different order from inside a method with # +implicit_parts_order+. class Base - include AdvAttrAccessor, PartContainer + include AdvAttrAccessor, PartContainer, Quoting, Utils if Object.const_defined?(:ActionController) include ActionController::UrlWriter include ActionController::Layout @@ -386,12 +380,15 @@ module ActionMailer #:nodoc: end def method_missing(method_symbol, *parameters) #:nodoc: - match = matches_dynamic_method?(method_symbol) - case match[1] - when 'create' then new(match[2], *parameters).mail - when 'deliver' then new(match[2], *parameters).deliver! - when 'new' then nil - else super + if match = matches_dynamic_method?(method_symbol) + case match[1] + when 'create' then new(match[2], *parameters).mail + when 'deliver' then new(match[2], *parameters).deliver! + when 'new' then nil + else super + end + else + super end end @@ -423,12 +420,6 @@ module ActionMailer #:nodoc: new.deliver!(mail) end - def register_template_extension(extension) - ActiveSupport::Deprecation.warn( - "ActionMailer::Base.register_template_extension has been deprecated." + - "Use ActionView::Base.register_template_extension instead", caller) - end - def template_root self.view_paths && self.view_paths.first end @@ -440,7 +431,7 @@ module ActionMailer #:nodoc: private def matches_dynamic_method?(method_name) #:nodoc: method_name = method_name.to_s - /(create|deliver)_([_a-z]\w*)/.match(method_name) || /^(new)$/.match(method_name) + /^(create|deliver)_([_a-z]\w*)/.match(method_name) || /^(new)$/.match(method_name) end end @@ -546,7 +537,12 @@ module ActionMailer #:nodoc: end def render_message(method_name, body) + if method_name.respond_to?(:content_type) + @current_template_content_type = method_name.content_type + end render :file => method_name, :body => body + ensure + @current_template_content_type = nil end def render(opts) @@ -565,7 +561,11 @@ module ActionMailer #:nodoc: end def default_template_format - :html + if @current_template_content_type + Mime::Type.lookup(@current_template_content_type).to_sym + else + :html + end end def candidate_for_layout?(options) @@ -585,7 +585,9 @@ module ActionMailer #:nodoc: end def initialize_template_class(assigns) - ActionView::Base.new(view_paths, assigns, self) + template = ActionView::Base.new(view_paths, assigns, self) + template.template_format = default_template_format + template end def sort_parts(parts, order = []) @@ -634,11 +636,11 @@ module ActionMailer #:nodoc: if @parts.empty? m.set_content_type(real_content_type, nil, ctype_attrs) - m.body = Utils.normalize_new_lines(body) + m.body = normalize_new_lines(body) else if String === body part = TMail::Mail.new - part.body = Utils.normalize_new_lines(body) + part.body = normalize_new_lines(body) part.set_content_type(real_content_type, nil, ctype_attrs) part.set_content_disposition "inline" m.parts << part @@ -663,8 +665,10 @@ module ActionMailer #:nodoc: mail.ready_to_send sender = mail['return-path'] || mail.from - Net::SMTP.start(smtp_settings[:address], smtp_settings[:port], smtp_settings[:domain], - smtp_settings[:user_name], smtp_settings[:password], smtp_settings[:authentication]) do |smtp| + smtp = Net::SMTP.new(smtp_settings[:address], smtp_settings[:port]) + smtp.enable_starttls_auto if smtp.respond_to?(:enable_starttls_auto) + smtp.start(smtp_settings[:domain], smtp_settings[:user_name], smtp_settings[:password], + smtp_settings[:authentication]) do |smtp| smtp.sendmail(mail.encoded, sender, destinations) end end @@ -682,4 +686,9 @@ module ActionMailer #:nodoc: deliveries << mail end end + + Base.class_eval do + include Helpers + helper MailHelper + end end diff --git a/actionmailer/lib/action_mailer/helpers.rb b/actionmailer/lib/action_mailer/helpers.rb index 5f6dcd77cd..31f7de8d60 100644 --- a/actionmailer/lib/action_mailer/helpers.rb +++ b/actionmailer/lib/action_mailer/helpers.rb @@ -1,3 +1,5 @@ +require 'active_support/dependencies' + module ActionMailer module Helpers #:nodoc: def self.included(base) #:nodoc: diff --git a/actionmailer/lib/action_mailer/mail_helper.rb b/actionmailer/lib/action_mailer/mail_helper.rb index 11fd7d77e0..351b966abe 100644 --- a/actionmailer/lib/action_mailer/mail_helper.rb +++ b/actionmailer/lib/action_mailer/mail_helper.rb @@ -1,5 +1,3 @@ -require 'text/format' - module MailHelper # Uses Text::Format to take the text and format it, indented two spaces for # each line, and wrapped at 72 columns. diff --git a/actionmailer/lib/action_mailer/part.rb b/actionmailer/lib/action_mailer/part.rb index 2dabf15f08..977c0b2b5c 100644 --- a/actionmailer/lib/action_mailer/part.rb +++ b/actionmailer/lib/action_mailer/part.rb @@ -1,15 +1,10 @@ -require 'action_mailer/adv_attr_accessor' -require 'action_mailer/part_container' -require 'action_mailer/utils' - module ActionMailer # Represents a subpart of an email message. It shares many similar # attributes of ActionMailer::Base. Although you can create parts manually # and add them to the +parts+ list of the mailer, it is easier # to use the helper methods in ActionMailer::PartContainer. class Part - include ActionMailer::AdvAttrAccessor - include ActionMailer::PartContainer + include AdvAttrAccessor, PartContainer, Utils # Represents the body of the part, as a string. This should not be a # Hash (like ActionMailer::Base), but if you want a template to be rendered @@ -64,7 +59,7 @@ module ActionMailer when "base64" then part.body = TMail::Base64.folding_encode(body) when "quoted-printable" - part.body = [Utils.normalize_new_lines(body)].pack("M*") + part.body = [normalize_new_lines(body)].pack("M*") else part.body = body end @@ -102,7 +97,6 @@ module ActionMailer end private - def squish(values={}) values.delete_if { |k,v| v.nil? } end diff --git a/actionmailer/lib/action_mailer/part_container.rb b/actionmailer/lib/action_mailer/part_container.rb index 3e3d6b9d4f..abfd8f8426 100644 --- a/actionmailer/lib/action_mailer/part_container.rb +++ b/actionmailer/lib/action_mailer/part_container.rb @@ -41,7 +41,11 @@ module ActionMailer private def parse_content_type(defaults=nil) - return [defaults && defaults.content_type, {}] if content_type.blank? + if content_type.blank? + return defaults ? + [ defaults.content_type, { 'charset' => defaults.charset } ] : + [ nil, {} ] + end ctype, *attrs = content_type.split(/;\s*/) attrs = attrs.inject({}) { |h,s| k,v = s.split(/=/, 2); h[k] = v; h } [ctype, {"charset" => charset || defaults && defaults.charset}.merge(attrs)] diff --git a/actionmailer/lib/action_mailer/quoting.rb b/actionmailer/lib/action_mailer/quoting.rb index a2f2c70799..94fa042002 100644 --- a/actionmailer/lib/action_mailer/quoting.rb +++ b/actionmailer/lib/action_mailer/quoting.rb @@ -12,7 +12,7 @@ module ActionMailer # account multi-byte characters (if executing with $KCODE="u", for instance) def quoted_printable_encode(character) result = "" - character.each_byte { |b| result << "=%02x" % b } + character.each_byte { |b| result << "=%02X" % b } result end diff --git a/actionmailer/lib/action_mailer/test_case.rb b/actionmailer/lib/action_mailer/test_case.rb index d474afe3a2..8035db6f03 100644 --- a/actionmailer/lib/action_mailer/test_case.rb +++ b/actionmailer/lib/action_mailer/test_case.rb @@ -10,7 +10,7 @@ module ActionMailer end class TestCase < ActiveSupport::TestCase - include ActionMailer::Quoting + include Quoting, TestHelper setup :initialize_test_deliveries setup :set_expected_mail diff --git a/actionmailer/lib/action_mailer/test_helper.rb b/actionmailer/lib/action_mailer/test_helper.rb index 3a1612442f..f234c0248c 100644 --- a/actionmailer/lib/action_mailer/test_helper.rb +++ b/actionmailer/lib/action_mailer/test_helper.rb @@ -58,6 +58,7 @@ module ActionMailer end end +# TODO: Deprecate this module Test module Unit class TestCase diff --git a/actionmailer/lib/action_mailer/utils.rb b/actionmailer/lib/action_mailer/utils.rb index 552f695a92..26d2e60aaf 100644 --- a/actionmailer/lib/action_mailer/utils.rb +++ b/actionmailer/lib/action_mailer/utils.rb @@ -3,6 +3,5 @@ module ActionMailer def normalize_new_lines(text) text.to_s.gsub(/\r\n?/, "\n") end - module_function :normalize_new_lines end end diff --git a/actionmailer/lib/action_mailer/vendor.rb b/actionmailer/lib/action_mailer/vendor.rb deleted file mode 100644 index 7a20e9bd6e..0000000000 --- a/actionmailer/lib/action_mailer/vendor.rb +++ /dev/null @@ -1,14 +0,0 @@ -# Prefer gems to the bundled libs. -require 'rubygems' - -begin - gem 'tmail', '~> 1.2.3' -rescue Gem::LoadError - $:.unshift "#{File.dirname(__FILE__)}/vendor/tmail-1.2.3" -end - -begin - gem 'text-format', '>= 0.6.3' -rescue Gem::LoadError - $:.unshift "#{File.dirname(__FILE__)}/vendor/text-format-0.6.3" -end diff --git a/actionmailer/lib/action_mailer/vendor/text_format.rb b/actionmailer/lib/action_mailer/vendor/text_format.rb new file mode 100644 index 0000000000..c6c8c394d0 --- /dev/null +++ b/actionmailer/lib/action_mailer/vendor/text_format.rb @@ -0,0 +1,10 @@ +# Prefer gems to the bundled libs. +require 'rubygems' + +begin + gem 'text-format', '>= 0.6.3' +rescue Gem::LoadError + $:.unshift "#{File.dirname(__FILE__)}/text-format-0.6.3" +end + +require 'text/format' diff --git a/actionmailer/lib/action_mailer/vendor/tmail.rb b/actionmailer/lib/action_mailer/vendor/tmail.rb new file mode 100644 index 0000000000..51d36cdd0d --- /dev/null +++ b/actionmailer/lib/action_mailer/vendor/tmail.rb @@ -0,0 +1,17 @@ +# Prefer gems to the bundled libs. +require 'rubygems' + +begin + gem 'tmail', '~> 1.2.3' +rescue Gem::LoadError + $:.unshift "#{File.dirname(__FILE__)}/tmail-1.2.3" +end + +module TMail +end + +require 'tmail' + +silence_warnings do + TMail::Encoder.const_set("MAX_LINE_LEN", 200) +end diff --git a/actionmailer/lib/action_mailer/version.rb b/actionmailer/lib/action_mailer/version.rb index 9728d1b4db..9cd7a14b73 100644 --- a/actionmailer/lib/action_mailer/version.rb +++ b/actionmailer/lib/action_mailer/version.rb @@ -1,7 +1,7 @@ module ActionMailer module VERSION #:nodoc: MAJOR = 2 - MINOR = 2 + MINOR = 3 TINY = 0 STRING = [MAJOR, MINOR, TINY].join('.') |