From c86b06e3fad2f3a2ac5ce6ee0ca9ae5601d82c10 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Mon, 4 Nov 2013 15:30:24 -0500 Subject: [PATCH] Fix for non-english email polling. --- lib/email/receiver.rb | 2 +- spec/components/email/receiver_spec.rb | 11 +++++++++++ spec/fixtures/emails/hebrew.eml | 17 +++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 spec/fixtures/emails/hebrew.eml diff --git a/lib/email/receiver.rb b/lib/email/receiver.rb index c580b5ce1..02e0004c5 100644 --- a/lib/email/receiver.rb +++ b/lib/email/receiver.rb @@ -26,7 +26,7 @@ module Email return Email::Receiver.results[:unprocessable] if @body.blank? # Then run the github EmailReplyParser on it in case we didn't catch it - @body = EmailReplyParser.read(@body).visible_text + @body = EmailReplyParser.read(@body).visible_text.force_encoding('UTF-8') discourse_email_parser diff --git a/spec/components/email/receiver_spec.rb b/spec/components/email/receiver_spec.rb index d999b773f..8c382f954 100644 --- a/spec/components/email/receiver_spec.rb +++ b/spec/components/email/receiver_spec.rb @@ -50,6 +50,17 @@ stripped from my reply?") end end + describe "It supports a non english reply" do + let(:hebrew) { File.read("#{Rails.root}/spec/fixtures/emails/hebrew.eml") } + let(:receiver) { Email::Receiver.new(hebrew) } + + it "processes correctly" do + I18n.expects(:t).with('user_notifications.previous_discussion').returns('כלטוב') + receiver.process + expect(receiver.body).to eq("שלום") + end + end + describe "via" do let(:wrote) { File.read("#{Rails.root}/spec/fixtures/emails/via_line.eml") } let(:receiver) { Email::Receiver.new(wrote) } diff --git a/spec/fixtures/emails/hebrew.eml b/spec/fixtures/emails/hebrew.eml new file mode 100644 index 000000000..e21ba739d --- /dev/null +++ b/spec/fixtures/emails/hebrew.eml @@ -0,0 +1,17 @@ + +Delivered-To: discourse-reply+cd480e301683c9902891f15968bf07a5@discourse.org +Received: by 10.194.216.104 with SMTP id op8csp80593wjc; + Wed, 24 Jul 2013 07:59:14 -0700 (PDT) +Return-Path: +References: <51efeb9b36c34_66dc2dfce6811866@discourse.mail> +From: Walter White +In-Reply-To: <51efeb9b36c34_66dc2dfce6811866@discourse.mail> +Mime-Version: 1.0 (1.0) +Date: Wed, 24 Jul 2013 15:59:10 +0100 +Message-ID: <4597127794206131679@unknownmsgid> +Subject: Re: [Discourse] new reply to your post in 'Crystal Blue' +To: walter via Discourse +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: base64 + +16nXnNeV150= \ No newline at end of file