Permalink
Browse files

Starting again on actionmailer integration with mail

  • Loading branch information...
1 parent cbded53 commit 15d7cac282e29f0a8e7b38dade07abb32d97a991 @mikel mikel committed Nov 12, 2009
Showing with 186 additions and 8,119 deletions.
  1. +2 −1 actionmailer/lib/action_mailer.rb
  2. +34 −16 actionmailer/lib/action_mailer/base.rb
  3. +1 −2 actionmailer/lib/action_mailer/delivery_method/smtp.rb
  4. +0 −107 actionmailer/lib/action_mailer/part.rb
  5. +0 −55 actionmailer/lib/action_mailer/part_container.rb
  6. +1 −1 actionmailer/lib/action_mailer/test_case.rb
  7. +0 −5 actionmailer/lib/action_mailer/vendor/tmail-1.2.3/tmail.rb
  8. +0 −426 actionmailer/lib/action_mailer/vendor/tmail-1.2.3/tmail/address.rb
  9. +0 −46 actionmailer/lib/action_mailer/vendor/tmail-1.2.3/tmail/attachments.rb
  10. +0 −46 actionmailer/lib/action_mailer/vendor/tmail-1.2.3/tmail/base64.rb
  11. +0 −41 actionmailer/lib/action_mailer/vendor/tmail-1.2.3/tmail/compat.rb
  12. +0 −67 actionmailer/lib/action_mailer/vendor/tmail-1.2.3/tmail/config.rb
  13. +0 −63 actionmailer/lib/action_mailer/vendor/tmail-1.2.3/tmail/core_extensions.rb
  14. +0 −581 actionmailer/lib/action_mailer/vendor/tmail-1.2.3/tmail/encode.rb
  15. +0 −960 actionmailer/lib/action_mailer/vendor/tmail-1.2.3/tmail/header.rb
  16. +0 −9 actionmailer/lib/action_mailer/vendor/tmail-1.2.3/tmail/index.rb
  17. +0 −1,130 actionmailer/lib/action_mailer/vendor/tmail-1.2.3/tmail/interface.rb
  18. +0 −3 actionmailer/lib/action_mailer/vendor/tmail-1.2.3/tmail/loader.rb
  19. +0 −579 actionmailer/lib/action_mailer/vendor/tmail-1.2.3/tmail/mail.rb
  20. +0 −495 actionmailer/lib/action_mailer/vendor/tmail-1.2.3/tmail/mailbox.rb
  21. +0 −6 actionmailer/lib/action_mailer/vendor/tmail-1.2.3/tmail/main.rb
  22. +0 −3 actionmailer/lib/action_mailer/vendor/tmail-1.2.3/tmail/mbox.rb
  23. +0 −248 actionmailer/lib/action_mailer/vendor/tmail-1.2.3/tmail/net.rb
  24. +0 −132 actionmailer/lib/action_mailer/vendor/tmail-1.2.3/tmail/obsolete.rb
  25. +0 −1,478 actionmailer/lib/action_mailer/vendor/tmail-1.2.3/tmail/parser.rb
  26. +0 −379 actionmailer/lib/action_mailer/vendor/tmail-1.2.3/tmail/port.rb
  27. +0 −118 actionmailer/lib/action_mailer/vendor/tmail-1.2.3/tmail/quoting.rb
  28. +0 −58 actionmailer/lib/action_mailer/vendor/tmail-1.2.3/tmail/require_arch.rb
  29. +0 −49 actionmailer/lib/action_mailer/vendor/tmail-1.2.3/tmail/scanner.rb
  30. +0 −261 actionmailer/lib/action_mailer/vendor/tmail-1.2.3/tmail/scanner_r.rb
  31. +0 −280 actionmailer/lib/action_mailer/vendor/tmail-1.2.3/tmail/stringio.rb
  32. +0 −337 actionmailer/lib/action_mailer/vendor/tmail-1.2.3/tmail/utils.rb
  33. +0 −39 actionmailer/lib/action_mailer/vendor/tmail-1.2.3/tmail/version.rb
  34. +0 −18 actionmailer/lib/action_mailer/vendor/tmail.rb
  35. +36 −0 actionmailer/lib/action_mailer/vendor/tmail_compat.rb
  36. +3 −3 actionmailer/test/asset_host_test.rb
  37. +1 −1 actionmailer/test/mail_helper_test.rb
  38. +42 −20 actionmailer/test/mail_layout_test.rb
  39. +19 −9 actionmailer/test/mail_render_test.rb
  40. +32 −37 actionmailer/test/mail_service_test.rb
  41. +8 −4 actionmailer/test/quoting_test.rb
  42. +2 −2 actionmailer/test/test_helper_test.rb
  43. +4 −3 actionmailer/test/tmail_test.rb
  44. +1 −1 actionmailer/test/url_test.rb
