mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 17:46:05 -05:00
Have parse_body() recover from ASCII-8BIT encoding
Added a test to make sure that the result can be passed into TextCleaner (which expects UTF-8)
This commit is contained in:
parent
1c9f6159cd
commit
8ddd90daa4
2 changed files with 14 additions and 3 deletions
|
@ -95,6 +95,7 @@ module Email
|
|||
|
||||
def parse_body(message)
|
||||
body = select_body message
|
||||
encoding = body.encoding
|
||||
raise EmptyEmailError if body.strip.blank?
|
||||
|
||||
body = discourse_email_trimmer body
|
||||
|
@ -103,7 +104,7 @@ module Email
|
|||
body = EmailReplyParser.parse_reply body
|
||||
raise EmptyEmailError if body.strip.blank?
|
||||
|
||||
body
|
||||
body.force_encoding(encoding).encode("UTF-8")
|
||||
end
|
||||
|
||||
def select_body(message)
|
||||
|
|
|
@ -45,14 +45,14 @@ describe Email::Receiver do
|
|||
I18n.expects(:t).with('user_notifications.previous_discussion').returns('כלטוב')
|
||||
|
||||
# The force_encoding call is only needed for the test - it is passed on fine to the cooked post
|
||||
test_parse_body(fixture_file("emails/hebrew.eml")).force_encoding("UTF-8").should == "שלום"
|
||||
test_parse_body(fixture_file("emails/hebrew.eml")).should == "שלום"
|
||||
end
|
||||
|
||||
it "supports a BIG5-encoded reply" do
|
||||
I18n.expects(:t).with('user_notifications.previous_discussion').returns('媽!我上電視了!')
|
||||
|
||||
# The force_encoding call is only needed for the test - it is passed on fine to the cooked post
|
||||
test_parse_body(fixture_file("emails/big5.eml")).force_encoding("UTF-8").should == "媽!我上電視了!"
|
||||
test_parse_body(fixture_file("emails/big5.eml")).should == "媽!我上電視了!"
|
||||
end
|
||||
|
||||
it "removes 'via' lines if they match the site title" do
|
||||
|
@ -77,6 +77,16 @@ it there without worrying about it too much, imo.
|
|||
Thanks for listening."
|
||||
)
|
||||
end
|
||||
|
||||
it "converts back to UTF-8 at the end" do
|
||||
result = test_parse_body(fixture_file("emails/big5.eml"))
|
||||
result.encoding.should == Encoding::UTF_8
|
||||
|
||||
# should not throw
|
||||
TextCleaner.normalize_whitespaces(
|
||||
test_parse_body(fixture_file("emails/big5.eml"))
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
describe "posting replies" do
|
||||
|
|
Loading…
Reference in a new issue