Merge pull request #3010 from techAPJ/patch-1

FEATURE: switch to GitHub email_reply_parser library and parse plain tex...
This commit is contained in:
Régis Hanol 2014-12-01 11:18:24 +01:00
commit a6074af711
11 changed files with 85 additions and 10 deletions

View File

@ -120,11 +120,7 @@ gem 'fastimage'
gem 'fog', '1.22.1', require: false
gem 'unf', require: false
# see: https://twitter.com/samsaffron/status/412360162297393152
# Massive amount of changes made in branch we use, no PR upstreamed
# We need to get this sorted
# https://github.com/samsaffron/email_reply_parser
gem 'email_reply_parser-discourse', require: 'email_reply_parser'
gem 'email_reply_parser'
# note: for image_optim to correctly work you need
# sudo apt-get install -y advancecomp gifsicle jpegoptim libjpeg-progs optipng pngcrush

View File

@ -65,7 +65,7 @@ GEM
dotenv (0.11.1)
dotenv-deployment (~> 0.0.2)
dotenv-deployment (0.0.2)
email_reply_parser-discourse (0.6)
email_reply_parser (0.5.8)
ember-data-source (0.14)
ember-source
ember-rails (0.14.1)
@ -412,7 +412,7 @@ DEPENDENCIES
better_errors
binding_of_caller
certified
email_reply_parser-discourse
email_reply_parser
ember-rails
ember-source (= 1.6.0.beta.2)
eventmachine

View File

@ -117,9 +117,9 @@ module Email
if message.multipart?
html = fix_charset message.html_part
text = fix_charset message.text_part
# TODO picking text if available may be better
# in case of email reply from MS Outlook client, prefer text
if (text && !html) || (text && (message.header.to_s =~ /X-MS-Has-Attach/ || message.header.to_s =~ /Microsoft Outlook/))
# prefer plain text
if text
return text
end
elsif message.content_type =~ /text\/html/

View File

@ -93,6 +93,85 @@ Pleasure to have you here!
)
end
it "handles newlines" do
test_parse_body(fixture_file("emails/newlines.eml")).
should == (
"This is my reply.
It is my best reply.
It will also be my *only* reply."
)
end
it "should not include previous replies" do
test_parse_body(fixture_file("emails/previous_replies.eml")).should_not match /Previous Replies/
end
it "strips iPhone signature" do
test_parse_body(fixture_file("emails/iphone_signature.eml")).should_not match /Sent from my iPhone/
end
it "properly renders email reply from gmail web client" do
test_parse_body(fixture_file("emails/gmail_web.eml")).
should == (
"### This is a reply from standard GMail in Google Chrome.
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.
Here's some **bold** text in Markdown.
Here's a link http://example.com"
)
end
it "properly renders email reply from iOS default mail client" do
test_parse_body(fixture_file("emails/ios_default.eml")).
should == (
"### this is a reply from iOS default mail
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.
Here's some **bold** markdown text.
Here's a link http://example.com"
)
end
it "properly renders email reply from Android 5 gmail client" do
test_parse_body(fixture_file("emails/android_gmail.eml")).
should == (
"### this is a reply from Android 5 gmail
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 **bold** in Markdown.
This is a link to http://example.com"
)
end
it "properly renders email reply from Windows 8.1 Metro default mail client" do
test_parse_body(fixture_file("emails/windows_8_metro.eml")).
should == (
"### 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"
)
end
it "properly renders email reply from MS Outlook client" do
test_parse_body(fixture_file("emails/outlook.eml")).should == "Microsoft Outlook 2010"
end

BIN
spec/fixtures/emails/android_gmail.eml vendored Normal file

Binary file not shown.

BIN
spec/fixtures/emails/gmail_web.eml vendored Normal file

Binary file not shown.

BIN
spec/fixtures/emails/ios_default.eml vendored Normal file

Binary file not shown.

Binary file not shown.

BIN
spec/fixtures/emails/newlines.eml vendored Normal file

Binary file not shown.

Binary file not shown.

BIN
spec/fixtures/emails/windows_8_metro.eml vendored Normal file

Binary file not shown.