email_signature_parser 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/email_signature_parser/parser.rb +38 -10
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: aea0b96676e5c0bfef82293806dd41bf895639693826ed74100d9c8427fec69a
|
|
4
|
+
data.tar.gz: cb0f908d47ce09dd63a8fd7e74476278c0280ffae24846e4467e6a306e5c5768
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7afa6bc16d40d2d056751860bbf1dbd6cb4fe4aa1ba664f3385e0683cf89c248ced290d961fb75d9956cb73d86cb26db959572a9147d469c3b5d76c4c6b4caec
|
|
7
|
+
data.tar.gz: 5e9175050f2c345658f896305ade73dcc107823e6260eef89ccdc72477d847b355929338781236aa456e5f17d5374a5e53375c29262818cad779b8aa41f96e1e
|
|
@@ -7,6 +7,38 @@ module EmailSignatureParser
|
|
|
7
7
|
class InvalidFromError < ParseError; end
|
|
8
8
|
|
|
9
9
|
class Parser
|
|
10
|
+
# Matches the start of a quoted/forwarded reply block. Patterns observed in samples:
|
|
11
|
+
#
|
|
12
|
+
# 1. Markdown bold Outlook headers (most common — HTML emails converted to markdown):
|
|
13
|
+
# **De:** Name / **From:** Name
|
|
14
|
+
# These appear after a blank line, optionally preceded by a long dash separator line.
|
|
15
|
+
#
|
|
16
|
+
# 2. Long dash separator variants followed by **De:**/**From:**:
|
|
17
|
+
# -----...----- (plain dashes, 40+ chars)
|
|
18
|
+
# -----...----- (then blank line) then **De:** ...
|
|
19
|
+
#
|
|
20
|
+
# 3. Forwarded/original message banners:
|
|
21
|
+
# ---------- Forwarded message ---------
|
|
22
|
+
# ------------------- Mensaje original -------------------
|
|
23
|
+
# --------Cita original---------
|
|
24
|
+
#
|
|
25
|
+
# 4. Gmail "On <date>, <name> wrote:" / Spanish "El <fecha> escribió:"
|
|
26
|
+
#
|
|
27
|
+
# 5. Plain-text (non-HTML) emails: bare "De: ..." / "From: ..." at line start
|
|
28
|
+
THREADS_MARKER_REGEX = /
|
|
29
|
+
(?:^-{5,}[^\n]*\n[ \t]*\n?)?
|
|
30
|
+
(?:
|
|
31
|
+
\*\*(?:De|From|Enviado\s+de)\s*:\*\*
|
|
32
|
+
|
|
|
33
|
+
(?:^|\n)(?:De|From):\s+\S
|
|
34
|
+
|
|
|
35
|
+
^-{5,}\s*(?:Forwarded\s+message|original)
|
|
36
|
+
|
|
|
37
|
+
^On\s+\S[^\n]+wrote:\s*\n
|
|
38
|
+
|
|
|
39
|
+
^El\s+\S[^\n]+escribi[oó]:\s*\n
|
|
40
|
+
)
|
|
41
|
+
/imx
|
|
10
42
|
|
|
11
43
|
SOCIAL_MEDIA_URLS = ['instagram', 'x', 'twitter', 'facebook', 'linkedin', 'youtube', 'tiktok', 'bsky']
|
|
12
44
|
|
|
@@ -686,25 +718,21 @@ module EmailSignatureParser
|
|
|
686
718
|
|
|
687
719
|
def split_in_threads(text)
|
|
688
720
|
|
|
689
|
-
|
|
690
|
-
# (from|de):\s.*@+.+) matches from followed by an email address
|
|
691
|
-
# (-{5,}\s*?^(from|de):\s+\w+) matches lines that start with ----- followed by from and a name
|
|
692
|
-
marker_regex = /((from|de):\s.*@+.+)|(-{5,}\s*?^(from|de):\s+\w+)/i
|
|
721
|
+
return [] if text.blank?
|
|
693
722
|
|
|
694
|
-
marker_indexes = text.enum_for(:scan,
|
|
723
|
+
marker_indexes = text.enum_for(:scan, THREADS_MARKER_REGEX).map { Regexp.last_match.begin(0) }
|
|
695
724
|
messages = []
|
|
696
725
|
last_index = 0
|
|
697
726
|
|
|
698
727
|
marker_indexes.each do |marker_index|
|
|
699
|
-
|
|
728
|
+
segment = text[last_index...marker_index].strip
|
|
729
|
+
messages << segment unless segment.empty?
|
|
700
730
|
last_index = marker_index
|
|
701
731
|
end
|
|
702
732
|
|
|
703
|
-
if last_index < text.size
|
|
704
|
-
|
|
705
|
-
end
|
|
733
|
+
messages << text[last_index..].strip if last_index < text.size
|
|
734
|
+
messages.reject(&:empty?)
|
|
706
735
|
|
|
707
|
-
return messages
|
|
708
736
|
end
|
|
709
737
|
|
|
710
738
|
def remove_forwarded_content(text)
|