diff --git a/lib/email/receiver.rb b/lib/email/receiver.rb index c644950cee4..c15f8c42739 100644 --- a/lib/email/receiver.rb +++ b/lib/email/receiver.rb @@ -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) diff --git a/spec/components/email/receiver_spec.rb b/spec/components/email/receiver_spec.rb index c5ef25543ec..a0431606773 100644 --- a/spec/components/email/receiver_spec.rb +++ b/spec/components/email/receiver_spec.rb @@ -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