@@ -53,4 +53,5 @@ module Net
autoload :MailHelper, 'action_mailer/mail_helper'
-require 'action_mailer/vendor/tmail'
+require '/Users/mikel/ruby_programs/mail/lib/mail'
+require 'action_mailer/vendor/tmail_compat'
@@ -251,7 +251,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, Quoting, Utils
+ include AdvAttrAccessor, Quoting, Utils
include AbstractController::RenderingController
include AbstractController::LocalizedCache
@@ -366,6 +366,12 @@ def mailer_name(value = nil)
# Alias controller_path to mailer_name so render :partial in views work.
alias :controller_path :mailer_name
+ def part(params)
+ part = Mail::Part.new(params)
+ yield part
+ self.parts << part
+ end
+
class << self
attr_writer :mailer_name
@@ -411,7 +417,7 @@ def method_missing(method_symbol, *parameters) #:nodoc:
# end
def receive(raw_email)
logger.info "Received mail:\n #{raw_email}" unless logger.nil?
- mail = TMail::Mail.parse(raw_email)
+ mail = Mail.parse(raw_email)
mail.base64_decode
new.receive(mail)
end
@@ -456,7 +462,7 @@ def initialize(method_name=nil, *parameters) #:nodoc:
end
# Initialize the mailer via the given +method_name+. The body will be
- # rendered and a new TMail::Mail object created.
+ # rendered and a new Mail object created.
def create!(method_name, *parameters) #:nodoc:
initialize_defaults(method_name)
__send__(method_name, *parameters)
@@ -472,7 +478,7 @@ def create!(method_name, *parameters) #:nodoc:
@mail = create_mail
end
- # Delivers a TMail::Mail object. By default, it delivers the cached mail
+ # Delivers a Mail object. By default, it delivers the cached mail
# object (from the <tt>create!</tt> method). If no cached mail object exists, and
# no alternate has been given as the parameter, this will fail.
def deliver!(mail = @mail)
@@ -520,18 +526,18 @@ def create_parts
super # Run deprecation hooks
if String === response_body
- @parts.unshift Part.new(
- :content_type => "text/plain",
- :disposition => "inline",
- :charset => charset,
+ @parts.unshift Mail::Part.new(
+ :content_type => ["text", "plain", {:charset => charset}],
+ :content_disposition => "inline",
:body => response_body
)
else
self.class.template_root.find_all(@template, {}, mailer_name).each do |template|
- @parts << Part.new(
- :content_type => template.mime_type ? template.mime_type.to_s : "text/plain",
- :disposition => "inline",
- :charset => charset,
+ 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)
)
end
@@ -551,8 +557,8 @@ def sort_parts(parts, order = [])
order = order.collect { |s| s.downcase }
parts = parts.sort do |a, b|
- a_ct = a.content_type.downcase
- b_ct = b.content_type.downcase
+ a_ct = a.content_type.content_type.downcase
+ b_ct = b.content_type.content_type.downcase
a_in = order.include? a_ct
b_in = order.include? b_ct
@@ -577,7 +583,7 @@ def sort_parts(parts, order = [])
end
def create_mail
- m = TMail::Mail.new
+ m = Mail.new
m.subject, = quote_any_if_necessary(charset, subject)
m.to, m.from = quote_any_address_if_necessary(charset, recipients, from)
@@ -599,7 +605,7 @@ def create_mail
m.body = normalize_new_lines(@parts.first.body)
else
@parts.each do |p|
- part = (TMail::Mail === p ? p : p.to_mail(self))
+ part = (Mail === p ? p : p.to_mail(self))
m.parts << part
end
@@ -612,5 +618,17 @@ def create_mail
@mail = m
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)]
+ end
+
+
end
end
@@ -15,8 +15,7 @@ class Smtp < Method
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'].address) || mail['from']
smtp = Net::SMTP.new(settings[:address], settings[:port])
smtp.enable_starttls_auto if settings[:enable_starttls_auto] && smtp.respond_to?(:enable_starttls_auto)
@@ -1,107 +0,0 @@
-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 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
- # into the body of a subpart you can do it with the mailer's +render+ method
- # and assign the result here.
- adv_attr_accessor :body
-
- # Specify the charset for this subpart. By default, it will be the charset
- # of the containing part or mailer.
- adv_attr_accessor :charset
-
- # The content disposition of this part, typically either "inline" or
- # "attachment".
- adv_attr_accessor :content_disposition
-
- # The content type of the part.
- adv_attr_accessor :content_type
-
- # The filename to use for this subpart (usually for attachments).
- adv_attr_accessor :filename
-
- # Accessor for specifying additional headers to include with this part.
- adv_attr_accessor :headers
-
- # The transfer encoding to use for this subpart, like "base64" or
- # "quoted-printable".
- adv_attr_accessor :transfer_encoding
-
- # Create a new part from the given +params+ hash. The valid params keys
- # correspond to the accessors.
- def initialize(params)
- @content_type = params[:content_type]
- @content_disposition = params[:disposition] || "inline"
- @charset = params[:charset]
- @body = params[:body]
- @filename = params[:filename]
- @transfer_encoding = params[:transfer_encoding] || "quoted-printable"
- @headers = params[:headers] || {}
- @parts = []
- end
-
- # Convert the part to a mail object which can be included in the parts
- # list of another mail object.
- def to_mail(defaults)
- part = TMail::Mail.new
-
- real_content_type, ctype_attrs = parse_content_type(defaults)
-
- if @parts.empty?
- part.content_transfer_encoding = transfer_encoding || "quoted-printable"
- case (transfer_encoding || "").downcase
- when "base64" then
- part.body = TMail::Base64.folding_encode(body)
- when "quoted-printable"
- part.body = [normalize_new_lines(body)].pack("M*")
- else
- part.body = body
- end
-
- # Always set the content_type after setting the body and or parts!
- # Also don't set filename and name when there is none (like in
- # non-attachment parts)
- if content_disposition == "attachment"
- ctype_attrs.delete "charset"
- part.set_content_type(real_content_type, nil,
- squish("name" => filename).merge(ctype_attrs))
- part.set_content_disposition(content_disposition,
- squish("filename" => filename).merge(ctype_attrs))
- else
- part.set_content_type(real_content_type, nil, ctype_attrs)
- part.set_content_disposition(content_disposition)
- end
- else
- if String === body
- @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
- end
-
- headers.each { |k,v| part[k] = v }
-
- part
- end
-
- private
- def squish(values={})
- values.delete_if { |k,v| v.nil? }
- end
- end
-end
@@ -1,55 +0,0 @@
-module ActionMailer
- # Accessors and helpers that ActionMailer::Base and ActionMailer::Part have
- # in common. Using these helpers you can easily add subparts or attachments
- # to your message:
- #
- # def my_mail_message(...)
- # ...
- # part "text/plain" do |p|
- # p.body "hello, world"
- # p.transfer_encoding "base64"
- # end
- #
- # attachment "image/jpg" do |a|
- # a.body = File.read("hello.jpg")
- # a.filename = "hello.jpg"
- # end
- # end
- module PartContainer
- # The list of subparts of this container
- attr_reader :parts
-
- # 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
- part = 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)
- params = { :content_type => params } if String === params
- params = { :disposition => "attachment",
- :transfer_encoding => "base64" }.merge(params)
- part(params, &block)
- end
-
- private
-
- 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)]
- end
-
- end
-end
@@ -43,7 +43,7 @@ def initialize_test_deliveries
end
def set_expected_mail
- @expected = TMail::Mail.new
+ @expected = Mail.new
@expected.set_content_type "text", "plain", { "charset" => charset }
@expected.mime_version = '1.0'
end
@@ -1,5 +0,0 @@
-require 'tmail/version'
-require 'tmail/mail'
-require 'tmail/mailbox'
-require 'tmail/core_extensions'
-require 'tmail/net'
Oops, something went wrong. Retry.

0 comments on commit 15d7cac

Please sign in to comment.