Skip to content

Commit ff3b163

Browse files
committed
FIX: Another email regexp for quote lines in the format we can recognize including
the site name.
1 parent adbb6a1 commit ff3b163

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

lib/email/receiver.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ def discourse_email_parser
9393
email_year = lines.each_with_index do |l, idx|
9494
break if l =~ /\A\s*\-{3,80}\s*\z/ ||
9595
l =~ Regexp.new("\\A\\s*" + I18n.t('user_notifications.previous_discussion') + "\\s*\\Z") ||
96+
(l =~ /via #{SiteSetting.title}(.*)\:$/) ||
9697
# This one might be controversial but so many reply lines have years, times and end with a colon.
9798
# Let's try it and see how well it works.
9899
(l =~ /\d{4}/ && l =~ /\d:\d\d/ && l =~ /\:$/)

spec/components/email/receiver_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@
5050
end
5151
end
5252

53+
describe "via" do
54+
let(:wrote) { File.read("#{Rails.root}/spec/fixtures/emails/via_line.eml") }
55+
let(:receiver) { Email::Receiver.new(wrote) }
56+
57+
it "removes via lines if we know them" do
58+
receiver.process
59+
expect(receiver.body).to eq("Hello this email has content!")
60+
end
61+
end
62+
5363
describe "if wrote is on a second line" do
5464
let(:wrote) { File.read("#{Rails.root}/spec/fixtures/emails/multiline_wrote.eml") }
5565
let(:receiver) { Email::Receiver.new(wrote) }

spec/fixtures/emails/via_line.eml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Delivered-To: [email protected]
3+
Received: by 10.194.216.104 with SMTP id op8csp80593wjc;
4+
Wed, 24 Jul 2013 07:59:14 -0700 (PDT)
5+
Return-Path: <[email protected]>
6+
7+
From: Walter White <[email protected]>
8+
In-Reply-To: <[email protected]>
9+
Mime-Version: 1.0 (1.0)
10+
Date: Wed, 24 Jul 2013 15:59:10 +0100
11+
Message-ID: <4597127794206131679@unknownmsgid>
12+
Subject: Re: [Discourse] new reply to your post in 'Crystal Blue'
13+
To: walter via Discourse <[email protected]>
14+
Content-Type: multipart/alternative; boundary=001a11c20edc15a39304e2432790
15+
16+
Hello this email has content!
17+
18+
codinghorror via Discourse wrote:
19+
> [codinghorror] codinghorror
20+
> <http://meta.discourse.org/users/codinghorror>
21+
> August 7
22+
>
23+
> It wouldn't be great at the moment for 100% email, since there's no
24+
> way to be notified of new topics via email. (you can get notified of
25+
> new replies to your posts and topics via email, and reply to them.)

0 commit comments

Comments
 (0)