generate missing text parts on incoming messages
fixes CNVS-19005 test plan - reply to an email from canvas with an email that does not have a text part - ensure that the posted discussion/conversation/whatever does not include html tags in the posted text Change-Id: I3223f10600e84aa0fb44f13435165557aaf59603 Reviewed-on: https://gerrit.instructure.com/53071 Tested-by: Jenkins Reviewed-by: Andrew Butterfield <abutterfield@instructure.com> QA-Review: Steven Shepherd <sshepherd@instructure.com> Product-Review: Joel Hough <joel@instructure.com>
This commit is contained in:
parent
2d312adf36
commit
1c5a640f44
|
@ -87,16 +87,27 @@ module IncomingMailProcessor
|
|||
text_part = incoming_message.text_part
|
||||
|
||||
html_body = self.class.utf8ify(html_part.body.decoded, html_part.charset) if html_part
|
||||
body = self.class.utf8ify(text_part.body.decoded, text_part.charset)
|
||||
text_body = self.class.utf8ify(text_part.body.decoded, text_part.charset) if text_part
|
||||
else
|
||||
body = self.class.utf8ify(incoming_message.body.decoded, incoming_message.charset)
|
||||
case incoming_message.mime_type
|
||||
when 'text/plain'
|
||||
text_body = self.class.utf8ify(incoming_message.body.decoded, incoming_message.charset)
|
||||
when 'text/html'
|
||||
html_body = self.class.utf8ify(incoming_message.body.decoded, incoming_message.charset)
|
||||
else
|
||||
raise "Unrecognized Content-Type: #{incoming_message.mime_type.inspect}"
|
||||
end
|
||||
end
|
||||
|
||||
if !html_body
|
||||
html_body = self.class.format_message(body).first
|
||||
if html_body && !text_body
|
||||
text_body = self.class.html_to_text(html_body)
|
||||
end
|
||||
|
||||
return body, html_body
|
||||
if text_body && !html_body
|
||||
html_body = self.class.format_message(text_body).first
|
||||
end
|
||||
|
||||
return text_body, html_body
|
||||
end
|
||||
|
||||
def self.mailbox_keys
|
||||
|
|
|
@ -63,11 +63,11 @@ describe IncomingMailProcessor::IncomingMessageProcessor do
|
|||
def test_message (filename)
|
||||
message = get_processed_message(filename)
|
||||
|
||||
text_body = message.body.strip!
|
||||
text_body.should == get_expected_text(filename)
|
||||
text_body = message.body.strip
|
||||
text_body.should == get_expected_text(filename).strip
|
||||
|
||||
html_body = message.html_body.strip!
|
||||
html_body.should == get_expected_html(filename)
|
||||
html_body = message.html_body.strip
|
||||
html_body.should == get_expected_html(filename).strip
|
||||
end
|
||||
|
||||
def get_processed_message(name)
|
||||
|
@ -128,7 +128,9 @@ describe IncomingMailProcessor::IncomingMessageProcessor do
|
|||
|
||||
describe "#process_single" do
|
||||
it "should not choke on invalid UTF-8" do
|
||||
IncomingMessageProcessor.new(message_handler, error_reporter).process_single(Mail.new { body "he\xffllo".force_encoding(Encoding::BINARY) }, '')
|
||||
IncomingMessageProcessor.new(message_handler, error_reporter).process_single(Mail.new {
|
||||
content_type 'text/plain; charset=UTF-8'
|
||||
body "he\xffllo".force_encoding(Encoding::BINARY) }, '')
|
||||
|
||||
message_handler.body.should == "hello"
|
||||
message_handler.html_body.should == "hello"
|
||||
|
@ -169,6 +171,26 @@ describe IncomingMailProcessor::IncomingMessageProcessor do
|
|||
IncomingMessageProcessor.new(message_handler, error_reporter).process_single(incoming_bounce_message, '')
|
||||
end
|
||||
|
||||
it "creates text body from html only messages" do
|
||||
IncomingMessageProcessor.new(message_handler, error_reporter).process_single(Mail.new {
|
||||
content_type 'text/html; charset=UTF-8'
|
||||
body '<h1>This is HTML</h1>'
|
||||
}, '')
|
||||
message_handler.body.should == "************\nThis is HTML\n************"
|
||||
message_handler.html_body.should == '<h1>This is HTML</h1>'
|
||||
end
|
||||
|
||||
it "creates missing text part from html part" do
|
||||
IncomingMessageProcessor.new(message_handler, error_reporter).process_single(Mail.new {
|
||||
html_part do
|
||||
content_type 'text/html; charset=UTF-8'
|
||||
body '<h1>This is HTML</h1>'
|
||||
end
|
||||
}, '')
|
||||
message_handler.body.should == "************\nThis is HTML\n************"
|
||||
message_handler.html_body.should == '<h1>This is HTML</h1>'
|
||||
end
|
||||
|
||||
it "works with multipart emails with no html part" do
|
||||
test_message('multipart_mixed_no_html_part.eml')
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue