email-forward-parser 1.0.6 → 1.0.7

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.
Files changed (2) hide show
  1. package/lib/parser.js +36 -13
  2. package/package.json +1 -1
package/lib/parser.js CHANGED
@@ -593,11 +593,16 @@ class Parser {
593
593
  __parseOriginalTo(text) {
594
594
  // First method: extract the primary recipient(s) via the To part \
595
595
  // (Apple Mail, Gmail, Outlook Live, New Outlook 2019, Thunderbird)
596
- var _recipients = this.__parseMailbox(this.__regexes.original_to, text);
596
+ var _recipients = this.__parseMailbox(
597
+ this.__regexes.original_to,
598
+
599
+ text,
600
+ true //- [force_array]
601
+ );
597
602
 
598
603
  // Recipient(s) found?
599
- if (Array.isArray(_recipients) ||
600
- !(_recipients.address === null && _recipients.name === null)
604
+ if (Array.isArray(_recipients) &&
605
+ !(_recipients[0].address === null && _recipients[0].name === null)
601
606
  ) {
602
607
  return _recipients;
603
608
  }
@@ -626,8 +631,12 @@ class Parser {
626
631
  "replace"
627
632
  );
628
633
 
634
+ return this.__parseMailbox(
635
+ this.__regexes.original_to_lax,
629
636
 
630
- return this.__parseMailbox(this.__regexes.original_to_lax, _cleanText);
637
+ _cleanText,
638
+ true //- [force_array]
639
+ );
631
640
  }
632
641
 
633
642
 
@@ -640,11 +649,16 @@ class Parser {
640
649
  __parseOriginalCc(text) {
641
650
  // First method: extract the carbon-copy recipient(s) via the Cc part
642
651
  // (Apple Mail, Gmail, Outlook Live, New Outlook 2019, Thunderbird)
643
- var _recipients = this.__parseMailbox(this.__regexes.original_cc, text);
652
+ var _recipients = this.__parseMailbox(
653
+ this.__regexes.original_cc,
654
+
655
+ text,
656
+ true //- [force_array]
657
+ );
644
658
 
645
659
  // Recipient(s) found?
646
- if (Array.isArray(_recipients) ||
647
- !(_recipients.address === null && _recipients.name === null)
660
+ if (Array.isArray(_recipients) &&
661
+ !(_recipients[0].address === null && _recipients[0].name === null)
648
662
  ) {
649
663
  return _recipients;
650
664
  }
@@ -666,17 +680,24 @@ class Parser {
666
680
  "replace"
667
681
  );
668
682
 
669
- return this.__parseMailbox(this.__regexes.original_cc_lax, _cleanText);
683
+ return this.__parseMailbox(
684
+ this.__regexes.original_cc_lax,
685
+
686
+ _cleanText,
687
+ true //- [force_array]
688
+ );
670
689
  }
671
690
 
672
691
 
673
692
  /**
674
693
  * Parses mailboxes(s)
675
694
  * @private
676
- * @param {string} text
677
- * @return {object} The parsed mailboxes(s)
695
+ * @param {object} regexes
696
+ * @param {string} text
697
+ * @param {boolean} [force_array]
698
+ * @return {object} The parsed mailboxes(s)
678
699
  */
679
- __parseMailbox(regexes, text) {
700
+ __parseMailbox(regexes, text, force_array=false) {
680
701
  var _match = loopRegexes(regexes, text);
681
702
 
682
703
  if (_match && _match.length > 0) {
@@ -723,14 +744,16 @@ class Parser {
723
744
  }
724
745
 
725
746
  // Return single mailbox
726
- return _mailboxes[0];
747
+ return (force_array === true) ? _mailboxes : _mailboxes[0];
727
748
  }
728
749
  }
729
750
 
730
- return {
751
+ var _mailbox = {
731
752
  address : null,
732
753
  name : null
733
754
  };
755
+
756
+ return (force_array === true) ? [_mailbox] : _mailbox;
734
757
  }
735
758
 
736
759
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "email-forward-parser",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "Parses forwarded emails and extract content",
5
5
  "author": "Eliott Vincent <eliott@crisp.chat>",
6
6
  "main": "lib/index.js",