Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Quote parser for portuguese #4

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/email_reply_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,9 @@ def read(text)
# German
/(?!Am.*Am\s.+?schrieb[^:]*:)(Am\s(.+?)schrieb[^:]*:)/m,
# Italian
/(?!Il.*Il\s.+?scritto[^:]*:)(Il[\s\S]+?(.+?)scritto:)/m
/(?!Il.*Il\s.+?scritto[^:]*:)(Il[\s\S]+?(.+?)scritto:)/m,
# Portuguese
/(?!Em.*Em\s.+?escreveu\s*:)(Em[\s\S]+?escre[a-zA-Z=\s]*:)/m
].freeze
QUOTE_HEADER_REGULAR_EXPRESSIONS = [
# English
Expand All @@ -163,7 +165,10 @@ def read(text)
# German
/[a-zA-Z]{2,5}.*schrieb[^:]*:$/,
# Italian
/^Il.+?ha scritto:$/
/^Il.+?ha scritto:$/,
# Portuguese
/^Em.+?escre[a-zA-Z=\s]*:$/m,
/^(De|Enviado|Para|Assunto):.*$/m
].freeze

### Line-by-Line Parsing
Expand Down
16 changes: 16 additions & 0 deletions test/email_reply_parser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,22 @@ def test_email_reply_italian_multiline
assert_equal [false, false], reply.fragments.map { |f| f.signature? }
end

def test_quote_reply_portuguese
reply = email('quote_reply_portuguese')
assert_equal('This is a reply with Portuguese quote', reply.fragments[0].to_s)
assert_equal [false, true], reply.fragments.map(&:hidden?)
assert_equal [false, true], reply.fragments.map(&:quoted?)
assert_equal [false, false], reply.fragments.map(&:signature?)
end

def test_quote_reply_portuguese_multiline
reply = email('quote_reply_portuguese_multiline')
assert_equal('This is a reply with Portuguese quote multiline', reply.fragments[0].to_s)
assert_equal [false, true, true], reply.fragments.map(&:hidden?)
assert_equal [false, true, false], reply.fragments.map(&:quoted?)
assert_equal [false, false, false], reply.fragments.map(&:signature?)
end

def test_pathological_emails
t0 = Time.now
email("pathological")
Expand Down
6 changes: 6 additions & 0 deletions test/emails/quote_reply_portuguese.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
This is a reply with Portuguese quote

Em qui., 20 de out. de 2022 =C3=A0s 09:36, Rick <[email protected]> escreveu:

> Hello this is a test
>
8 changes: 8 additions & 0 deletions test/emails/quote_reply_portuguese_multiline.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
This is a reply with Portuguese quote multiline

Em qui., 20 de out. de 2022 =C3=A0s 09:37, Rick <[email protected]> escre=
veu:

> Hello this is a test:
> test
>