mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
More updates... 45 errors left to get it working with Mail gem
This commit is contained in:
parent
15d7cac282
commit
539d9b355f
9 changed files with 94 additions and 72 deletions
|
@ -366,10 +366,27 @@ module ActionMailer #:nodoc:
|
||||||
# Alias controller_path to mailer_name so render :partial in views work.
|
# Alias controller_path to mailer_name so render :partial in views work.
|
||||||
alias :controller_path :mailer_name
|
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)
|
def part(params)
|
||||||
|
params = {:content_type => params} if String === params
|
||||||
|
if custom_headers = params.delete(:headers)
|
||||||
|
STDERR.puts("Passing custom headers with :headers => {} is deprecated. Please just pass in custom headers directly.")
|
||||||
|
params = params.merge(custom_headers)
|
||||||
|
end
|
||||||
part = Mail::Part.new(params)
|
part = Mail::Part.new(params)
|
||||||
yield part
|
yield part if block_given?
|
||||||
self.parts << part
|
@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
|
end
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
|
@ -417,8 +434,7 @@ module ActionMailer #:nodoc:
|
||||||
# end
|
# end
|
||||||
def receive(raw_email)
|
def receive(raw_email)
|
||||||
logger.info "Received mail:\n #{raw_email}" unless logger.nil?
|
logger.info "Received mail:\n #{raw_email}" unless logger.nil?
|
||||||
mail = Mail.parse(raw_email)
|
mail = Mail.new(raw_email)
|
||||||
mail.base64_decode
|
|
||||||
new.receive(mail)
|
new.receive(mail)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -598,26 +614,32 @@ module ActionMailer #:nodoc:
|
||||||
real_content_type, ctype_attrs = parse_content_type
|
real_content_type, ctype_attrs = parse_content_type
|
||||||
|
|
||||||
if @parts.empty?
|
if @parts.empty?
|
||||||
m.set_content_type(real_content_type, nil, ctype_attrs)
|
main_type, sub_type = split_content_type(real_content_type)
|
||||||
|
m.content_type(main_type, sub_type, ctype_attrs)
|
||||||
m.body = normalize_new_lines(body)
|
m.body = normalize_new_lines(body)
|
||||||
elsif @parts.size == 1 && @parts.first.parts.empty?
|
elsif @parts.size == 1 && @parts.first.parts.empty?
|
||||||
m.set_content_type(real_content_type, nil, ctype_attrs)
|
main_type, sub_type = split_content_type(real_content_type)
|
||||||
|
m.content_type(main_type, sub_type, ctype_attrs)
|
||||||
m.body = normalize_new_lines(@parts.first.body)
|
m.body = normalize_new_lines(@parts.first.body)
|
||||||
else
|
else
|
||||||
@parts.each do |p|
|
@parts.each do |p|
|
||||||
part = (Mail === p ? p : p.to_mail(self))
|
m.parts << p
|
||||||
m.parts << part
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if real_content_type =~ /multipart/
|
if real_content_type =~ /multipart/
|
||||||
ctype_attrs.delete "charset"
|
ctype_attrs.delete "charset"
|
||||||
m.set_content_type(real_content_type, nil, ctype_attrs)
|
main_type, sub_type = split_content_type(real_content_type)
|
||||||
|
m.content_type([main_type.to_s, sub_type.to_s, ctype_attrs])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@mail = m
|
@mail = m
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def split_content_type(ct)
|
||||||
|
ct.to_s.split("/")
|
||||||
|
end
|
||||||
|
|
||||||
def parse_content_type(defaults=nil)
|
def parse_content_type(defaults=nil)
|
||||||
if content_type.blank?
|
if content_type.blank?
|
||||||
return defaults ?
|
return defaults ?
|
||||||
|
|
|
@ -44,7 +44,7 @@ module ActionMailer
|
||||||
|
|
||||||
def set_expected_mail
|
def set_expected_mail
|
||||||
@expected = Mail.new
|
@expected = Mail.new
|
||||||
@expected.set_content_type "text", "plain", { "charset" => charset }
|
@expected.content_type ["text", "plain", { "charset" => charset }]
|
||||||
@expected.mime_version = '1.0'
|
@expected.mime_version = '1.0'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -2,22 +2,8 @@
|
||||||
# Created in 1.2 of Mail. Will be deprecated
|
# Created in 1.2 of Mail. Will be deprecated
|
||||||
STDERR.puts("DEPRECATION WARNING, Mail running in TMail compatibility mode. This will be deprecated soon.")
|
STDERR.puts("DEPRECATION WARNING, Mail running in TMail compatibility mode. This will be deprecated soon.")
|
||||||
|
|
||||||
module Mail
|
|
||||||
|
|
||||||
def Mail.parse(string)
|
|
||||||
STDERR.puts("DEPRECATION WARNING, Mail.parse(string) is deprecated, please use Mail.new")
|
|
||||||
::Mail.new(string)
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
class Mail::Message
|
class Mail::Message
|
||||||
|
|
||||||
def set_content_type(*args)
|
|
||||||
STDERR.puts("DEPRECATION WARNING, Message#set_content_type is deprecated, please use Message#content_type")
|
|
||||||
content_type(args)
|
|
||||||
end
|
|
||||||
|
|
||||||
def set_content_disposition(*args)
|
def set_content_disposition(*args)
|
||||||
STDERR.puts("DEPRECATION WARNING, Message#set_content_disposition is deprecated, please use Message#content_disposition")
|
STDERR.puts("DEPRECATION WARNING, Message#set_content_disposition is deprecated, please use Message#content_disposition")
|
||||||
content_disposition(args)
|
content_disposition(args)
|
||||||
|
|
BIN
actionmailer/test/fixtures/attachments/test.jpg
vendored
Normal file
BIN
actionmailer/test/fixtures/attachments/test.jpg
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 2 KiB |
|
@ -56,7 +56,7 @@ end
|
||||||
class MailerHelperTest < Test::Unit::TestCase
|
class MailerHelperTest < Test::Unit::TestCase
|
||||||
def new_mail( charset="utf-8" )
|
def new_mail( charset="utf-8" )
|
||||||
mail = Mail.new
|
mail = Mail.new
|
||||||
mail.set_content_type "text", "plain", { "charset" => charset } if charset
|
mail.content_type ["text", "plain", { "charset" => charset }]
|
||||||
mail
|
mail
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -251,8 +251,8 @@ class TestMailer < ActionMailer::Base
|
||||||
subject "custom header in attachment"
|
subject "custom header in attachment"
|
||||||
from "test@example.com"
|
from "test@example.com"
|
||||||
content_type "multipart/related"
|
content_type "multipart/related"
|
||||||
part :content_type => "text/html", :body => 'yo'
|
part :content_type => "text/html", :body => 'yo'
|
||||||
attachment :content_type => "image/jpeg",:filename => "test.jpeg", :body => "i am not a real picture", :headers => { 'Content-ID' => '<test@test.com>' }
|
attachment :content_type => "image/jpeg", :filename => File.join(File.dirname(__FILE__), "fixtures", "attachments", "test.jpg"), :body => "i am not a real picture", :headers => { 'Content-ID' => '<test@test.com>' }
|
||||||
end
|
end
|
||||||
|
|
||||||
def unnamed_attachment(recipient)
|
def unnamed_attachment(recipient)
|
||||||
|
@ -272,11 +272,12 @@ class TestMailer < ActionMailer::Base
|
||||||
bcc "Five: Six <test@example.com>"
|
bcc "Five: Six <test@example.com>"
|
||||||
render :text => "testing"
|
render :text => "testing"
|
||||||
end
|
end
|
||||||
|
require 'ruby-debug'
|
||||||
def custom_content_type_attributes
|
def custom_content_type_attributes
|
||||||
recipients "no.one@nowhere.test"
|
recipients "no.one@nowhere.test"
|
||||||
subject "custom content types"
|
subject "custom content types"
|
||||||
from "some.one@somewhere.test"
|
from "some.one@somewhere.test"
|
||||||
|
debugger
|
||||||
content_type "text/plain; format=flowed"
|
content_type "text/plain; format=flowed"
|
||||||
render :text => "testing"
|
render :text => "testing"
|
||||||
end
|
end
|
||||||
|
@ -322,7 +323,7 @@ class ActionMailerTest < Test::Unit::TestCase
|
||||||
mail = Mail.new
|
mail = Mail.new
|
||||||
mail.mime_version = "1.0"
|
mail.mime_version = "1.0"
|
||||||
if charset
|
if charset
|
||||||
mail.set_content_type "text", "plain", { "charset" => charset }
|
mail.content_type ["text", "plain", { "charset" => charset }]
|
||||||
end
|
end
|
||||||
mail
|
mail
|
||||||
end
|
end
|
||||||
|
@ -375,6 +376,7 @@ class ActionMailerTest < Test::Unit::TestCase
|
||||||
def test_attachment_with_custom_header
|
def test_attachment_with_custom_header
|
||||||
created = nil
|
created = nil
|
||||||
assert_nothing_raised { created = TestMailer.create_attachment_with_custom_header(@recipient) }
|
assert_nothing_raised { created = TestMailer.create_attachment_with_custom_header(@recipient) }
|
||||||
|
created.encoded
|
||||||
assert created.parts.any? { |p| p.header['content-id'].to_s == "<test@test.com>" }
|
assert created.parts.any? { |p| p.header['content-id'].to_s == "<test@test.com>" }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -440,12 +442,12 @@ class ActionMailerTest < Test::Unit::TestCase
|
||||||
assert_nothing_raised { created = TestMailer.create_custom_templating_extension(@recipient) }
|
assert_nothing_raised { created = TestMailer.create_custom_templating_extension(@recipient) }
|
||||||
assert_not_nil created
|
assert_not_nil created
|
||||||
assert_equal 2, created.parts.length
|
assert_equal 2, created.parts.length
|
||||||
assert_equal 'text/plain', created.parts[0].content_type
|
assert_equal 'text/plain', created.parts[0].content_type.content_type
|
||||||
assert_equal 'text/html', created.parts[1].content_type
|
assert_equal 'text/html', created.parts[1].content_type.content_type
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_cancelled_account
|
def test_cancelled_account
|
||||||
expected = new_mail
|
expected = new_mail('US-ASCII')
|
||||||
expected.to = @recipient
|
expected.to = @recipient
|
||||||
expected.subject = "[Cancelled] Goodbye #{@recipient}"
|
expected.subject = "[Cancelled] Goodbye #{@recipient}"
|
||||||
expected.body = "Goodbye, Mr. #{@recipient}"
|
expected.body = "Goodbye, Mr. #{@recipient}"
|
||||||
|
@ -455,15 +457,21 @@ class ActionMailerTest < Test::Unit::TestCase
|
||||||
created = nil
|
created = nil
|
||||||
assert_nothing_raised { created = TestMailer.create_cancelled_account(@recipient) }
|
assert_nothing_raised { created = TestMailer.create_cancelled_account(@recipient) }
|
||||||
assert_not_nil created
|
assert_not_nil created
|
||||||
|
expected.message_id = '<123@456>'
|
||||||
|
created.message_id = '<123@456>'
|
||||||
assert_equal expected.encoded, created.encoded
|
assert_equal expected.encoded, created.encoded
|
||||||
|
|
||||||
assert_nothing_raised { TestMailer.deliver_cancelled_account(@recipient) }
|
assert_nothing_raised { TestMailer.deliver_cancelled_account(@recipient) }
|
||||||
assert_not_nil ActionMailer::Base.deliveries.first
|
assert_not_nil ActionMailer::Base.deliveries.first
|
||||||
assert_equal expected.encoded, ActionMailer::Base.deliveries.first.encoded
|
delivered = ActionMailer::Base.deliveries.first
|
||||||
|
expected.message_id = '<123@456>'
|
||||||
|
delivered.message_id = '<123@456>'
|
||||||
|
|
||||||
|
assert_equal expected.encoded, delivered.encoded
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_cc_bcc
|
def test_cc_bcc
|
||||||
expected = new_mail
|
expected = new_mail('US-ASCII')
|
||||||
expected.to = @recipient
|
expected.to = @recipient
|
||||||
expected.subject = "testing bcc/cc"
|
expected.subject = "testing bcc/cc"
|
||||||
expected.body = "Nothing to see here."
|
expected.body = "Nothing to see here."
|
||||||
|
@ -477,6 +485,8 @@ class ActionMailerTest < Test::Unit::TestCase
|
||||||
created = TestMailer.create_cc_bcc @recipient
|
created = TestMailer.create_cc_bcc @recipient
|
||||||
end
|
end
|
||||||
assert_not_nil created
|
assert_not_nil created
|
||||||
|
expected.message_id = '<123@456>'
|
||||||
|
created.message_id = '<123@456>'
|
||||||
assert_equal expected.encoded, created.encoded
|
assert_equal expected.encoded, created.encoded
|
||||||
|
|
||||||
assert_nothing_raised do
|
assert_nothing_raised do
|
||||||
|
@ -484,7 +494,11 @@ class ActionMailerTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
assert_not_nil ActionMailer::Base.deliveries.first
|
assert_not_nil ActionMailer::Base.deliveries.first
|
||||||
assert_equal expected.encoded, ActionMailer::Base.deliveries.first.encoded
|
delivered = ActionMailer::Base.deliveries.first
|
||||||
|
expected.message_id = '<123@456>'
|
||||||
|
delivered.message_id = '<123@456>'
|
||||||
|
|
||||||
|
assert_equal expected.encoded, delivered.encoded
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_reply_to
|
def test_reply_to
|
||||||
|
@ -636,7 +650,7 @@ Content-Type: text/plain; charset=iso-8859-1
|
||||||
|
|
||||||
The body
|
The body
|
||||||
EOF
|
EOF
|
||||||
mail = Mail.parse(msg)
|
mail = Mail.new(msg)
|
||||||
assert_equal "testing testing \326\244", mail.subject.decoded
|
assert_equal "testing testing \326\244", mail.subject.decoded
|
||||||
assert_equal "=?utf-8?Q?testing_testing_=D6=A4?=", mail.quoted_subject
|
assert_equal "=?utf-8?Q?testing_testing_=D6=A4?=", mail.quoted_subject
|
||||||
end
|
end
|
||||||
|
@ -649,7 +663,7 @@ Content-Type: text/plain; charset=iso-8859-1
|
||||||
|
|
||||||
The body
|
The body
|
||||||
EOF
|
EOF
|
||||||
mail = Mail.parse(msg)
|
mail = Mail.new(msg)
|
||||||
assert_equal "this == working?", mail.subject.decoded
|
assert_equal "this == working?", mail.subject.decoded
|
||||||
assert_equal "this == working?", mail.quoted_subject
|
assert_equal "this == working?", mail.quoted_subject
|
||||||
end
|
end
|
||||||
|
@ -663,7 +677,7 @@ Content-Transfer-Encoding: 7bit
|
||||||
|
|
||||||
The=3Dbody
|
The=3Dbody
|
||||||
EOF
|
EOF
|
||||||
mail = Mail.parse(msg)
|
mail = Mail.new(msg)
|
||||||
assert_equal "The=3Dbody", mail.body.decoded.strip
|
assert_equal "The=3Dbody", mail.body.decoded.strip
|
||||||
assert_equal "The=3Dbody", mail.quoted_body.strip
|
assert_equal "The=3Dbody", mail.quoted_body.strip
|
||||||
end
|
end
|
||||||
|
@ -677,7 +691,7 @@ Content-Transfer-Encoding: quoted-printable
|
||||||
|
|
||||||
The=3Dbody
|
The=3Dbody
|
||||||
EOF
|
EOF
|
||||||
mail = Mail.parse(msg)
|
mail = Mail.new(msg)
|
||||||
assert_equal "The=body", mail.body.decoded.strip
|
assert_equal "The=body", mail.body.decoded.strip
|
||||||
assert_equal "The=3Dbody", mail.quoted_body.strip
|
assert_equal "The=3Dbody", mail.quoted_body.strip
|
||||||
end
|
end
|
||||||
|
@ -691,7 +705,7 @@ Content-Transfer-Encoding: base64
|
||||||
|
|
||||||
VGhlIGJvZHk=
|
VGhlIGJvZHk=
|
||||||
EOF
|
EOF
|
||||||
mail = Mail.parse(msg)
|
mail = Mail.new(msg)
|
||||||
assert_equal "The body", mail.body.decoded.strip
|
assert_equal "The body", mail.body.decoded.strip
|
||||||
assert_equal "VGhlIGJvZHk=", mail.quoted_body.strip
|
assert_equal "VGhlIGJvZHk=", mail.quoted_body.strip
|
||||||
end
|
end
|
||||||
|
@ -763,7 +777,7 @@ EOF
|
||||||
|
|
||||||
def test_receive_attachments
|
def test_receive_attachments
|
||||||
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email2")
|
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email2")
|
||||||
mail = Mail.parse(fixture)
|
mail = Mail.new(fixture)
|
||||||
attachment = mail.attachments.last
|
attachment = mail.attachments.last
|
||||||
assert_equal "smime.p7s", attachment.original_filename
|
assert_equal "smime.p7s", attachment.original_filename
|
||||||
assert_equal "application/pkcs7-signature", attachment.content_type
|
assert_equal "application/pkcs7-signature", attachment.content_type
|
||||||
|
@ -771,21 +785,21 @@ EOF
|
||||||
|
|
||||||
def test_decode_attachment_without_charset
|
def test_decode_attachment_without_charset
|
||||||
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email3")
|
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email3")
|
||||||
mail = Mail.parse(fixture)
|
mail = Mail.new(fixture)
|
||||||
attachment = mail.attachments.last
|
attachment = mail.attachments.last
|
||||||
assert_equal 1026, attachment.read.length
|
assert_equal 1026, attachment.read.length
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_attachment_using_content_location
|
def test_attachment_using_content_location
|
||||||
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email12")
|
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email12")
|
||||||
mail = Mail.parse(fixture)
|
mail = Mail.new(fixture)
|
||||||
assert_equal 1, mail.attachments.length
|
assert_equal 1, mail.attachments.length
|
||||||
assert_equal "Photo25.jpg", mail.attachments.first.original_filename
|
assert_equal "Photo25.jpg", mail.attachments.first.original_filename
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_attachment_with_text_type
|
def test_attachment_with_text_type
|
||||||
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email13")
|
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email13")
|
||||||
mail = Mail.parse(fixture)
|
mail = Mail.new(fixture)
|
||||||
assert mail.has_attachments?
|
assert mail.has_attachments?
|
||||||
assert_equal 1, mail.attachments.length
|
assert_equal 1, mail.attachments.length
|
||||||
assert_equal "hello.rb", mail.attachments.first.original_filename
|
assert_equal "hello.rb", mail.attachments.first.original_filename
|
||||||
|
@ -793,19 +807,19 @@ EOF
|
||||||
|
|
||||||
def test_decode_part_without_content_type
|
def test_decode_part_without_content_type
|
||||||
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email4")
|
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email4")
|
||||||
mail = Mail.parse(fixture)
|
mail = Mail.new(fixture)
|
||||||
assert_nothing_raised { mail.body }
|
assert_nothing_raised { mail.body }
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_decode_message_without_content_type
|
def test_decode_message_without_content_type
|
||||||
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email5")
|
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email5")
|
||||||
mail = Mail.parse(fixture)
|
mail = Mail.new(fixture)
|
||||||
assert_nothing_raised { mail.body }
|
assert_nothing_raised { mail.body }
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_decode_message_with_incorrect_charset
|
def test_decode_message_with_incorrect_charset
|
||||||
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email6")
|
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email6")
|
||||||
mail = Mail.parse(fixture)
|
mail = Mail.new(fixture)
|
||||||
assert_nothing_raised { mail.body }
|
assert_nothing_raised { mail.body }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -858,14 +872,14 @@ EOF
|
||||||
|
|
||||||
mail = TestMailer.create_implicitly_multipart_example(@recipient)
|
mail = TestMailer.create_implicitly_multipart_example(@recipient)
|
||||||
assert_equal 3, mail.parts.length
|
assert_equal 3, mail.parts.length
|
||||||
assert_equal "1.0", mail.mime_version
|
assert_equal "1.0", mail.mime_version.decoded
|
||||||
assert_equal "multipart/alternative", mail.content_type
|
assert_equal "multipart/alternative", mail.content_type.content_type
|
||||||
assert_equal "application/x-yaml", mail.parts[0].content_type
|
assert_equal "application/x-yaml", mail.parts[0].content_type.content_type
|
||||||
assert_equal "utf-8", mail.parts[0].sub_header("content-type", "charset")
|
assert_equal "utf-8", mail.parts[0].content_type.parameters[:charset]
|
||||||
assert_equal "text/plain", mail.parts[1].content_type
|
assert_equal "text/plain", mail.parts[1].content_type.content_type
|
||||||
assert_equal "utf-8", mail.parts[1].sub_header("content-type", "charset")
|
assert_equal "utf-8", mail.parts[1].content_type.parameters[:charset]
|
||||||
assert_equal "text/html", mail.parts[2].content_type
|
assert_equal "text/html", mail.parts[2].content_type.content_type
|
||||||
assert_equal "utf-8", mail.parts[2].sub_header("content-type", "charset")
|
assert_equal "utf-8", mail.parts[2].content_type.parameters[:charset]
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_implicitly_multipart_messages_with_custom_order
|
def test_implicitly_multipart_messages_with_custom_order
|
||||||
|
@ -873,19 +887,19 @@ EOF
|
||||||
|
|
||||||
mail = TestMailer.create_implicitly_multipart_example(@recipient, nil, ["application/x-yaml", "text/plain"])
|
mail = TestMailer.create_implicitly_multipart_example(@recipient, nil, ["application/x-yaml", "text/plain"])
|
||||||
assert_equal 3, mail.parts.length
|
assert_equal 3, mail.parts.length
|
||||||
assert_equal "text/html", mail.parts[0].content_type
|
assert_equal "text/html", mail.parts[0].content_type.content_type
|
||||||
assert_equal "text/plain", mail.parts[1].content_type
|
assert_equal "text/plain", mail.parts[1].content_type.content_type
|
||||||
assert_equal "application/x-yaml", mail.parts[2].content_type
|
assert_equal "application/x-yaml", mail.parts[2].content_type.content_type
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_implicitly_multipart_messages_with_charset
|
def test_implicitly_multipart_messages_with_charset
|
||||||
mail = TestMailer.create_implicitly_multipart_example(@recipient, 'iso-8859-1')
|
mail = TestMailer.create_implicitly_multipart_example(@recipient, 'iso-8859-1')
|
||||||
|
|
||||||
assert_equal "multipart/alternative", mail.header['content-type'].body
|
assert_equal "multipart/alternative", mail.header['content-type'].content_type
|
||||||
|
|
||||||
assert_equal 'iso-8859-1', mail.parts[0].sub_header("content-type", "charset")
|
assert_equal 'iso-8859-1', mail.parts[0].content_type.parameters[:charset]
|
||||||
assert_equal 'iso-8859-1', mail.parts[1].sub_header("content-type", "charset")
|
assert_equal 'iso-8859-1', mail.parts[1].content_type.parameters[:charset]
|
||||||
assert_equal 'iso-8859-1', mail.parts[2].sub_header("content-type", "charset")
|
assert_equal 'iso-8859-1', mail.parts[2].content_type.parameters[:charset]
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_html_mail
|
def test_html_mail
|
||||||
|
@ -935,13 +949,13 @@ EOF
|
||||||
|
|
||||||
def test_recursive_multipart_processing
|
def test_recursive_multipart_processing
|
||||||
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email7")
|
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email7")
|
||||||
mail = Mail.parse(fixture)
|
mail = Mail.new(fixture)
|
||||||
assert_equal "This is the first part.\n\nAttachment: test.rb\nAttachment: test.pdf\n\n\nAttachment: smime.p7s\n", mail.body.decoded
|
assert_equal "This is the first part.\n\nAttachment: test.rb\nAttachment: test.pdf\n\n\nAttachment: smime.p7s\n", mail.body.decoded
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_decode_encoded_attachment_filename
|
def test_decode_encoded_attachment_filename
|
||||||
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email8")
|
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email8")
|
||||||
mail = Mail.parse(fixture)
|
mail = Mail.new(fixture)
|
||||||
attachment = mail.attachments.last
|
attachment = mail.attachments.last
|
||||||
|
|
||||||
expected = "01 Quien Te Dij\212at. Pitbull.mp3"
|
expected = "01 Quien Te Dij\212at. Pitbull.mp3"
|
||||||
|
@ -952,7 +966,7 @@ EOF
|
||||||
|
|
||||||
def test_decode_message_with_unknown_charset
|
def test_decode_message_with_unknown_charset
|
||||||
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email10")
|
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email10")
|
||||||
mail = Mail.parse(fixture)
|
mail = Mail.new(fixture)
|
||||||
assert_nothing_raised { mail.body }
|
assert_nothing_raised { mail.body }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -987,8 +1001,8 @@ EOF
|
||||||
|
|
||||||
def test_custom_content_type_attributes
|
def test_custom_content_type_attributes
|
||||||
mail = TestMailer.create_custom_content_type_attributes
|
mail = TestMailer.create_custom_content_type_attributes
|
||||||
assert_match %r{format=flowed}, mail['content-type'].to_s
|
assert_match %r{format=flowed}, mail.content_type.encoded
|
||||||
assert_match %r{charset=utf-8}, mail['content-type'].to_s
|
assert_match %r{charset=utf-8}, mail.content_type.encoded
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_return_path_with_create
|
def test_return_path_with_create
|
||||||
|
@ -1005,7 +1019,7 @@ EOF
|
||||||
|
|
||||||
def test_body_is_stored_as_an_ivar
|
def test_body_is_stored_as_an_ivar
|
||||||
mail = TestMailer.create_body_ivar(@recipient)
|
mail = TestMailer.create_body_ivar(@recipient)
|
||||||
assert_equal "body: foo\nbar: baz", mail.body
|
assert_equal "body: foo\nbar: baz", mail.body.encoded
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_starttls_is_enabled_if_supported
|
def test_starttls_is_enabled_if_supported
|
||||||
|
|
|
@ -65,14 +65,14 @@ class QuotingTest < Test::Unit::TestCase
|
||||||
# test an email that has been created using \r\n newlines, instead of
|
# test an email that has been created using \r\n newlines, instead of
|
||||||
# \n newlines.
|
# \n newlines.
|
||||||
def test_email_quoted_with_0d0a
|
def test_email_quoted_with_0d0a
|
||||||
mail = Mail.parse(IO.read("#{File.dirname(__FILE__)}/fixtures/raw_email_quoted_with_0d0a"))
|
mail = Mail.new(IO.read("#{File.dirname(__FILE__)}/fixtures/raw_email_quoted_with_0d0a"))
|
||||||
# CHANGED: subject returns an object now
|
# CHANGED: subject returns an object now
|
||||||
# assert_match %r{Elapsed time}, mail.body
|
# assert_match %r{Elapsed time}, mail.body
|
||||||
assert_match %r{Elapsed time}, mail.body.decoded
|
assert_match %r{Elapsed time}, mail.body.decoded
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_email_with_partially_quoted_subject
|
def test_email_with_partially_quoted_subject
|
||||||
mail = Mail.parse(IO.read("#{File.dirname(__FILE__)}/fixtures/raw_email_with_partially_quoted_subject"))
|
mail = Mail.new(IO.read("#{File.dirname(__FILE__)}/fixtures/raw_email_with_partially_quoted_subject"))
|
||||||
# CHANGED: subject returns an object now
|
# CHANGED: subject returns an object now
|
||||||
# assert_equal "Re: Test: \"\346\274\242\345\255\227\" mid \"\346\274\242\345\255\227\" tail", mail.subject
|
# assert_equal "Re: Test: \"\346\274\242\345\255\227\" mid \"\346\274\242\345\255\227\" tail", mail.subject
|
||||||
assert_equal "Re: Test: \"\346\274\242\345\255\227\" mid \"\346\274\242\345\255\227\" tail", mail.subject.decoded
|
assert_equal "Re: Test: \"\346\274\242\345\255\227\" mid \"\346\274\242\345\255\227\" tail", mail.subject.decoded
|
||||||
|
|
|
@ -14,7 +14,7 @@ class TMailMailTest < Test::Unit::TestCase
|
||||||
|
|
||||||
def test_nested_attachments_are_recognized_correctly
|
def test_nested_attachments_are_recognized_correctly
|
||||||
fixture = File.read("#{File.dirname(__FILE__)}/fixtures/raw_email_with_nested_attachment")
|
fixture = File.read("#{File.dirname(__FILE__)}/fixtures/raw_email_with_nested_attachment")
|
||||||
mail = Mail.parse(fixture)
|
mail = Mail.new(fixture)
|
||||||
assert_equal 2, mail.attachments.length
|
assert_equal 2, mail.attachments.length
|
||||||
assert_equal "image/png", mail.attachments.first.content_type
|
assert_equal "image/png", mail.attachments.first.content_type
|
||||||
assert_equal 1902, mail.attachments.first.length
|
assert_equal 1902, mail.attachments.first.length
|
||||||
|
|
|
@ -34,7 +34,7 @@ class ActionMailerUrlTest < Test::Unit::TestCase
|
||||||
mail = Mail.new
|
mail = Mail.new
|
||||||
mail.mime_version = "1.0"
|
mail.mime_version = "1.0"
|
||||||
if charset
|
if charset
|
||||||
mail.set_content_type "text", "plain", { "charset" => charset }
|
mail.content_type ["text", "plain", { "charset" => charset }]
|
||||||
end
|
end
|
||||||
mail
|
mail
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue