From 5055da76e64fce45fd19185f11603832f29ea506 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Wed, 20 Nov 2013 13:29:42 -0500 Subject: [PATCH] Abort triggers for email body processing --- Gemfile | 2 +- lib/email/receiver.rb | 7 + spec/components/email/receiver_spec.rb | 10 + spec/fixtures/emails/attachment.eml | 351 +++++++++++++++++++++++++ 4 files changed, 369 insertions(+), 1 deletion(-) create mode 100644 spec/fixtures/emails/attachment.eml diff --git a/Gemfile b/Gemfile index 55496f185..9dbe67a42 100644 --- a/Gemfile +++ b/Gemfile @@ -163,7 +163,7 @@ group :development do end # Gem that enables support for plugins. It is required. -# TODO: does this really need to be a gem ? +# TODO: does this really need to be a gem ? gem 'discourse_plugin', path: 'vendor/gems/discourse_plugin' # this is an optional gem, it provides a high performance replacement diff --git a/lib/email/receiver.rb b/lib/email/receiver.rb index 02e0004c5..fdb700928 100644 --- a/lib/email/receiver.rb +++ b/lib/email/receiver.rb @@ -72,6 +72,13 @@ module Email end @body = @message.body.to_s.strip + + # Certain trigger phrases that means we didn't parse correctly + @body = nil if @body =~ /Content\-Type\:/ || + @body =~ /multipart\/alternative/ || + @body =~ /text\/plain/ + + @body end def scrub_html(html) diff --git a/spec/components/email/receiver_spec.rb b/spec/components/email/receiver_spec.rb index 8c382f954..b9d3dcadd 100644 --- a/spec/components/email/receiver_spec.rb +++ b/spec/components/email/receiver_spec.rb @@ -40,6 +40,16 @@ stripped from my reply?") end end + describe "it ignores messages it can't parse due to containing weird terms" do + let(:attachment) { File.read("#{Rails.root}/spec/fixtures/emails/attachment.eml") } + let(:receiver) { Email::Receiver.new(attachment) } + + it "processes correctly" do + expect(receiver.process).to eq(Email::Receiver.results[:unprocessable]) + expect(receiver.body).to be_blank + end + end + describe "it supports a dutch reply" do let(:dutch) { File.read("#{Rails.root}/spec/fixtures/emails/dutch.eml") } let(:receiver) { Email::Receiver.new(dutch) } diff --git a/spec/fixtures/emails/attachment.eml b/spec/fixtures/emails/attachment.eml new file mode 100644 index 000000000..608d1632b --- /dev/null +++ b/spec/fixtures/emails/attachment.eml @@ -0,0 +1,351 @@ +Message-ID: <51C22E52.1030509@darthvader.ca> +Date: Wed, 19 Jun 2013 18:18:58 -0400 +From: Anakin Skywalker +User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130510 Thunderbird/17.0.6 +MIME-Version: 1.0 +To: Han Solo via Death Star +Subject: Re: [Death Star] [PM] re: Regarding your post in "Site Customization + not working" +References: <51d23d33f41fb_5f4e4b35d7d60798@xwing.mail> +In-Reply-To: <51d23d33f41fb_5f4e4b35d7d60798@xwing.mail> +Content-Type: multipart/mixed; boundary=047d7b45041e19c68004eb9f3de8 + +--047d7b45041e19c68004eb9f3de8 +Content-Type: multipart/alternative; boundary=047d7b45041e19c67b04eb9f3de6 + +--047d7b45041e19c67b04eb9f3de6 +Content-Type: text/plain; charset=ISO-8859-1 + +here is an image attachment + + +On Tue, Nov 19, 2013 at 5:11 PM, Neil wrote: + +> Neil +> November 19 +> +> Actually, deleting a spammer does what it's supposed to. It does mark the +> topic as deleted. +> +> That topic has id 11002, and you're right that the user was deleted. +> +> @eviltrout Any idea why it showed up in +> suggested topics? +> +> To respond, reply to this email or visit +> http://meta.discourse.org/t/spam-post-pops-back-up-in-suggested-topics/11005/5in your browser. +> ------------------------------ +> Previous Replies Neil +> November 19 +> +> Looks like a bug when deleting a spammer. I'll look at it. +> riking +> November 19 +> +> codinghorror said: +> +> I can't even find that topic by name. +> +> In that case, I'm fairly certain someone used the 'Delete Spammer' +> function on the user, which would explain your inability to find it - it's +> gone. +> +> I'm raising this because, well, it's gone and shouldn't be showing up. And +> even if it was hanging around, it should be invisible to me, and not +> showing up in Suggested Topics. +> codinghorror +> November 19 +> +> Hmm, that's interesting -- can you have a look @eviltrout? +> I can't even find that topic by name. +> riking +> November 19 +> +> I'm one of the users who flagged this particular spam post, and it was +> promptly deleted/hidden, but it just popped up in the Suggested Topics box: +> +> Pasted image1125x220 27.7 KB +> +> +> We may want to recheck the suppression on these. +> ------------------------------ +> +> To respond, reply to this email or visit +> http://meta.discourse.org/t/spam-post-pops-back-up-in-suggested-topics/11005/5in your browser. +> +> To unsubscribe from these emails, visit your user preferences +> . +> + +--047d7b45041e19c67b04eb9f3de6 +Content-Type: text/html; charset=ISO-8859-1 +Content-Transfer-Encoding: quoted-printable + +
here is an image attachment


On Tue, Nov 19, 2013 at 5:11 PM, Neil = +<info@discourse.org> wrote:
+
+ + + + + + + + +
+ + + Neil<= +/a>
+No= +vember 19 +
+

Actually, deleting a spammer does what it's s= +upposed to. It does mark the topic as deleted.

+ +

That topic has id 11002, and you're right tha= +t the user was deleted.

+ +

@eviltrout Any idea why it showed up in suggested topics?

+
+
+

To respond, reply to this email or visit http://meta.discourse.org/t/spam-post-pops-back= +-up-in-suggested-topics/11005/5 in your browser.

+ +
+
+

Previous Replies

+ + + + + + + + + +
+ + + Neil<= +/a>
+No= +vember 19 +

Looks= + like a bug when deleting a spammer. I'll look at it.

+ + + + + + + + +
+ + + rik= +ing
+No= +vember 19 +
+

+
+codinghorror said:
+

I can't even find that topic by n= +ame.

+ +

In that case, I'm fairly certain someone used= + the 'Delete Spammer' function on the user, which would explain you= +r inability to find it - it's gone.

+ +

I'm raising this because, well, it's gone= + and shouldn't be showing up. And even if it was hanging around, it sho= +uld be invisible to me, and not showing up in Suggested Topics.

+
+ + + + + + + + +
+ + + codinghorror
+No= +vember 19 +

Hmm, = +that's interesting -- can you have a look @eviltrout? I can't even find that topic by= + name.

+
+ + + + + + + + +
+ + + rik= +ing
+No= +vember 19 +
+

I'm one of the users who flagged this particu= +lar spam post, and it was promptly deleted/hidden, but it just popped up in= + the Suggested Topics box:

+ +

+ + +

We may want to recheck the suppression on these.<= +/p> +

+
+
+

To respond, reply to this email or visit http://meta.discourse.org/t/spam-post-pops-back-up-= +in-suggested-topics/11005/5 in your browser.

+ +
+
+

To unsubscribe from these emails, visit your user pre= +ferences.

+
+

+ +--047d7b45041e19c67b04eb9f3de6-- +--047d7b45041e19c68004eb9f3de8 +Content-Type: image/png; name="bricks.png" +Content-Disposition: attachment; filename="bricks.png" +Content-Transfer-Encoding: base64 +X-Attachment-Id: f_ho8uteve0 + +iVBORw0KGgoAAAANSUhEUgAAASEAAAB+CAIAAADk0DDaAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJ +bWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdp +bj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6 +eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEz +NDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJo +dHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlw +dGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAv +IiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RS +ZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpD +cmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBNYWNpbnRvc2giIHhtcE1NOkluc3RhbmNl +SUQ9InhtcC5paWQ6MDYxQjcyOUUzMDM1MTFFM0JFRTFBOTQ1RUY4QUU4MDIiIHhtcE1NOkRvY3Vt +ZW50SUQ9InhtcC5kaWQ6MDYxQjcyOUYzMDM1MTFFM0JFRTFBOTQ1RUY4QUU4MDIiPiA8eG1wTU06 +RGVyaXZlZEZyb20gc3RS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