email_signature_parser 0.1.4 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2525a79c98466992d96ab35de5d48b01ee2b582087db6e0a3f1b2fa7eb3825ae
4
- data.tar.gz: 5b3b825f71b431d535d1d56ab2c3a1b51e74ddcec16ac964b7e98a85a24558f9
3
+ metadata.gz: aea0b96676e5c0bfef82293806dd41bf895639693826ed74100d9c8427fec69a
4
+ data.tar.gz: cb0f908d47ce09dd63a8fd7e74476278c0280ffae24846e4467e6a306e5c5768
5
5
  SHA512:
6
- metadata.gz: e30da1515107da2c7975b480fbdaa867f989b874149147a3fdee2c14ffef787d9f89f2e2e4a7406588c7be126eacc603d80e18a1e92bdcc55e27527527a132da
7
- data.tar.gz: c666ea83e31f75aedee3baffe4132c6aee1e6edd2f0827efa4ed9e0e998af03cff4482202382fa4d0e60c1ae9c82b73136a715c2a22bb122897773c4ed61f331
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
- # Regex for reply markers. Handles English and Spanish.
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, marker_regex).map { Regexp.last_match.begin(0) }
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
- messages << text[last_index...marker_index].strip
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
- messages << text[last_index..].strip
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)
@@ -10,7 +10,7 @@ require 'yaml'
10
10
  require 'cgi'
11
11
 
12
12
  require_relative "email_signature_parser/parser"
13
- require_relative "email_signature_parser/html_text_parser"
13
+ require_relative "email_signature_parser/html_to_markdown_parser"
14
14
  require_relative "email_signature_parser/utils"
15
15
 
16
16
  module EmailSignatureParser
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: email_signature_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guillermo Molini