email_reply_trimmer 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/email_reply_trimmer-0.0.3.gem +0 -0
- data/lib/email_reply_trimmer.rb +13 -5
- data/lib/email_reply_trimmer/embedded_email_matcher.rb +5 -1
- data/lib/email_reply_trimmer/signature_matcher.rb +3 -0
- data/test/emails/dual_embedded.txt +13 -0
- data/test/emails/embedded_ception.txt +47 -0
- data/test/emails/embedded_email_9.txt +5 -0
- data/test/emails/embedded_email_german_2.txt +6 -0
- data/test/emails/signatures.txt +1 -0
- data/test/replies/dual_embedded.txt +1 -0
- data/test/replies/embedded_ception.txt +4 -0
- data/test/replies/embedded_email_9.txt +1 -0
- data/test/replies/embedded_email_german_2.txt +1 -0
- metadata +11 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cfa08e2fe81cc760935dd3581815a6b2e5a49ffc
|
4
|
+
data.tar.gz: cb319cb76c4a6428e8fdc4e20eab8aff083fbc8c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc0450c91a3c56dd692a688310046fc3560a9b9bce00c0998bb68b4077370a8a9c34464006a970800f29d4abb0b1ecba1e8b5d5ced8456c750373dbde54954ff
|
7
|
+
data.tar.gz: d350b84fbbc4c8df6d613f2097072465f326f43ab9538ccc7ac6164251b1cf8b1e77e2200fe08231edc7a0cd9944eef72bc022d69c1f8f1a4f485f985308915a
|
Binary file
|
data/lib/email_reply_trimmer.rb
CHANGED
@@ -6,7 +6,7 @@ require_relative "email_reply_trimmer/email_header_matcher"
|
|
6
6
|
require_relative "email_reply_trimmer/quote_matcher"
|
7
7
|
|
8
8
|
class EmailReplyTrimmer
|
9
|
-
VERSION = "0.0.
|
9
|
+
VERSION = "0.0.4"
|
10
10
|
|
11
11
|
DELIMITER = "d"
|
12
12
|
EMBEDDED = "b"
|
@@ -30,7 +30,7 @@ class EmailReplyTrimmer
|
|
30
30
|
return "" if text.nil? || text =~ /\A[[:space:]]*\Z/m
|
31
31
|
|
32
32
|
# normalize line endings
|
33
|
-
text.gsub!(/\r*\n/, "\n")
|
33
|
+
text = text.gsub!(/\r*\n/, "\n")
|
34
34
|
|
35
35
|
# fix embedded email markers that might span over multiple lines
|
36
36
|
EmbeddedEmailMatcher::ON_DATE_SOMEONE_WROTE_REGEXES.each do |r|
|
@@ -51,10 +51,18 @@ class EmailReplyTrimmer
|
|
51
51
|
lines.slice!(index)
|
52
52
|
end
|
53
53
|
|
54
|
-
# if there is an embedded email marker, followed only by
|
54
|
+
# if there is an embedded email marker, followed only by other email markers and/or text
|
55
55
|
# then take everything up to that marker
|
56
|
-
if pattern =~ /
|
57
|
-
index = pattern =~ /
|
56
|
+
if pattern =~ /te*b[etb]*$/
|
57
|
+
index = pattern =~ /te*b[etb]*$/
|
58
|
+
pattern = pattern[0..index]
|
59
|
+
lines = lines[0..index]
|
60
|
+
end
|
61
|
+
|
62
|
+
# if there is an embedded email marker, followed by a huge quote
|
63
|
+
# then take everything up to that marker
|
64
|
+
if pattern =~ /te*b[eqb]*[te]*$/
|
65
|
+
index = pattern =~ /te*b[eqb]*[te]*$/
|
58
66
|
pattern = pattern[0..index]
|
59
67
|
lines = lines[0..index]
|
60
68
|
end
|
@@ -10,6 +10,7 @@ class EmbeddedEmailMatcher
|
|
10
10
|
# Dnia 14 lip 2015 o godz. 00:25 Michael Downey <info@discourse.org> napisał(a):
|
11
11
|
# Em seg, 27 de jul de 2015 17:13, Neil Lalonde <info@discourse.org> escreveu:
|
12
12
|
# El jueves, 21 de noviembre de 2013, codinghorror escribió:
|
13
|
+
# Am 03.02.2016 3:35 nachm. schrieb Max Mustermann <mail@example.com>:
|
13
14
|
ON_DATE_SOMEONE_WROTE_MARKERS = [
|
14
15
|
# Dutch
|
15
16
|
["Op","het volgende geschreven"],
|
@@ -23,6 +24,8 @@ class EmbeddedEmailMatcher
|
|
23
24
|
["Em", "escreveu"],
|
24
25
|
# Spanish
|
25
26
|
["El", "escribió"],
|
27
|
+
# German
|
28
|
+
["Am", "schrieb"],
|
26
29
|
]
|
27
30
|
|
28
31
|
ON_DATE_SOMEONE_WROTE_REGEXES = ON_DATE_SOMEONE_WROTE_MARKERS.map do |on, wrote|
|
@@ -83,11 +86,12 @@ class EmbeddedEmailMatcher
|
|
83
86
|
# ----- Forwarded Message -----
|
84
87
|
# ----- Original Message -----
|
85
88
|
# -----Original Message-----
|
89
|
+
# *----- Original Message -----*
|
86
90
|
FORWARDED_EMAIL_REGEXES = [
|
87
91
|
# English
|
88
92
|
/^[[:space:]]*Begin forwarded message:/i,
|
89
93
|
/^[[:space:]]*Reply message/i,
|
90
|
-
/^[[:space:]]*-{2,}[[:space:]]*(Forwarded|Original) Message[[:space:]]*-{2,}/i
|
94
|
+
/^[[:space:]\*]*-{2,}[[:space:]]*(Forwarded|Original) Message[[:space:]]*-{2,}/i
|
91
95
|
]
|
92
96
|
|
93
97
|
EMBEDDED_REGEXES = [
|
@@ -12,7 +12,10 @@ class SignatureMatcher
|
|
12
12
|
# <<sent by galaxy>>
|
13
13
|
# (sent from a phone)
|
14
14
|
# (Sent from mobile device)
|
15
|
+
# 從我的 iPhone 傳送
|
15
16
|
SIGNATURE_REGEXES = [
|
17
|
+
# Chinese
|
18
|
+
/^[[:space:]]*從我的 iPhone 傳送/i,
|
16
19
|
# English
|
17
20
|
/^[[:space:]]*[[:word:]]+ from mobile/i,
|
18
21
|
/^[[:space:]]*sent (?:from|via|with|by) .+/i,
|
@@ -0,0 +1,47 @@
|
|
1
|
+
This is the reply.
|
2
|
+
|
3
|
+
Thanks,
|
4
|
+
Some One
|
5
|
+
|
6
|
+
On Mon, Feb 1, 2016 at 6:32 PM, Jeff Atwood <info@discourse.org>
|
7
|
+
wrote:
|
8
|
+
|
9
|
+
> This is Jeff's reply.
|
10
|
+
>
|
11
|
+
> On Mon, Feb 1, 2016 at 7:50 AM, Some One <foo@bar.com
|
12
|
+
> > wrote:
|
13
|
+
>
|
14
|
+
>> Great!
|
15
|
+
>>
|
16
|
+
>> Many thanks.
|
17
|
+
>>
|
18
|
+
>> ~s
|
19
|
+
>>
|
20
|
+
>> On Mon, Feb 1, 2016 at 5:05 AM Discourse Team <team@discourse.org> wrote:
|
21
|
+
>>
|
22
|
+
>>> WAT?
|
23
|
+
>>>
|
24
|
+
>>> On Wed, Jan 27, 2016 at 10:48 PM, Some One <
|
25
|
+
>>> foo@bar.com> wrote:
|
26
|
+
>>>
|
27
|
+
>>>> Hi Team,
|
28
|
+
>>>>
|
29
|
+
>>>> How is it doing?
|
30
|
+
>>>>
|
31
|
+
>>>> Some One
|
32
|
+
>>>>
|
33
|
+
>>>> On Wed, Jan 27, 2016 at 10:10 AM Discourse Team <team@discourse.org>
|
34
|
+
>>>> wrote:
|
35
|
+
>>>>
|
36
|
+
>>>>> Hello :waves_hand:
|
37
|
+
>>>>>
|
38
|
+
>>>>
|
39
|
+
>>>
|
40
|
+
>
|
41
|
+
|
42
|
+
|
43
|
+
--
|
44
|
+
Some One
|
45
|
+
Community Manager
|
46
|
+
foo@bar.com
|
47
|
+
(123) 456-7890
|
@@ -0,0 +1,6 @@
|
|
1
|
+
Hey:)
|
2
|
+
|
3
|
+
|
4
|
+
Am 03.02.2016 3:35 nachm. schrieb Max Mustermann <noreply@meta.discourse.org>:
|
5
|
+
|
6
|
+
> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
data/test/emails/signatures.txt
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
This is the 3rd email.
|
@@ -0,0 +1 @@
|
|
1
|
+
Bar
|
@@ -0,0 +1 @@
|
|
1
|
+
Hey:)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: email_reply_trimmer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Régis Hanol
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-02-04 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: EmailReplyTrimmer is a small library to trim replies from plain text
|
14
14
|
email.
|
@@ -21,6 +21,7 @@ files:
|
|
21
21
|
- LICENSE
|
22
22
|
- README.md
|
23
23
|
- Rakefile
|
24
|
+
- email_reply_trimmer-0.0.3.gem
|
24
25
|
- email_reply_trimmer.gemspec
|
25
26
|
- lib/email_reply_trimmer.rb
|
26
27
|
- lib/email_reply_trimmer/delimiter_matcher.rb
|
@@ -30,8 +31,10 @@ files:
|
|
30
31
|
- lib/email_reply_trimmer/quote_matcher.rb
|
31
32
|
- lib/email_reply_trimmer/signature_matcher.rb
|
32
33
|
- test/emails/delimiters.txt
|
34
|
+
- test/emails/dual_embedded.txt
|
33
35
|
- test/emails/email_headers_1.txt
|
34
36
|
- test/emails/email_headers_2.txt
|
37
|
+
- test/emails/embedded_ception.txt
|
35
38
|
- test/emails/embedded_email_1.txt
|
36
39
|
- test/emails/embedded_email_2.txt
|
37
40
|
- test/emails/embedded_email_3.txt
|
@@ -40,10 +43,12 @@ files:
|
|
40
43
|
- test/emails/embedded_email_6.txt
|
41
44
|
- test/emails/embedded_email_7.txt
|
42
45
|
- test/emails/embedded_email_8.txt
|
46
|
+
- test/emails/embedded_email_9.txt
|
43
47
|
- test/emails/embedded_email_dutch_1.txt
|
44
48
|
- test/emails/embedded_email_dutch_2.txt
|
45
49
|
- test/emails/embedded_email_french.txt
|
46
50
|
- test/emails/embedded_email_german.txt
|
51
|
+
- test/emails/embedded_email_german_2.txt
|
47
52
|
- test/emails/embedded_email_polish.txt
|
48
53
|
- test/emails/embedded_email_portuguese.txt
|
49
54
|
- test/emails/embedded_email_quote_text.txt
|
@@ -58,8 +63,10 @@ files:
|
|
58
63
|
- test/emails/strip.txt
|
59
64
|
- test/emails/text_only.txt
|
60
65
|
- test/replies/delimiters.txt
|
66
|
+
- test/replies/dual_embedded.txt
|
61
67
|
- test/replies/email_headers_1.txt
|
62
68
|
- test/replies/email_headers_2.txt
|
69
|
+
- test/replies/embedded_ception.txt
|
63
70
|
- test/replies/embedded_email_1.txt
|
64
71
|
- test/replies/embedded_email_2.txt
|
65
72
|
- test/replies/embedded_email_3.txt
|
@@ -68,10 +75,12 @@ files:
|
|
68
75
|
- test/replies/embedded_email_6.txt
|
69
76
|
- test/replies/embedded_email_7.txt
|
70
77
|
- test/replies/embedded_email_8.txt
|
78
|
+
- test/replies/embedded_email_9.txt
|
71
79
|
- test/replies/embedded_email_dutch_1.txt
|
72
80
|
- test/replies/embedded_email_dutch_2.txt
|
73
81
|
- test/replies/embedded_email_french.txt
|
74
82
|
- test/replies/embedded_email_german.txt
|
83
|
+
- test/replies/embedded_email_german_2.txt
|
75
84
|
- test/replies/embedded_email_polish.txt
|
76
85
|
- test/replies/embedded_email_portuguese.txt
|
77
86
|
- test/replies/embedded_email_quote_text.txt
|