FIX: support emails in with weird encoding

This commit is contained in:
Régis Hanol 2016-03-11 18:51:53 +01:00
parent 01f2f05f2d
commit 841cec1bc1
3 changed files with 15 additions and 1 deletions

View File

@ -166,7 +166,9 @@ module Email
def try_to_encode(string, encoding) def try_to_encode(string, encoding)
string.encode("UTF-8", encoding) string.encode("UTF-8", encoding)
rescue Encoding::InvalidByteSequenceError, Encoding::UndefinedConversionError rescue Encoding::InvalidByteSequenceError,
Encoding::UndefinedConversionError,
Encoding::ConverterNotFoundError
nil nil
end end

View File

@ -109,6 +109,9 @@ describe Email::Receiver do
expect { process(:chinese_reply) }.to change { topic.posts.count } expect { process(:chinese_reply) }.to change { topic.posts.count }
expect(topic.posts.last.raw).to eq("您好! 你今天好吗?") expect(topic.posts.last.raw).to eq("您好! 你今天好吗?")
expect { process(:reply_with_weird_encoding) }.to change { topic.posts.count }
expect(topic.posts.last.raw).to eq("This is a reply with a weird encoding.")
end end
it "prefers text over html" do it "prefers text over html" do

View File

@ -0,0 +1,9 @@
Return-Path: <discourse@bar.com>
From: Foo Bar <discourse@bar.com>
To: reply+4f97315cc828096c9cb34c6f1a0d6fe8@bar.com
Date: Fri, 15 Jan 2016 00:12:43 +0100
Message-ID: <42@foo.bar.mail>
Mime-Version: 1.0
Content-Type: text/plain; charset=unicode-1-1-utf-7
This is a reply with a weird encoding.