2015-08-20 14:05:06 -04:00
|
|
|
require "spec_helper"
|
|
|
|
|
|
|
|
# Inspired in great part by Discourse's Email::Receiver
|
2015-12-09 05:55:36 -05:00
|
|
|
describe Gitlab::Email::ReplyParser, lib: true do
|
2015-08-20 14:33:35 -04:00
|
|
|
describe '#execute' do
|
2015-08-20 14:05:06 -04:00
|
|
|
def test_parse_body(mail_string)
|
|
|
|
described_class.new(Mail::Message.new(mail_string)).execute
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns an empty string if the message is blank" do
|
|
|
|
expect(test_parse_body("")).to eq("")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns an empty string if the message is not an email" do
|
|
|
|
expect(test_parse_body("asdf" * 30)).to eq("")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns an empty string if there is no reply content" do
|
|
|
|
expect(test_parse_body(fixture_file("emails/no_content_reply.eml"))).to eq("")
|
|
|
|
end
|
|
|
|
|
2015-08-21 19:09:55 -04:00
|
|
|
it "properly renders plaintext-only email" do
|
|
|
|
expect(test_parse_body(fixture_file("emails/plaintext_only.eml"))).
|
|
|
|
to eq(
|
|
|
|
<<-BODY.strip_heredoc.chomp
|
|
|
|
### reply from default mail client in Windows 8.1 Metro
|
|
|
|
|
|
|
|
|
|
|
|
The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.
|
|
|
|
|
|
|
|
|
|
|
|
This is a **bold** word in Markdown
|
|
|
|
|
|
|
|
|
|
|
|
This is a link http://example.com
|
|
|
|
BODY
|
|
|
|
)
|
2015-08-20 14:05:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "supports a Dutch reply" do
|
|
|
|
expect(test_parse_body(fixture_file("emails/dutch.eml"))).to eq("Dit is een antwoord in het Nederlands.")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "removes an 'on date wrote' quoting line" do
|
|
|
|
expect(test_parse_body(fixture_file("emails/on_wrote.eml"))).to eq("Sure, all you need to do is frobnicate the foobar and you'll be all set!")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "handles multiple paragraphs" do
|
|
|
|
expect(test_parse_body(fixture_file("emails/paragraphs.eml"))).
|
2015-08-20 16:10:55 -04:00
|
|
|
to eq(
|
|
|
|
<<-BODY.strip_heredoc.chomp
|
|
|
|
Is there any reason the *old* candy can't be be kept in silos while the new candy
|
|
|
|
is imported into *new* silos?
|
2015-08-20 14:05:06 -04:00
|
|
|
|
2015-08-20 16:10:55 -04:00
|
|
|
The thing about candy is it stays delicious for a long time -- we can just keep
|
|
|
|
it there without worrying about it too much, imo.
|
2015-08-20 14:05:06 -04:00
|
|
|
|
2015-08-20 16:10:55 -04:00
|
|
|
Thanks for listening.
|
|
|
|
BODY
|
|
|
|
)
|
2015-08-20 14:05:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "handles multiple paragraphs when parsing html" do
|
|
|
|
expect(test_parse_body(fixture_file("emails/html_paragraphs.eml"))).
|
2015-08-20 16:10:55 -04:00
|
|
|
to eq(
|
|
|
|
<<-BODY.strip_heredoc.chomp
|
|
|
|
Awesome!
|
2015-08-20 14:05:06 -04:00
|
|
|
|
2015-08-20 16:10:55 -04:00
|
|
|
Pleasure to have you here!
|
2015-08-20 14:05:06 -04:00
|
|
|
|
2015-08-20 16:10:55 -04:00
|
|
|
:boom:
|
|
|
|
BODY
|
|
|
|
)
|
2015-08-20 14:05:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "handles newlines" do
|
|
|
|
expect(test_parse_body(fixture_file("emails/newlines.eml"))).
|
2015-08-20 16:10:55 -04:00
|
|
|
to eq(
|
|
|
|
<<-BODY.strip_heredoc.chomp
|
|
|
|
This is my reply.
|
|
|
|
It is my best reply.
|
|
|
|
It will also be my *only* reply.
|
|
|
|
BODY
|
|
|
|
)
|
2015-08-20 14:05:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "handles inline reply" do
|
|
|
|
expect(test_parse_body(fixture_file("emails/inline_reply.eml"))).
|
2015-08-20 16:10:55 -04:00
|
|
|
to eq(
|
|
|
|
<<-BODY.strip_heredoc.chomp
|
|
|
|
On Wed, Oct 8, 2014 at 11:12 AM, techAPJ <info@unconfigured.discourse.org> wrote:
|
|
|
|
|
|
|
|
> techAPJ <https://meta.discourse.org/users/techapj>
|
|
|
|
> November 28
|
|
|
|
>
|
|
|
|
> Test reply.
|
|
|
|
>
|
|
|
|
> First paragraph.
|
|
|
|
>
|
|
|
|
> Second paragraph.
|
|
|
|
>
|
|
|
|
> To respond, reply to this email or visit
|
|
|
|
> https://meta.discourse.org/t/testing-default-email-replies/22638/3 in
|
|
|
|
> your browser.
|
|
|
|
> ------------------------------
|
|
|
|
> Previous Replies codinghorror
|
|
|
|
> <https://meta.discourse.org/users/codinghorror>
|
|
|
|
> November 28
|
|
|
|
>
|
|
|
|
> We're testing the latest GitHub email processing library which we are
|
|
|
|
> integrating now.
|
|
|
|
>
|
|
|
|
> https://github.com/github/email_reply_parser
|
|
|
|
>
|
|
|
|
> Go ahead and reply to this topic and I'll reply from various email clients
|
|
|
|
> for testing.
|
|
|
|
> ------------------------------
|
|
|
|
>
|
|
|
|
> To respond, reply to this email or visit
|
|
|
|
> https://meta.discourse.org/t/testing-default-email-replies/22638/3 in
|
|
|
|
> your browser.
|
|
|
|
>
|
|
|
|
> To unsubscribe from these emails, visit your user preferences
|
|
|
|
> <https://meta.discourse.org/my/preferences>.
|
|
|
|
>
|
|
|
|
|
|
|
|
The quick brown fox jumps over the lazy dog. The quick brown fox jumps over
|
|
|
|
the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown
|
|
|
|
fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.
|
|
|
|
The quick brown fox jumps over the lazy dog. The quick brown fox jumps over
|
|
|
|
the lazy dog. The quick brown fox jumps over the lazy dog.
|
|
|
|
BODY
|
|
|
|
)
|
2015-08-20 14:05:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "properly renders email reply from gmail web client" do
|
|
|
|
expect(test_parse_body(fixture_file("emails/gmail_web.eml"))).
|
2015-08-20 16:10:55 -04:00
|
|
|
to eq(
|
|
|
|
<<-BODY.strip_heredoc.chomp
|
|
|
|
### This is a reply from standard GMail in Google Chrome.
|
2015-08-20 14:05:06 -04:00
|
|
|
|
2015-08-20 16:10:55 -04:00
|
|
|
The quick brown fox jumps over the lazy dog. The quick brown fox jumps over
|
|
|
|
the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown
|
|
|
|
fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.
|
|
|
|
The quick brown fox jumps over the lazy dog. The quick brown fox jumps over
|
|
|
|
the lazy dog. The quick brown fox jumps over the lazy dog.
|
2015-08-20 14:05:06 -04:00
|
|
|
|
2015-08-20 16:10:55 -04:00
|
|
|
Here's some **bold** text in Markdown.
|
2015-08-20 14:05:06 -04:00
|
|
|
|
2015-08-20 16:10:55 -04:00
|
|
|
Here's a link http://example.com
|
|
|
|
BODY
|
|
|
|
)
|
2015-08-20 14:05:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "properly renders email reply from iOS default mail client" do
|
|
|
|
expect(test_parse_body(fixture_file("emails/ios_default.eml"))).
|
2015-08-20 16:10:55 -04:00
|
|
|
to eq(
|
|
|
|
<<-BODY.strip_heredoc.chomp
|
|
|
|
### this is a reply from iOS default mail
|
2015-08-20 14:05:06 -04:00
|
|
|
|
2015-08-20 16:10:55 -04:00
|
|
|
The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.
|
2015-08-20 14:05:06 -04:00
|
|
|
|
2015-08-20 16:10:55 -04:00
|
|
|
Here's some **bold** markdown text.
|
2015-08-20 14:05:06 -04:00
|
|
|
|
2015-08-20 16:10:55 -04:00
|
|
|
Here's a link http://example.com
|
|
|
|
BODY
|
|
|
|
)
|
2015-08-20 14:05:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "properly renders email reply from Android 5 gmail client" do
|
|
|
|
expect(test_parse_body(fixture_file("emails/android_gmail.eml"))).
|
2015-08-20 16:10:55 -04:00
|
|
|
to eq(
|
|
|
|
<<-BODY.strip_heredoc.chomp
|
|
|
|
### this is a reply from Android 5 gmail
|
2015-08-20 14:05:06 -04:00
|
|
|
|
2015-08-20 16:10:55 -04:00
|
|
|
The quick brown fox jumps over the lazy dog. The quick brown fox jumps over
|
|
|
|
the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown
|
|
|
|
fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.
|
|
|
|
The quick brown fox jumps over the lazy dog.
|
2015-08-20 14:05:06 -04:00
|
|
|
|
2015-08-20 16:10:55 -04:00
|
|
|
This is **bold** in Markdown.
|
2015-08-20 14:05:06 -04:00
|
|
|
|
2015-08-20 16:10:55 -04:00
|
|
|
This is a link to http://example.com
|
|
|
|
BODY
|
|
|
|
)
|
2015-08-20 14:05:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "properly renders email reply from Windows 8.1 Metro default mail client" do
|
|
|
|
expect(test_parse_body(fixture_file("emails/windows_8_metro.eml"))).
|
2015-08-20 16:10:55 -04:00
|
|
|
to eq(
|
|
|
|
<<-BODY.strip_heredoc.chomp
|
|
|
|
### reply from default mail client in Windows 8.1 Metro
|
2015-08-20 14:05:06 -04:00
|
|
|
|
|
|
|
|
2015-08-20 16:10:55 -04:00
|
|
|
The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.
|
2015-08-20 14:05:06 -04:00
|
|
|
|
|
|
|
|
2015-08-20 16:10:55 -04:00
|
|
|
This is a **bold** word in Markdown
|
2015-08-20 14:05:06 -04:00
|
|
|
|
|
|
|
|
2015-08-20 16:10:55 -04:00
|
|
|
This is a link http://example.com
|
|
|
|
BODY
|
|
|
|
)
|
2015-08-20 14:05:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "properly renders email reply from MS Outlook client" do
|
|
|
|
expect(test_parse_body(fixture_file("emails/outlook.eml"))).to eq("Microsoft Outlook 2010")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|