email-origin-chain 1.0.8 → 1.0.10

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.
@@ -10,7 +10,7 @@ import { ForwardDetector, DetectionResult } from './types';
10
10
  */
11
11
  export declare class OutlookEmptyHeaderDetector implements ForwardDetector {
12
12
  readonly name = "outlook_empty_header";
13
- readonly priority = 50;
13
+ readonly priority = -50;
14
14
  private readonly HEADER_PATTERN;
15
15
  detect(text: string): DetectionResult;
16
16
  }
@@ -14,7 +14,7 @@ const cleaner_1 = require("../utils/cleaner");
14
14
  class OutlookEmptyHeaderDetector {
15
15
  constructor() {
16
16
  this.name = 'outlook_empty_header';
17
- this.priority = 50; // Fallback for corrupted headers (after specifics, before generic Crisp)
17
+ this.priority = -50; // Very specific - High Priority
18
18
  // Regex to capture the header block:
19
19
  // 1. Optional Separator (mostly underscores)
20
20
  // 2. De: ... (From)
@@ -51,6 +51,7 @@ class OutlookEmptyHeaderDetector {
51
51
  message: message || undefined,
52
52
  email: {
53
53
  from: fromLine,
54
+ to: toLine,
54
55
  subject: subjectLine,
55
56
  date: dateLine || undefined,
56
57
  body: finalBody
@@ -4,7 +4,7 @@ import { ForwardDetector, DetectionResult } from './types';
4
4
  */
5
5
  export declare class OutlookReverseFrDetector implements ForwardDetector {
6
6
  readonly name = "outlook_reverse_fr";
7
- readonly priority = -20;
7
+ readonly priority = -45;
8
8
  private readonly ENVOYE_PATTERN;
9
9
  private readonly DE_PATTERN;
10
10
  private readonly A_PATTERN;
@@ -8,7 +8,7 @@ const cleaner_1 = require("../utils/cleaner");
8
8
  class OutlookReverseFrDetector {
9
9
  constructor() {
10
10
  this.name = 'outlook_reverse_fr';
11
- this.priority = -20; // Specific detector - High Priority (Override)
11
+ this.priority = -45; // Specific detector - High Priority
12
12
  // Regex patterns for field detection
13
13
  this.ENVOYE_PATTERN = /^[ \t]*Envoy(?:é|=E9|e)?\s*:\s*(.*?)\s*$/m;
14
14
  this.DE_PATTERN = /^[ \t]*De\s*:/i;
@@ -76,6 +76,7 @@ class OutlookReverseFrDetector {
76
76
  from: fromEmail.includes('@')
77
77
  ? { name: fromName !== fromEmail ? fromName : '', address: fromEmail }
78
78
  : { name: fromName, address: fromName },
79
+ to: a ? extractValue(a.line) : undefined,
79
80
  subject: objet ? extractValue(objet.line) : '',
80
81
  date: extractValue(envoyeMatch[0]),
81
82
  body: finalBody
@@ -15,12 +15,12 @@ class DetectorRegistry {
15
15
  constructor(customDetectors = []) {
16
16
  this.detectors = [];
17
17
  // Register all detectors (priority determines order)
18
- this.register(new crisp_detector_1.CrispDetector()); // priority: 0 (highest - universal library)
19
- this.register(new outlook_empty_header_detector_1.OutlookEmptyHeaderDetector()); // priority: 5 (handle empty headers)
20
- this.register(new outlook_reverse_fr_detector_1.OutlookReverseFrDetector()); // priority: 6 (handle reversed FR headers)
21
- this.register(new reply_detector_1.ReplyDetector()); // priority: 7 (handle standard replies)
22
- this.register(new outlook_fr_detector_1.OutlookFRDetector()); // priority: 10 (fallback for FR formats)
23
- this.register(new new_outlook_detector_1.NewOutlookDetector()); // priority: 10 (fallback for new Outlook)
18
+ this.register(new outlook_empty_header_detector_1.OutlookEmptyHeaderDetector()); // priority: -50 (Very specific)
19
+ this.register(new outlook_reverse_fr_detector_1.OutlookReverseFrDetector()); // priority: -45 (Specific)
20
+ this.register(new new_outlook_detector_1.NewOutlookDetector()); // priority: -40 (Specific)
21
+ this.register(new outlook_fr_detector_1.OutlookFRDetector()); // priority: -30 (Fallback for FR)
22
+ this.register(new reply_detector_1.ReplyDetector()); // priority: -10 (Replies)
23
+ this.register(new crisp_detector_1.CrispDetector()); // priority: 100 (Universal fallback)
24
24
  // Register custom detectors
25
25
  customDetectors.forEach(detector => this.register(detector));
26
26
  }
package/dist/index.js CHANGED
@@ -53,17 +53,17 @@ async function extractDeepestHybrid(raw, options) {
53
53
  const inlineResult = await (0, inline_layer_1.processInline)(mimeResult.rawBody, mimeResult.depth, mimeResult.history, opts.customDetectors);
54
54
  // Step 3: Align results
55
55
  let from = (0, utils_1.normalizeFrom)(inlineResult.from);
56
- let to = inlineResult.to;
56
+ let to = (0, utils_1.normalizeFrom)(inlineResult.to);
57
57
  let subject = inlineResult.subject;
58
58
  let date_raw = inlineResult.date_raw;
59
59
  let date_iso = inlineResult.date_iso;
60
60
  let text = inlineResult.text;
61
61
  if (inlineResult.diagnostics.method === 'fallback' && mimeResult.metadata) {
62
62
  const m = mimeResult.metadata;
63
- if (!from && m.from?.value?.[0]) {
63
+ if ((!from || !from.address) && m.from?.value?.[0]) {
64
64
  from = (0, utils_1.normalizeFrom)({ name: m.from.value[0].name, address: m.from.value[0].address });
65
65
  }
66
- if (!to && m.to?.value?.[0]) {
66
+ if ((!to || !to.address) && m.to?.value?.[0]) {
67
67
  to = (0, utils_1.normalizeFrom)({ name: m.to.value[0].name, address: m.to.value[0].address });
68
68
  }
69
69
  if (!subject && m.subject)
@@ -121,7 +121,7 @@ async function processInline(text, depth, baseHistory = [], customDetectors = []
121
121
  attachments: [],
122
122
  history: history.slice().reverse(),
123
123
  diagnostics: {
124
- method: (deepestEntry.flags.find(f => f.startsWith('method:')) || 'inline'),
124
+ method: (deepestEntry.flags.find(f => f.startsWith('method:'))?.replace('method:', '') || 'inline'),
125
125
  depth: currentDepth - startingDepth,
126
126
  parsedOk: true,
127
127
  warnings: warnings
package/dist/utils.js CHANGED
@@ -221,6 +221,9 @@ function normalizeFrom(from) {
221
221
  if (from.address) {
222
222
  from.address = from.address.replace(/^[\*\_]+|[\*\_]+$/g, '').trim();
223
223
  }
224
+ // FINAL VALIDATION: If at the end we have no address and no name, return null
225
+ if (!from.address && !from.name)
226
+ return null;
224
227
  return from;
225
228
  }
226
229
  function normalizeParserResult(parsed, method, depth, warnings = []) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "email-origin-chain",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
4
4
  "description": "Uncover the full audit trail of your email threads. Recursively reconstructs the entire conversation history with instant access to the original sender and true source message.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",