From 841cec1bc13a6258f2b2f55ba9bad8da91847bee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Fri, 11 Mar 2016 18:51:53 +0100 Subject: [PATCH] FIX: support emails in with weird encoding --- lib/email/receiver.rb | 4 +++- spec/components/email/receiver_spec.rb | 3 +++ spec/fixtures/emails/reply_with_weird_encoding.eml | 9 +++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 spec/fixtures/emails/reply_with_weird_encoding.eml diff --git a/lib/email/receiver.rb b/lib/email/receiver.rb index 24eb6f7cf..9906e7e49 100644 --- a/lib/email/receiver.rb +++ b/lib/email/receiver.rb @@ -166,7 +166,9 @@ module Email def try_to_encode(string, encoding) string.encode("UTF-8", encoding) - rescue Encoding::InvalidByteSequenceError, Encoding::UndefinedConversionError + rescue Encoding::InvalidByteSequenceError, + Encoding::UndefinedConversionError, + Encoding::ConverterNotFoundError nil end diff --git a/spec/components/email/receiver_spec.rb b/spec/components/email/receiver_spec.rb index 697231e43..9225e8277 100644 --- a/spec/components/email/receiver_spec.rb +++ b/spec/components/email/receiver_spec.rb @@ -109,6 +109,9 @@ describe Email::Receiver do expect { process(:chinese_reply) }.to change { topic.posts.count } 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 it "prefers text over html" do diff --git a/spec/fixtures/emails/reply_with_weird_encoding.eml b/spec/fixtures/emails/reply_with_weird_encoding.eml new file mode 100644 index 000000000..c764584e8 --- /dev/null +++ b/spec/fixtures/emails/reply_with_weird_encoding.eml @@ -0,0 +1,9 @@ +Return-Path: +From: Foo Bar +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.