From 7e0aa35c20f06fd9ef245155e30e81cfb38bad05 Mon Sep 17 00:00:00 2001 From: Michael Koziarski Date: Sat, 28 Nov 2009 13:34:05 +1300 Subject: avoid generating invalid SMTP commands in ruby pre 1.9 Signed-off-by: Michael Koziarski Conflicts: actionmailer/lib/action_mailer/base.rb --- actionmailer/lib/action_mailer/delivery_method/smtp.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionmailer/lib') diff --git a/actionmailer/lib/action_mailer/delivery_method/smtp.rb b/actionmailer/lib/action_mailer/delivery_method/smtp.rb index 86b0ae8329..95c117c9e0 100644 --- a/actionmailer/lib/action_mailer/delivery_method/smtp.rb +++ b/actionmailer/lib/action_mailer/delivery_method/smtp.rb @@ -16,7 +16,7 @@ module ActionMailer def perform_delivery(mail) destinations = mail.destinations mail.ready_to_send - sender = (mail['return-path'] && mail['return-path'].spec) || mail['from'] + sender = (mail['return-path'] && mail['return-path'].spec) || Array(mail.from).first smtp = Net::SMTP.new(settings[:address], settings[:port]) smtp.enable_starttls_auto if settings[:enable_starttls_auto] && smtp.respond_to?(:enable_starttls_auto) -- cgit v1.2.3 From 5d9af09563897bd36b4baaf9bb366cf100be90a9 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 1 Dec 2009 23:01:21 -0600 Subject: Silence known internal AM deprecation calls --- actionmailer/lib/action_mailer/base.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'actionmailer/lib') diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index bef9bb8e79..7b952c462f 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -515,11 +515,15 @@ module ActionMailer #:nodoc: @headers ||= {} @sent_on ||= Time.now - super # Run deprecation hooks + ActiveSupport::Deprecation.silence do + super # Run deprecation hooks + end end def create_parts - super # Run deprecation hooks + ActiveSupport::Deprecation.silence do + super # Run deprecation hooks + end if String === response_body @parts.unshift Part.new( @@ -592,7 +596,7 @@ module ActionMailer #:nodoc: headers.each { |k, v| m[k] = v } real_content_type, ctype_attrs = parse_content_type - + if @parts.empty? m.set_content_type(real_content_type, nil, ctype_attrs) m.body = normalize_new_lines(body) -- cgit v1.2.3 From c1304098cca8a9247a9ad1461a1a343354650843 Mon Sep 17 00:00:00 2001 From: Carlhuda Date: Wed, 2 Dec 2009 20:01:01 -0800 Subject: Reorganize autoloads: * A new module (ActiveSupport::Autoload) is provide that extends autoloading with new behavior. * All autoloads in modules that have extended ActiveSupport::Autoload will be eagerly required in threadsafe environments * Autoloads can optionally leave off the path if the path is the same as full_constant_name.underscore * It is possible to specify that a group of autoloads live under an additional path. For instance, all of ActionDispatch's middlewares are ActionDispatch::MiddlewareName, but they live under "action_dispatch/middlewares/middleware_name" * It is possible to specify that a group of autoloads are all found at the same path. For instance, a number of exceptions might all be declared there. * One consequence of this is that testing-related constants are not autoloaded. To get the testing helpers for a given component, require "component_name/test_case". For instance, "action_controller/test_case". * test_help.rb, which is automatically required by a Rails application's test helper, requires the test_case.rb for all active components, so this change will not be disruptive in existing or new applications. --- actionmailer/lib/action_mailer.rb | 34 ++++++++++++---------- actionmailer/lib/action_mailer/base.rb | 2 +- .../lib/action_mailer/delivery_method/file.rb | 2 +- actionmailer/lib/action_mailer/mail_helper.rb | 30 ++++++++++--------- 4 files changed, 36 insertions(+), 32 deletions(-) (limited to 'actionmailer/lib') diff --git a/actionmailer/lib/action_mailer.rb b/actionmailer/lib/action_mailer.rb index 23f04a11ba..12e781b6c3 100644 --- a/actionmailer/lib/action_mailer.rb +++ b/actionmailer/lib/action_mailer.rb @@ -25,32 +25,34 @@ actionpack_path = "#{File.dirname(__FILE__)}/../../actionpack/lib" $:.unshift(actionpack_path) if File.directory?(actionpack_path) require 'action_controller' require 'action_view' +require 'active_support/autoload' module ActionMailer - def self.load_all! - [Base, Part, ::Text::Format, ::Net::SMTP] - end - - autoload :AdvAttrAccessor, 'action_mailer/adv_attr_accessor' - autoload :DeprecatedBody, 'action_mailer/deprecated_body' - autoload :Base, 'action_mailer/base' - autoload :DeliveryMethod, 'action_mailer/delivery_method' - autoload :Part, 'action_mailer/part' - autoload :PartContainer, 'action_mailer/part_container' - autoload :Quoting, 'action_mailer/quoting' - autoload :TestCase, 'action_mailer/test_case' - autoload :TestHelper, 'action_mailer/test_helper' - autoload :Utils, 'action_mailer/utils' + extend ::ActiveSupport::Autoload + + autoload :AdvAttrAccessor + autoload :DeprecatedBody + autoload :Base + autoload :DeliveryMethod + autoload :MailHelper + autoload :Part + autoload :PartContainer + autoload :Quoting + autoload :TestHelper + autoload :Utils end module Text + extend ActiveSupport::Autoload + autoload :Format, 'action_mailer/vendor/text_format' end module Net - autoload :SMTP, 'net/smtp' + extend ActiveSupport::Autoload + + autoload :SMTP end -autoload :MailHelper, 'action_mailer/mail_helper' require 'action_mailer/vendor/tmail' diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index 7b952c462f..b5239ac0cd 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -258,7 +258,7 @@ module ActionMailer #:nodoc: include AbstractController::Layouts include AbstractController::Helpers - helper MailHelper + helper ActionMailer::MailHelper if Object.const_defined?(:ActionController) include ActionController::UrlWriter diff --git a/actionmailer/lib/action_mailer/delivery_method/file.rb b/actionmailer/lib/action_mailer/delivery_method/file.rb index 587ae37ffa..6c8cdf4450 100644 --- a/actionmailer/lib/action_mailer/delivery_method/file.rb +++ b/actionmailer/lib/action_mailer/delivery_method/file.rb @@ -6,7 +6,7 @@ module ActionMailer # A delivery method implementation which writes all mails to a file. class File < Method self.settings = { - :location => defined?(Rails) ? "#{Rails.root}/tmp/mails" : "#{Dir.tmpdir}/mails" + :location => defined?(Rails.root) ? "#{Rails.root}/tmp/mails" : "#{Dir.tmpdir}/mails" } def perform_delivery(mail) diff --git a/actionmailer/lib/action_mailer/mail_helper.rb b/actionmailer/lib/action_mailer/mail_helper.rb index 351b966abe..9aa178cdef 100644 --- a/actionmailer/lib/action_mailer/mail_helper.rb +++ b/actionmailer/lib/action_mailer/mail_helper.rb @@ -1,17 +1,19 @@ -module MailHelper - # Uses Text::Format to take the text and format it, indented two spaces for - # each line, and wrapped at 72 columns. - def block_format(text) - formatted = text.split(/\n\r\n/).collect { |paragraph| - Text::Format.new( - :columns => 72, :first_indent => 2, :body_indent => 2, :text => paragraph - ).format - }.join("\n") +module ActionMailer + module MailHelper + # Uses Text::Format to take the text and format it, indented two spaces for + # each line, and wrapped at 72 columns. + def block_format(text) + formatted = text.split(/\n\r\n/).collect { |paragraph| + Text::Format.new( + :columns => 72, :first_indent => 2, :body_indent => 2, :text => paragraph + ).format + }.join("\n") - # Make list points stand on their own line - formatted.gsub!(/[ ]*([*]+) ([^*]*)/) { |s| " #{$1} #{$2.strip}\n" } - formatted.gsub!(/[ ]*([#]+) ([^#]*)/) { |s| " #{$1} #{$2.strip}\n" } + # Make list points stand on their own line + formatted.gsub!(/[ ]*([*]+) ([^*]*)/) { |s| " #{$1} #{$2.strip}\n" } + formatted.gsub!(/[ ]*([#]+) ([^#]*)/) { |s| " #{$1} #{$2.strip}\n" } - formatted + formatted + end end -end +end \ No newline at end of file -- cgit v1.2.3 From 96e0638ce2a287eb5c43266fb4eb3e656e9968cf Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Thu, 3 Dec 2009 09:06:01 -0800 Subject: Should fix a few Sam Ruby fails. --- actionmailer/lib/action_mailer.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'actionmailer/lib') diff --git a/actionmailer/lib/action_mailer.rb b/actionmailer/lib/action_mailer.rb index 12e781b6c3..eec4040bcc 100644 --- a/actionmailer/lib/action_mailer.rb +++ b/actionmailer/lib/action_mailer.rb @@ -25,7 +25,6 @@ actionpack_path = "#{File.dirname(__FILE__)}/../../actionpack/lib" $:.unshift(actionpack_path) if File.directory?(actionpack_path) require 'action_controller' require 'action_view' -require 'active_support/autoload' module ActionMailer extend ::ActiveSupport::Autoload -- cgit v1.2.3 From 7ee5843c3cedfe36a680d5b28aa31eef45296c50 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Wed, 16 Dec 2009 11:56:51 -0600 Subject: Fully expand relative rails framework paths and make sure we aren't adding any to the load path more than once. --- actionmailer/lib/action_mailer.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'actionmailer/lib') diff --git a/actionmailer/lib/action_mailer.rb b/actionmailer/lib/action_mailer.rb index eec4040bcc..f439eb175c 100644 --- a/actionmailer/lib/action_mailer.rb +++ b/actionmailer/lib/action_mailer.rb @@ -21,8 +21,9 @@ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #++ -actionpack_path = "#{File.dirname(__FILE__)}/../../actionpack/lib" -$:.unshift(actionpack_path) if File.directory?(actionpack_path) +actionpack_path = File.expand_path('../../../actionpack/lib', __FILE__) +$:.unshift(actionpack_path) if File.directory?(actionpack_path) && !$:.include?(actionpack_path) + require 'action_controller' require 'action_view' -- cgit v1.2.3 From 418639b4cfe477d7309fa53e8b8e2472b44bda80 Mon Sep 17 00:00:00 2001 From: Mikel Lindsaar Date: Thu, 17 Dec 2009 12:00:32 +1100 Subject: Fixes for working with 1.9.1-head --- actionmailer/lib/action_mailer.rb | 2 +- actionmailer/lib/action_mailer/base.rb | 1 - actionmailer/lib/action_mailer/mail_helper.rb | 19 ------------------- 3 files changed, 1 insertion(+), 21 deletions(-) delete mode 100644 actionmailer/lib/action_mailer/mail_helper.rb (limited to 'actionmailer/lib') diff --git a/actionmailer/lib/action_mailer.rb b/actionmailer/lib/action_mailer.rb index e7ad68e212..e8adbf0eff 100644 --- a/actionmailer/lib/action_mailer.rb +++ b/actionmailer/lib/action_mailer.rb @@ -54,5 +54,5 @@ module Net end -gem 'mail', '>= 1.3.0' +gem 'mail', '>= 1.3.2' require 'mail' diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index 24064b3a74..ab00bbba3c 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -258,7 +258,6 @@ module ActionMailer #:nodoc: include AbstractController::Layouts include AbstractController::Helpers - helper ActionMailer::MailHelper if Object.const_defined?(:ActionController) include ActionController::UrlWriter diff --git a/actionmailer/lib/action_mailer/mail_helper.rb b/actionmailer/lib/action_mailer/mail_helper.rb deleted file mode 100644 index 9aa178cdef..0000000000 --- a/actionmailer/lib/action_mailer/mail_helper.rb +++ /dev/null @@ -1,19 +0,0 @@ -module ActionMailer - module MailHelper - # Uses Text::Format to take the text and format it, indented two spaces for - # each line, and wrapped at 72 columns. - def block_format(text) - formatted = text.split(/\n\r\n/).collect { |paragraph| - Text::Format.new( - :columns => 72, :first_indent => 2, :body_indent => 2, :text => paragraph - ).format - }.join("\n") - - # Make list points stand on their own line - formatted.gsub!(/[ ]*([*]+) ([^*]*)/) { |s| " #{$1} #{$2.strip}\n" } - formatted.gsub!(/[ ]*([#]+) ([^#]*)/) { |s| " #{$1} #{$2.strip}\n" } - - formatted - end - end -end \ No newline at end of file -- cgit v1.2.3 From 63b124b043dec036403f9a88aeafdf99669064e0 Mon Sep 17 00:00:00 2001 From: Mikel Lindsaar Date: Thu, 17 Dec 2009 12:23:08 +1100 Subject: Merged in latest changes from rails/master --- actionmailer/lib/action_mailer.rb | 3 ++- actionmailer/lib/action_mailer/base.rb | 3 ++- actionmailer/lib/action_mailer/mail_helper.rb | 19 +++++++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 actionmailer/lib/action_mailer/mail_helper.rb (limited to 'actionmailer/lib') diff --git a/actionmailer/lib/action_mailer.rb b/actionmailer/lib/action_mailer.rb index e8adbf0eff..e7d396aca5 100644 --- a/actionmailer/lib/action_mailer.rb +++ b/actionmailer/lib/action_mailer.rb @@ -34,11 +34,12 @@ module ActionMailer autoload :DeprecatedBody autoload :Base autoload :DeliveryMethod + autoload :MailHelper autoload :Part autoload :PartContainer autoload :Quoting - autoload :TestCase autoload :TestHelper + end module Text diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index ab00bbba3c..9862c2265b 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -258,7 +258,8 @@ module ActionMailer #:nodoc: include AbstractController::Layouts include AbstractController::Helpers - + helper ActionMailer::MailHelper + if Object.const_defined?(:ActionController) include ActionController::UrlWriter end diff --git a/actionmailer/lib/action_mailer/mail_helper.rb b/actionmailer/lib/action_mailer/mail_helper.rb new file mode 100644 index 0000000000..f4eeed0e42 --- /dev/null +++ b/actionmailer/lib/action_mailer/mail_helper.rb @@ -0,0 +1,19 @@ +module ActionMailer + module MailHelper + # Uses Text::Format to take the text and format it, indented two spaces for + # each line, and wrapped at 72 columns. + def block_format(text) + formatted = text.split(/\n\r\n/).collect { |paragraph| + Text::Format.new( + :columns => 72, :first_indent => 2, :body_indent => 2, :text => paragraph + ).format + }.join("\n") + + # Make list points stand on their own line + formatted.gsub!(/[ ]*([*]+) ([^*]*)/) { |s| " #{$1} #{$2.strip}\n" } + formatted.gsub!(/[ ]*([#]+) ([^#]*)/) { |s| " #{$1} #{$2.strip}\n" } + + formatted + end + end +end -- cgit v1.2.3 From f176c9466381adcff70d06dbf9b81ad89f17df04 Mon Sep 17 00:00:00 2001 From: Mikel Lindsaar Date: Thu, 17 Dec 2009 12:35:07 +1100 Subject: Updating requirement for mail to 1.3.3 --- actionmailer/lib/action_mailer.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionmailer/lib') diff --git a/actionmailer/lib/action_mailer.rb b/actionmailer/lib/action_mailer.rb index e7d396aca5..d32d421c2c 100644 --- a/actionmailer/lib/action_mailer.rb +++ b/actionmailer/lib/action_mailer.rb @@ -55,5 +55,5 @@ module Net end -gem 'mail', '>= 1.3.2' +gem 'mail', '>= 1.3.3' require 'mail' -- cgit v1.2.3 From 8950346f8a043b5bf4dde39e527270909bf2668c Mon Sep 17 00:00:00 2001 From: Mikel Lindsaar Date: Thu, 17 Dec 2009 13:17:35 +1100 Subject: Updating requirement for mail to 1.3.4 --- actionmailer/lib/action_mailer.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionmailer/lib') diff --git a/actionmailer/lib/action_mailer.rb b/actionmailer/lib/action_mailer.rb index d32d421c2c..87e1c4a1f3 100644 --- a/actionmailer/lib/action_mailer.rb +++ b/actionmailer/lib/action_mailer.rb @@ -55,5 +55,5 @@ module Net end -gem 'mail', '>= 1.3.3' +gem 'mail', '>= 1.3.4' require 'mail' -- cgit v1.2.3 From 83f4d86a9330533ec9af21ba18b4ab28011b8981 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 20 Dec 2009 17:15:31 -0800 Subject: Rename the RenderingController module to just plain Rendering --- actionmailer/lib/action_mailer/base.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionmailer/lib') diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index b5239ac0cd..a69838fe43 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -253,7 +253,7 @@ module ActionMailer #:nodoc: class Base include AdvAttrAccessor, PartContainer, Quoting, Utils - include AbstractController::RenderingController + include AbstractController::Rendering include AbstractController::LocalizedCache include AbstractController::Layouts -- cgit v1.2.3 From be225adafbec267353fa7260179b0ce5a72e4283 Mon Sep 17 00:00:00 2001 From: Carlhuda Date: Mon, 21 Dec 2009 16:48:44 -0800 Subject: Fix ActionMailer. The fact that ActionMailer::Base does not inherit from AbstractController::Base is either a bug or we need to re-evaluate the requirements of the mixins. --- actionmailer/lib/action_mailer/base.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'actionmailer/lib') diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index a69838fe43..40aff7f0d8 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -271,6 +271,8 @@ module ActionMailer #:nodoc: class_inheritable_accessor :view_paths self.view_paths = [] + attr_internal :formats + cattr_accessor :logger @@raise_delivery_errors = true @@ -452,6 +454,7 @@ module ActionMailer #:nodoc: # remain uninitialized (useful when you only need to invoke the "receive" # method, for instance). def initialize(method_name=nil, *parameters) #:nodoc: + @_formats = [] @_response_body = nil super() create!(method_name, *parameters) if method_name -- cgit v1.2.3 From 4964d3b02cd5c87d821ab7d41d243154c727185d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 22 Dec 2009 20:17:27 +0100 Subject: Make ActionMailer::Base inherit from AbstractController::Base Signed-off-by: Yehuda Katz --- actionmailer/lib/action_mailer/base.rb | 60 +++++++++------------------------- 1 file changed, 16 insertions(+), 44 deletions(-) (limited to 'actionmailer/lib') diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index 40aff7f0d8..b2c355c7ae 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -250,31 +250,21 @@ module ActionMailer #:nodoc: # ["text/html", "text/enriched", "text/plain"]. Items that appear first in the array have higher priority in the mail client # 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 + class Base < AbstractController::Base include AdvAttrAccessor, PartContainer, Quoting, Utils include AbstractController::Rendering include AbstractController::LocalizedCache include AbstractController::Layouts - include AbstractController::Helpers - helper ActionMailer::MailHelper - if Object.const_defined?(:ActionController) - include ActionController::UrlWriter - end + helper ActionMailer::MailHelper + include ActionController::UrlWriter include ActionMailer::DeprecatedBody private_class_method :new #:nodoc: - class_inheritable_accessor :view_paths - self.view_paths = [] - - attr_internal :formats - - cattr_accessor :logger - @@raise_delivery_errors = true cattr_accessor :raise_delivery_errors @@ -346,24 +336,13 @@ module ActionMailer #:nodoc: # have multiple mailer methods share the same template. adv_attr_accessor :template - # The mail and action_name instances referenced by this mailer. - attr_reader :mail, :action_name - - # Where the response body is stored. - attr_internal :response_body - # Override the mailer name, which defaults to an inflected version of the # mailer's class name. If you want to use a template in a non-standard # location, you can use this to specify that location. - attr_writer :mailer_name + adv_attr_accessor :mailer_name - def mailer_name(value = nil) - if value - @mailer_name = value - else - @mailer_name || self.class.mailer_name - end - end + # Expose the internal mail + attr_reader :mail # Alias controller_path to mailer_name so render :partial in views work. alias :controller_path :mailer_name @@ -453,18 +432,16 @@ module ActionMailer #:nodoc: # will be initialized according to the named method. If not, the mailer will # remain uninitialized (useful when you only need to invoke the "receive" # method, for instance). - def initialize(method_name=nil, *parameters) #:nodoc: - @_formats = [] - @_response_body = nil + def initialize(method_name=nil, *args) #:nodoc: super() - create!(method_name, *parameters) if method_name + process(method_name, *args) if method_name end - # Initialize the mailer via the given +method_name+. The body will be + # Process the mailer via the given +method_name+. The body will be # rendered and a new TMail::Mail object created. - def create!(method_name, *parameters) #:nodoc: + def process(method_name, *args) #:nodoc: initialize_defaults(method_name) - __send__(method_name, *parameters) + super # Create e-mail parts create_parts @@ -473,7 +450,7 @@ module ActionMailer #:nodoc: @subject ||= I18n.t(:subject, :scope => [:actionmailer, mailer_name, method_name], :default => method_name.humanize) - # build the mail object itself + # Build the mail object itself @mail = create_mail end @@ -488,7 +465,7 @@ module ActionMailer #:nodoc: logger.debug "\n#{mail.encoded}" end - ActiveSupport::Notifications.instrument(:deliver_mail, :mail => @mail) do + ActiveSupport::Notifications.instrument(:deliver_mail, :mail => mail) do begin self.delivery_method.perform_delivery(mail) if perform_deliveries rescue Exception => e # Net::SMTP errors or sendmail pipe errors @@ -510,23 +487,18 @@ module ActionMailer #:nodoc: @implicit_parts_order ||= @@default_implicit_parts_order.dup @mime_version ||= @@default_mime_version.dup if @@default_mime_version - @mailer_name ||= self.class.mailer_name + @mailer_name ||= self.class.mailer_name.dup @template ||= method_name - @action_name = @template @parts ||= [] @headers ||= {} @sent_on ||= Time.now - ActiveSupport::Deprecation.silence do - super # Run deprecation hooks - end + super # Run deprecation hooks end def create_parts - ActiveSupport::Deprecation.silence do - super # Run deprecation hooks - end + super # Run deprecation hooks if String === response_body @parts.unshift Part.new( -- cgit v1.2.3 From ace20bd25e3818b7f29c222643dd445c48b36425 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 22 Dec 2009 17:27:37 -0600 Subject: Flip deferrable autoload convention --- actionmailer/lib/action_mailer.rb | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) (limited to 'actionmailer/lib') diff --git a/actionmailer/lib/action_mailer.rb b/actionmailer/lib/action_mailer.rb index f439eb175c..6539451bea 100644 --- a/actionmailer/lib/action_mailer.rb +++ b/actionmailer/lib/action_mailer.rb @@ -30,29 +30,34 @@ require 'action_view' module ActionMailer extend ::ActiveSupport::Autoload - autoload :AdvAttrAccessor - autoload :DeprecatedBody - autoload :Base - autoload :DeliveryMethod - autoload :MailHelper - autoload :Part - autoload :PartContainer - autoload :Quoting - autoload :TestHelper - autoload :Utils + eager_autoload do + autoload :AdvAttrAccessor + autoload :DeprecatedBody + autoload :Base + autoload :DeliveryMethod + autoload :MailHelper + autoload :Part + autoload :PartContainer + autoload :Quoting + autoload :TestHelper + autoload :Utils + end end module Text extend ActiveSupport::Autoload - autoload :Format, 'action_mailer/vendor/text_format' + eager_autoload do + autoload :Format, 'action_mailer/vendor/text_format' + end end module Net extend ActiveSupport::Autoload - autoload :SMTP + eager_autoload do + autoload :SMTP + end end - require 'action_mailer/vendor/tmail' -- cgit v1.2.3 From 2e4e8d156ca1a2f3fe2f587956097621433514f8 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 22 Dec 2009 17:33:00 -0600 Subject: All AM modules are safe to defer --- actionmailer/lib/action_mailer.rb | 40 ++++++---------------- actionmailer/lib/action_mailer/base.rb | 3 ++ actionmailer/lib/action_mailer/delivery_method.rb | 5 ++- .../lib/action_mailer/delivery_method/smtp.rb | 4 +-- 4 files changed, 17 insertions(+), 35 deletions(-) (limited to 'actionmailer/lib') diff --git a/actionmailer/lib/action_mailer.rb b/actionmailer/lib/action_mailer.rb index 6539451bea..d7bbbbd78c 100644 --- a/actionmailer/lib/action_mailer.rb +++ b/actionmailer/lib/action_mailer.rb @@ -30,34 +30,14 @@ require 'action_view' module ActionMailer extend ::ActiveSupport::Autoload - eager_autoload do - autoload :AdvAttrAccessor - autoload :DeprecatedBody - autoload :Base - autoload :DeliveryMethod - autoload :MailHelper - autoload :Part - autoload :PartContainer - autoload :Quoting - autoload :TestHelper - autoload :Utils - end + autoload :AdvAttrAccessor + autoload :DeprecatedBody + autoload :Base + autoload :DeliveryMethod + autoload :MailHelper + autoload :Part + autoload :PartContainer + autoload :Quoting + autoload :TestHelper + autoload :Utils end - -module Text - extend ActiveSupport::Autoload - - eager_autoload do - autoload :Format, 'action_mailer/vendor/text_format' - end -end - -module Net - extend ActiveSupport::Autoload - - eager_autoload do - autoload :SMTP - end -end - -require 'action_mailer/vendor/tmail' diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index b2c355c7ae..de78e87fb4 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -1,4 +1,7 @@ require 'active_support/core_ext/class' +require 'action_mailer/part' +require 'action_mailer/vendor/text_format' +require 'action_mailer/vendor/tmail' module ActionMailer #:nodoc: # Action Mailer allows you to send email from your application using a mailer model and views. diff --git a/actionmailer/lib/action_mailer/delivery_method.rb b/actionmailer/lib/action_mailer/delivery_method.rb index 29a51afdc3..4f7d3afc3c 100644 --- a/actionmailer/lib/action_mailer/delivery_method.rb +++ b/actionmailer/lib/action_mailer/delivery_method.rb @@ -1,7 +1,7 @@ -require "active_support/core_ext/class" +require 'active_support/core_ext/class' + module ActionMailer module DeliveryMethod - autoload :File, 'action_mailer/delivery_method/file' autoload :Sendmail, 'action_mailer/delivery_method/sendmail' autoload :Smtp, 'action_mailer/delivery_method/smtp' @@ -52,6 +52,5 @@ module ActionMailer superclass_delegating_accessor :settings self.settings = {} end - end end diff --git a/actionmailer/lib/action_mailer/delivery_method/smtp.rb b/actionmailer/lib/action_mailer/delivery_method/smtp.rb index 95c117c9e0..f81d64af36 100644 --- a/actionmailer/lib/action_mailer/delivery_method/smtp.rb +++ b/actionmailer/lib/action_mailer/delivery_method/smtp.rb @@ -1,8 +1,9 @@ +require 'net/smtp' + module ActionMailer module DeliveryMethod # A delivery method implementation which sends via smtp. class Smtp < Method - self.settings = { :address => "localhost", :port => 25, @@ -26,6 +27,5 @@ module ActionMailer end end end - end end -- cgit v1.2.3 From d2bd71a145ddc5e3e3750edc9a09eab742aaf02a Mon Sep 17 00:00:00 2001 From: Carlhuda Date: Wed, 23 Dec 2009 17:01:07 -0800 Subject: Finish moving config.frameworks-dependent code to the framework plugin --- actionmailer/lib/action_mailer/rails.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 actionmailer/lib/action_mailer/rails.rb (limited to 'actionmailer/lib') diff --git a/actionmailer/lib/action_mailer/rails.rb b/actionmailer/lib/action_mailer/rails.rb new file mode 100644 index 0000000000..a3573cdea7 --- /dev/null +++ b/actionmailer/lib/action_mailer/rails.rb @@ -0,0 +1,24 @@ +require "action_mailer" + +module ActionMailer + class Plugin < Rails::Plugin + plugin_name :action_mailer + + initializer "action_mailer.set_configs" do |app| + app.config.action_mailer.each do |k,v| + ActionMailer::Base.send "#{k}=", v + end + end + + # TODO: ActionController::Base.logger should delegate to its own config.logger + initializer "action_mailer.logger" do + ActionMailer::Base.logger ||= Rails.logger + end + + initializer "action_mailer.view_paths" do |app| + # TODO: this should be combined with the logic for default config.action_mailer.view_paths + view_path = ActionView::PathSet.type_cast(app.config.view_path, app.config.cache_classes) + ActionMailer::Base.template_root = view_path if ActionMailer::Base.view_paths.blank? + end + end +end \ No newline at end of file -- cgit v1.2.3 From ee70d1b6ad9b79d2c3d284e78af4e20416575ea8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 25 Dec 2009 21:35:40 +0100 Subject: adv_attr_accessors in ActionMailer are not sent to the views, use the mailer object if you need to access the subject, recipients, from, etc. --- .../lib/action_mailer/adv_attr_accessor.rb | 32 ++++++++++------------ actionmailer/lib/action_mailer/base.rb | 24 ++++++++-------- actionmailer/lib/action_mailer/mail_helper.rb | 5 ++++ actionmailer/lib/action_mailer/part.rb | 3 +- 4 files changed, 33 insertions(+), 31 deletions(-) (limited to 'actionmailer/lib') diff --git a/actionmailer/lib/action_mailer/adv_attr_accessor.rb b/actionmailer/lib/action_mailer/adv_attr_accessor.rb index e77029afdd..be6b1feca9 100644 --- a/actionmailer/lib/action_mailer/adv_attr_accessor.rb +++ b/actionmailer/lib/action_mailer/adv_attr_accessor.rb @@ -1,29 +1,25 @@ module ActionMailer module AdvAttrAccessor #:nodoc: - def self.included(base) - base.extend(ClassMethods) - end - - module ClassMethods #:nodoc: - def adv_attr_accessor(*names) - names.each do |name| - ivar = "@#{name}" + def adv_attr_accessor(*names) + names.each do |name| + ivar = "@#{name}" - define_method("#{name}=") do |value| - instance_variable_set(ivar, value) + class_eval <<-ACCESSORS, __FILE__, __LINE__ + 1 + def #{name}=(value) + #{ivar} = value end - define_method(name) do |*parameters| - raise ArgumentError, "expected 0 or 1 parameters" unless parameters.length <= 1 - if parameters.empty? - if instance_variable_names.include?(ivar) - instance_variable_get(ivar) - end + def #{name}(*args) + raise ArgumentError, "expected 0 or 1 parameters" unless args.length <= 1 + if args.empty? + #{ivar} if instance_variable_names.include?(#{ivar.inspect}) else - instance_variable_set(ivar, parameters.first) + #{ivar} = args.first end end - end + ACCESSORS + + self.protected_instance_variables << ivar if self.respond_to?(:protected_instance_variables) end end end diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index de78e87fb4..478762f94f 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -25,7 +25,8 @@ module ActionMailer #:nodoc: # bcc ["bcc@example.com", "Order Watcher "] # from "system@example.com" # subject "New account information" - # body :account => recipient + # + # @account = recipient # end # end # @@ -45,13 +46,6 @@ module ActionMailer #:nodoc: # address. Setting this is useful when you want delivery notifications sent to a different address than # the one in from. # - # The body method has special behavior. It takes a hash which generates an instance variable - # named after each key in the hash containing the value that that key points to. - # - # So, for example, body :account => recipient would result - # in an instance variable @account with the value of recipient being accessible in the - # view. - # # # = Mailer views # @@ -71,7 +65,12 @@ module ActionMailer #:nodoc: # You can even use Action Pack helpers in these views. For example: # # You got a new note! - # <%= truncate(note.body, 25) %> + # <%= truncate(@note.body, 25) %> + # + # If you need to access the subject, from or the recipients in the view, you can do that through mailer object: + # + # You got a new note from <%= mailer.from %>! + # <%= truncate(@note.body, 25) %> # # # = Generating URLs @@ -254,14 +253,15 @@ 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 < AbstractController::Base - include AdvAttrAccessor, PartContainer, Quoting, Utils + include PartContainer, Quoting, Utils + extend AdvAttrAccessor include AbstractController::Rendering include AbstractController::LocalizedCache include AbstractController::Layouts include AbstractController::Helpers - helper ActionMailer::MailHelper + helper ActionMailer::MailHelper include ActionController::UrlWriter include ActionMailer::DeprecatedBody @@ -289,7 +289,7 @@ module ActionMailer #:nodoc: @@default_implicit_parts_order = [ "text/html", "text/enriched", "text/plain" ] cattr_accessor :default_implicit_parts_order - @@protected_instance_variables = [] + @@protected_instance_variables = %w(@parts @mail) cattr_reader :protected_instance_variables # Specify the BCC addresses for the message diff --git a/actionmailer/lib/action_mailer/mail_helper.rb b/actionmailer/lib/action_mailer/mail_helper.rb index 9aa178cdef..a1dec68c5d 100644 --- a/actionmailer/lib/action_mailer/mail_helper.rb +++ b/actionmailer/lib/action_mailer/mail_helper.rb @@ -15,5 +15,10 @@ module ActionMailer formatted end + + # Access the mailer instance. + def mailer #:nodoc: + @controller + end end end \ No newline at end of file diff --git a/actionmailer/lib/action_mailer/part.rb b/actionmailer/lib/action_mailer/part.rb index 2bbb59cdb6..9ff962c39a 100644 --- a/actionmailer/lib/action_mailer/part.rb +++ b/actionmailer/lib/action_mailer/part.rb @@ -4,7 +4,8 @@ module ActionMailer # and add them to the +parts+ list of the mailer, it is easier # to use the helper methods in ActionMailer::PartContainer. class Part - include AdvAttrAccessor, PartContainer, Utils + include PartContainer, Utils + extend AdvAttrAccessor # 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 -- cgit v1.2.3 From 88ba056043e22c4c60dde6b07df897e502f49491 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 25 Dec 2009 21:46:01 +0100 Subject: Refactor multiple parts logic and move Utils to PartContainer. --- actionmailer/lib/action_mailer/base.rb | 14 +++----------- actionmailer/lib/action_mailer/part.rb | 14 +++----------- actionmailer/lib/action_mailer/part_container.rb | 20 ++++++++++++++++++-- actionmailer/lib/action_mailer/utils.rb | 7 ------- 4 files changed, 24 insertions(+), 31 deletions(-) delete mode 100644 actionmailer/lib/action_mailer/utils.rb (limited to 'actionmailer/lib') diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index 478762f94f..84f5bd23a9 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -253,7 +253,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 < AbstractController::Base - include PartContainer, Quoting, Utils + include PartContainer, Quoting extend AdvAttrAccessor include AbstractController::Rendering @@ -454,7 +454,7 @@ module ActionMailer #:nodoc: :default => method_name.humanize) # Build the mail object itself - @mail = create_mail + create_mail end # Delivers a TMail::Mail object. By default, it delivers the cached mail @@ -582,15 +582,7 @@ module ActionMailer #:nodoc: m.set_content_type(real_content_type, nil, ctype_attrs) m.body = normalize_new_lines(@parts.first.body) else - @parts.each do |p| - part = (TMail::Mail === p ? p : p.to_mail(self)) - m.parts << part - end - - if real_content_type =~ /multipart/ - ctype_attrs.delete "charset" - m.set_content_type(real_content_type, nil, ctype_attrs) - end + setup_multiple_parts(m, real_content_type, ctype_attrs) end @mail = m diff --git a/actionmailer/lib/action_mailer/part.rb b/actionmailer/lib/action_mailer/part.rb index 9ff962c39a..716eaae86e 100644 --- a/actionmailer/lib/action_mailer/part.rb +++ b/actionmailer/lib/action_mailer/part.rb @@ -4,7 +4,7 @@ module ActionMailer # and add them to the +parts+ list of the mailer, it is easier # to use the helper methods in ActionMailer::PartContainer. class Part - include PartContainer, Utils + include PartContainer extend AdvAttrAccessor # Represents the body of the part, as a string. This should not be a @@ -83,16 +83,8 @@ module ActionMailer @parts.unshift Part.new(:charset => charset, :body => @body, :content_type => 'text/plain') @body = nil end - - @parts.each do |p| - prt = (TMail::Mail === p ? p : p.to_mail(defaults)) - part.parts << prt - end - - if real_content_type =~ /multipart/ - ctype_attrs.delete 'charset' - part.set_content_type(real_content_type, nil, ctype_attrs) - end + + setup_multiple_parts(part, real_content_type, ctype_attrs) end headers.each { |k,v| part[k] = v } diff --git a/actionmailer/lib/action_mailer/part_container.rb b/actionmailer/lib/action_mailer/part_container.rb index abfd8f8426..3fe502b1fb 100644 --- a/actionmailer/lib/action_mailer/part_container.rb +++ b/actionmailer/lib/action_mailer/part_container.rb @@ -39,8 +39,24 @@ module ActionMailer end private - - def parse_content_type(defaults=nil) + + def normalize_new_lines(text) #:nodoc: + text.to_s.gsub(/\r\n?/, "\n") + end + + def setup_multiple_parts(mailer, real_content_type, ctype_attrs) #:nodoc: + @parts.each do |p| + part = (TMail::Mail === p ? p : p.to_mail(self)) + mailer.parts << part + end + + if real_content_type =~ /multipart/ + ctype_attrs.delete "charset" + mailer.set_content_type(real_content_type, nil, ctype_attrs) + end + end + + def parse_content_type(defaults=nil) #:nodoc: if content_type.blank? return defaults ? [ defaults.content_type, { 'charset' => defaults.charset } ] : diff --git a/actionmailer/lib/action_mailer/utils.rb b/actionmailer/lib/action_mailer/utils.rb deleted file mode 100644 index 26d2e60aaf..0000000000 --- a/actionmailer/lib/action_mailer/utils.rb +++ /dev/null @@ -1,7 +0,0 @@ -module ActionMailer - module Utils #:nodoc: - def normalize_new_lines(text) - text.to_s.gsub(/\r\n?/, "\n") - end - end -end -- cgit v1.2.3 From 4e1fa4912d2777cba980b4a936a89bd63d201614 Mon Sep 17 00:00:00 2001 From: Mikel Lindsaar Date: Sun, 27 Dec 2009 18:38:30 +1100 Subject: Updating actionmailer to call :to_s on all field values instead of decoded --- actionmailer/lib/action_mailer.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionmailer/lib') diff --git a/actionmailer/lib/action_mailer.rb b/actionmailer/lib/action_mailer.rb index 87e1c4a1f3..c82efe4d6d 100644 --- a/actionmailer/lib/action_mailer.rb +++ b/actionmailer/lib/action_mailer.rb @@ -55,5 +55,5 @@ module Net end -gem 'mail', '>= 1.3.4' +gem 'mail', '>= 1.3.5' require 'mail' -- cgit v1.2.3 From 331d375cc332e9e8a30a7f9e745414769b780c54 Mon Sep 17 00:00:00 2001 From: Mikel Lindsaar Date: Sun, 27 Dec 2009 20:56:16 +1100 Subject: Changing body to use :to_s instead of :decoded... better use case --- actionmailer/lib/action_mailer.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionmailer/lib') diff --git a/actionmailer/lib/action_mailer.rb b/actionmailer/lib/action_mailer.rb index c82efe4d6d..6a62267d90 100644 --- a/actionmailer/lib/action_mailer.rb +++ b/actionmailer/lib/action_mailer.rb @@ -55,5 +55,5 @@ module Net end -gem 'mail', '>= 1.3.5' +gem 'mail', '>= 1.4.0' require 'mail' -- cgit v1.2.3 From fd58a2d1da04508a7fdf825143e61d186112e63e Mon Sep 17 00:00:00 2001 From: Mikel Lindsaar Date: Sun, 27 Dec 2009 21:42:33 +1100 Subject: Updating action_mailer to need mail 1.4.1 --- actionmailer/lib/action_mailer.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionmailer/lib') diff --git a/actionmailer/lib/action_mailer.rb b/actionmailer/lib/action_mailer.rb index 6a62267d90..1c08d3843a 100644 --- a/actionmailer/lib/action_mailer.rb +++ b/actionmailer/lib/action_mailer.rb @@ -55,5 +55,5 @@ module Net end -gem 'mail', '>= 1.4.0' +gem 'mail', '>= 1.4.1' require 'mail' -- cgit v1.2.3 From 971f4ff829f7ead6381e0fead93b33104b037cdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 27 Dec 2009 12:36:00 +0100 Subject: DRY ActionMailer code. --- actionmailer/lib/action_mailer/base.rb | 121 +++++++++++++++++---------------- 1 file changed, 61 insertions(+), 60 deletions(-) (limited to 'actionmailer/lib') diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index 3b459da9bd..f28bce9947 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -346,33 +346,6 @@ module ActionMailer #:nodoc: # Alias controller_path to mailer_name so render :partial in views work. alias :controller_path :mailer_name - # Add a part to a multipart message, with the given content-type. The - # part itself is yielded to the block so that other properties (charset, - # body, headers, etc.) can be set on it. - def part(params) - params = {:content_type => params} if String === params - if custom_headers = params.delete(:headers) - ActiveSupport::Deprecation.warn('Passing custom headers with :headers => {} is deprecated. ' << - 'Please just pass in custom headers directly.', caller[0,10]) - params.merge!(custom_headers) - end - part = Mail::Part.new(params) - yield part if block_given? - @parts << part - end - - # Add an attachment to a multipart message. This is simply a part with the - # content-disposition set to "attachment". - def attachment(params, &block) - super # Run deprecation hooks - - params = { :content_type => params } if String === params - params = { :content_disposition => "attachment", - :content_transfer_encoding => "base64" }.merge(params) - - part(params, &block) - end - class << self attr_writer :mailer_name @@ -453,18 +426,45 @@ module ActionMailer #:nodoc: superclass_delegating_reader :delivery_method self.delivery_method = :smtp + # Add a part to a multipart message, with the given content-type. The + # part itself is yielded to the block so that other properties (charset, + # body, headers, etc.) can be set on it. + def part(params) + params = {:content_type => params} if String === params + if custom_headers = params.delete(:headers) + ActiveSupport::Deprecation.warn('Passing custom headers with :headers => {} is deprecated. ' << + 'Please just pass in custom headers directly.', caller[0,10]) + params.merge!(custom_headers) + end + part = Mail::Part.new(params) + yield part if block_given? + @parts << part + end + + # Add an attachment to a multipart message. This is simply a part with the + # content-disposition set to "attachment". + def attachment(params, &block) + super # Run deprecation hooks + + params = { :content_type => params } if String === params + params = { :content_disposition => "attachment", + :content_transfer_encoding => "base64" }.merge(params) + + part(params, &block) + 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" # method, for instance). - def initialize(method_name=nil, *args) #:nodoc: + def initialize(method_name=nil, *args) super() process(method_name, *args) if method_name end # Process the mailer via the given +method_name+. The body will be - # rendered and a new TMail::Mail object created. - def process(method_name, *args) #:nodoc: + # rendered and a new Mail object created. + def process(method_name, *args) initialize_defaults(method_name) super @@ -506,7 +506,7 @@ module ActionMailer #:nodoc: # Set up the default values for the various instance variables of this # mailer. Subclasses may override this method to provide different # defaults. - def initialize_defaults(method_name) + def initialize_defaults(method_name) #:nodoc: @charset ||= @@default_charset.dup @content_type ||= @@default_content_type.dup @implicit_parts_order ||= @@default_implicit_parts_order.dup @@ -522,24 +522,14 @@ module ActionMailer #:nodoc: super # Run deprecation hooks end - def create_parts + def create_parts #:nodoc: super # Run deprecation hooks if String === response_body - @parts.unshift Mail::Part.new( - :content_type => ["text", "plain", {:charset => charset}], - :content_disposition => "inline", - :body => response_body - ) + @parts.unshift create_inline_part(response_body) else self.class.template_root.find_all(@template, {}, mailer_name).each do |template| - ct = template.mime_type ? template.mime_type.to_s : "text/plain" - main_type, sub_type = ct.split("/") - @parts << Mail::Part.new( - :content_type => [main_type, sub_type, {:charset => charset}], - :content_disposition => "inline", - :body => render_to_body(:_template => template) - ) + @parts << create_inline_part(render_to_body(:_template => template), template.mime_type) end if @parts.size > 1 @@ -553,7 +543,18 @@ module ActionMailer #:nodoc: end end - def sort_parts(parts, order = []) + def create_inline_part(body, mime_type=nil) #:nodoc: + ct = mime_type || "text/plain" + main_type, sub_type = split_content_type(ct.to_s) + + Mail::Part.new( + :content_type => [main_type, sub_type, {:charset => charset}], + :content_disposition => "inline", + :body => body + ) + end + + def sort_parts(parts, order = []) #:nodoc: order = order.collect { |s| s.downcase } parts = parts.sort do |a, b| @@ -582,7 +583,7 @@ module ActionMailer #:nodoc: parts end - def create_mail + def create_mail #:nodoc: m = Mail.new m.subject, = quote_any_if_necessary(charset, subject) @@ -596,13 +597,12 @@ module ActionMailer #:nodoc: headers.each { |k, v| m[k] = v } real_content_type, ctype_attrs = parse_content_type + main_type, sub_type = split_content_type(real_content_type) if @parts.empty? - main_type, sub_type = split_content_type(real_content_type) m.content_type([main_type, sub_type, ctype_attrs]) m.body = body elsif @parts.size == 1 && @parts.first.parts.empty? - main_type, sub_type = split_content_type(real_content_type) m.content_type([main_type, sub_type, ctype_attrs]) m.body = @parts.first.body.encoded else @@ -612,7 +612,6 @@ module ActionMailer #:nodoc: if real_content_type =~ /multipart/ ctype_attrs.delete "charset" - main_type, sub_type = split_content_type(real_content_type) m.content_type([main_type, sub_type, ctype_attrs]) end end @@ -620,21 +619,23 @@ module ActionMailer #:nodoc: @mail = m end - def split_content_type(ct) + def split_content_type(ct) #:nodoc: ct.to_s.split("/") end - def parse_content_type(defaults=nil) - 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)] + def parse_content_type(defaults=nil) #:nodoc: + if content_type.blank? + if defaults + [ defaults.content_type, { 'charset' => defaults.charset } ] + else + [ nil, {} ] + end + else + 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)] + end end - end end -- cgit v1.2.3 From c039bcdb1c94d8b28fc9398d4b88b4453cdd9fb1 Mon Sep 17 00:00:00 2001 From: Mikel Lindsaar Date: Mon, 28 Dec 2009 12:25:14 +1100 Subject: Moved sort_parts into Mail, updated mail requirement to 1.4.2 --- actionmailer/lib/action_mailer.rb | 3 ++- actionmailer/lib/action_mailer/base.rb | 41 +++++++++------------------------- 2 files changed, 12 insertions(+), 32 deletions(-) (limited to 'actionmailer/lib') diff --git a/actionmailer/lib/action_mailer.rb b/actionmailer/lib/action_mailer.rb index 0221e36bb0..8ac6318f9e 100644 --- a/actionmailer/lib/action_mailer.rb +++ b/actionmailer/lib/action_mailer.rb @@ -24,6 +24,7 @@ actionpack_path = File.expand_path('../../../actionpack/lib', __FILE__) $:.unshift(actionpack_path) if File.directory?(actionpack_path) && !$:.include?(actionpack_path) + require 'action_controller' require 'action_view' @@ -46,4 +47,4 @@ module Text autoload :Format, 'action_mailer/vendor/text_format' end -require 'mail' \ No newline at end of file +require 'mail' diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index f28bce9947..ba9ec3b4de 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -282,7 +282,13 @@ module ActionMailer #:nodoc: @@default_mime_version = "1.0" cattr_accessor :default_mime_version - @@default_implicit_parts_order = [ "text/html", "text/enriched", "text/plain" ] + # This specifies the order that the parts of a multipart email will be. Usually you put + # text/plain at the top so someone without a MIME capable email reader can read the plain + # text of your email first. + # + # Any content type that is not listed here will be inserted in the order you add them to + # the email after the content types you list here. + @@default_implicit_parts_order = [ "text/plain", "text/enriched", "text/html" ] cattr_accessor :default_implicit_parts_order @@protected_instance_variables = %w(@parts @mail) @@ -534,7 +540,6 @@ module ActionMailer #:nodoc: if @parts.size > 1 @content_type = "multipart/alternative" if @content_type !~ /^multipart/ - @parts = sort_parts(@parts, @implicit_parts_order) end # If this is a multipart e-mail add the mime_version if it is not @@ -554,35 +559,6 @@ module ActionMailer #:nodoc: ) end - def sort_parts(parts, order = []) #:nodoc: - order = order.collect { |s| s.downcase } - - parts = parts.sort do |a, b| - a_ct = a.content_type.string.downcase - b_ct = b.content_type.string.downcase - - a_in = order.include? a_ct - b_in = order.include? b_ct - - s = case - when a_in && b_in - order.index(a_ct) <=> order.index(b_ct) - when a_in - -1 - when b_in - 1 - else - a_ct <=> b_ct - end - - # reverse the ordering because parts that come last are displayed - # first in mail clients - (s * -1) - end - - parts - end - def create_mail #:nodoc: m = Mail.new @@ -606,9 +582,12 @@ module ActionMailer #:nodoc: m.content_type([main_type, sub_type, ctype_attrs]) m.body = @parts.first.body.encoded else + @parts.each do |p| m.add_part(p) end + m.body.set_sort_order(@implicit_parts_order) + m.body.sort_parts! if real_content_type =~ /multipart/ ctype_attrs.delete "charset" -- cgit v1.2.3 From 616ebb8f6a5dc38a6fe0ee497f2059a9bd78a457 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Mon, 28 Dec 2009 11:21:36 +0100 Subject: Remove unused code paths and require mail only when it's needed. --- actionmailer/lib/action_mailer.rb | 3 --- actionmailer/lib/action_mailer/base.rb | 22 ++++++++-------------- actionmailer/lib/action_mailer/test_case.rb | 1 + 3 files changed, 9 insertions(+), 17 deletions(-) (limited to 'actionmailer/lib') diff --git a/actionmailer/lib/action_mailer.rb b/actionmailer/lib/action_mailer.rb index 8ac6318f9e..55ddbb24f4 100644 --- a/actionmailer/lib/action_mailer.rb +++ b/actionmailer/lib/action_mailer.rb @@ -24,7 +24,6 @@ actionpack_path = File.expand_path('../../../actionpack/lib', __FILE__) $:.unshift(actionpack_path) if File.directory?(actionpack_path) && !$:.include?(actionpack_path) - require 'action_controller' require 'action_view' @@ -46,5 +45,3 @@ module Text autoload :Format, 'action_mailer/vendor/text_format' end - -require 'mail' diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index ba9ec3b4de..cd9bbd2d7b 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -1,4 +1,5 @@ require 'active_support/core_ext/class' +require 'mail' module ActionMailer #:nodoc: # Action Mailer allows you to send email from your application using a mailer model and views. @@ -534,7 +535,7 @@ module ActionMailer #:nodoc: if String === response_body @parts.unshift create_inline_part(response_body) else - self.class.template_root.find_all(@template, {}, mailer_name).each do |template| + self.class.template_root.find_all(@template, {}, @mailer_name).each do |template| @parts << create_inline_part(render_to_body(:_template => template), template.mime_type) end @@ -575,17 +576,14 @@ module ActionMailer #:nodoc: real_content_type, ctype_attrs = parse_content_type main_type, sub_type = split_content_type(real_content_type) - if @parts.empty? - m.content_type([main_type, sub_type, ctype_attrs]) - m.body = body - elsif @parts.size == 1 && @parts.first.parts.empty? + if @parts.size == 1 && @parts.first.parts.empty? m.content_type([main_type, sub_type, ctype_attrs]) m.body = @parts.first.body.encoded else - @parts.each do |p| m.add_part(p) end + m.body.set_sort_order(@implicit_parts_order) m.body.sort_parts! @@ -603,16 +601,12 @@ module ActionMailer #:nodoc: end def parse_content_type(defaults=nil) #:nodoc: - if content_type.blank? - if defaults - [ defaults.content_type, { 'charset' => defaults.charset } ] - else - [ nil, {} ] - end + if @content_type.blank? + [ nil, {} ] else - ctype, *attrs = content_type.split(/;\s*/) + 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)] + [ctype, {"charset" => @charset}.merge(attrs)] end end diff --git a/actionmailer/lib/action_mailer/test_case.rb b/actionmailer/lib/action_mailer/test_case.rb index 49f6d680a2..445abd0b89 100644 --- a/actionmailer/lib/action_mailer/test_case.rb +++ b/actionmailer/lib/action_mailer/test_case.rb @@ -1,4 +1,5 @@ require 'active_support/test_case' +require 'mail' module ActionMailer class NonInferrableMailerError < ::StandardError -- cgit v1.2.3 From b354496bda901cb0af499d6f3dff17a96a834a67 Mon Sep 17 00:00:00 2001 From: Mikel Lindsaar Date: Mon, 28 Dec 2009 21:41:16 +1100 Subject: Adding default 8bit encoding if the body has non usascii in it --- actionmailer/lib/action_mailer/base.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'actionmailer/lib') diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index cd9bbd2d7b..aea2498d4d 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -593,6 +593,8 @@ module ActionMailer #:nodoc: end end + m.content_transfer_encoding = '8bit' unless m.body.only_us_ascii? + @mail = m end -- cgit v1.2.3