Skip to content

Commit

Permalink
Merge branch 'master' of github.com:crisp-oss/email-reply-parser
Browse files Browse the repository at this point in the history
  • Loading branch information
valeriansaliou committed Jan 6, 2025
2 parents be8e556 + 71d8cb5 commit ff295b9
Show file tree
Hide file tree
Showing 14 changed files with 380 additions and 209 deletions.
4 changes: 2 additions & 2 deletions lib/email.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ class Email {

getVisibleText() {
return this.filterText((fragment) => {
return !fragment.isHidden;
return !fragment.isHidden();
});
}

getQuotedText() {
return this.filterText((fragment) => {
return fragment.isQuoted;
return fragment.isQuoted();
});
}

Expand Down
1 change: 0 additions & 1 deletion lib/emailreplyparser.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
var EmailParser = require("./parser/emailparser");

class EmailReplyParser {

read(text) {
return new EmailParser().parse(text);
}
Expand Down
20 changes: 10 additions & 10 deletions lib/fragment.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
class Fragment {
constructor(content, isHidden, isSignature, isQuoted) {
this.content = content;
this.isHidden = isHidden;
this.isSignature = isSignature;
this.isQuoted = isQuoted;
this._content = content;
this._isHidden = isHidden;
this._isSignature = isSignature;
this._isQuoted = isQuoted;
}

isHidden() {
return this.isHidden;
return this._isHidden;
}

isSignature() {
return this.isSignature;
return this._isSignature;
}

isQuoted() {
return this.isQuoted;
return this._isQuoted;
}

getContent() {
return this.content;
return this._content;
}

isEmpty() {
return "" === this.getContent.replace(/\n/g, "");
return "" === this.getContent().replace(/\n/g, "");
}

toString() {
return this.getContent();
}
}

module.exports = Fragment;
module.exports = Fragment;
29 changes: 24 additions & 5 deletions lib/regex.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,18 @@ class RegexList {
/^(.+\s<.+>\sschrieb:)$/m, // NAME <EMAIL> schrieb:
/^(.+\son.*at.*wrote:)$/m, // NAME on DATE wrote:
/^\s*(From\s?:.+\s?\n?\s*[\[|<].+[\]|>])/m, // "From: NAME <EMAIL>" OR "From : NAME <EMAIL>" OR "From : NAME<EMAIL>"(With support whitespace before start and before <)
/^\s*(Von\s?:.+\s?\n?\s*[\[|<].+[\]|>])/m, // "Von: NAME <EMAIL>" OR "Von : NAME <EMAIL>" OR "Von : NAME<EMAIL>"(With support whitespace before start and before <)
/^\s*(De\s?:.+\s?\n?\s*(\[|<).+(\]|>))/m, // "De: NAME <EMAIL>" OR "De : NAME <EMAIL>" OR "De : NAME<EMAIL>" (With support whitespace before start and before <)
/^\s*(Van\s?:.+\s?\n?\s*(\[|<).+(\]|>))/m, // "Van: NAME <EMAIL>" OR "Van : NAME <EMAIL>" OR "Van : NAME<EMAIL>" (With support whitespace before start and before <)
/^\s*(Da\s?:.+\s?\n?\s*(\[|<).+(\]|>))/m, // "Da: NAME <EMAIL>" OR "Da : NAME <EMAIL>" OR "Da : NAME<EMAIL>" (With support whitespace before start and before <)
/^(20[0-9]{2})-([0-9]{2}).([0-9]{2}).([0-9]{2}):([0-9]{2})\n?(.*)>:$/m, // 20YY-MM-DD HH:II GMT+01:00 NAME <EMAIL>:
/^\s*([a-z]{3,4}\.\s[\s\S]+\sskrev\s[\s\S]+:)$/m, // DATE skrev NAME <EMAIL>:
/^([0-9]{2}).([0-9]{2}).(20[0-9]{2})(.*)(([0-9]{2}).([0-9]{2}))(.*)\"( *)<(.*)>( *):$/m, // DD.MM.20YY HH:II NAME <EMAIL>
/^[0-9]{2}:[0-9]{2}(.*)[0-9]{4}(.*)\"( *)<(.*)>( *):$/, // HH:II, DATE, NAME <EMAIL>:
/^(.*)[0-9]{4}(.*)from(.*)<(.*)>:$/
/^(.*)[0-9]{4}(.*)from(.*)<(.*)>:$/,
/^-{1,12} ?(O|o)riginal (M|m)essage ?-{1,12}$/i,
/^-{1,12} ?(O|o)prindelig (B|b)esked ?-{1,12}$/i,
/^-{1,12} ?(M|m)essage d\'origine ?-{1,12}$/i
]);

this.signatureRegex = this.buildRe2([
Expand All @@ -38,20 +42,35 @@ class RegexList {
/^\+{2,4}$/, // Separator
/^\={2,4}$/, // Separator
/^________________________________$/, // Separator
/^-{1,10}Original message-{1,10}$/,

// EN
/^Sent from (?:\s*.+)$/, // en
/^Get Outlook for (?:\s*.+).*/m, // en
/^Cheers,?!?$/mi, // en
/^Thank you,?!?$/mi, // en
/^Best wishes,?!?$/mi, // en
/^\w{0,20}\s?(\sand\s)?Regards,?!??$/mi, //en

// DE
/^Von (?:\s*.+) gesendet$/, // de
/^Gesendet von (?:\s*.+) für (?:\s*.+)$/, // de

// DA
/^Sendt fra (?:\s*.+)$/, // da

// FR
/^Envoyé depuis (?:\s*.+)$/, //fr
/^Envoyé de mon (?:\s*.+)$/, // fr - e.g. Envoyé de mon iPhone
/^Envoyé à partir de (?:\s*.+)$/, //fr
/^Télécharger Outlook pour (?:\s*.+).*/m, // fr
/^Bien . vous,?!?$/mi, // fr
/^\w{0,20}\s?cordialement,?!?$/mi, // fr
/^Bonne (journ.e|soir.e)!?$/mi, // fr
/^Enviado desde (?:\s*.+)$/, // es

// ES
/^Enviado desde (?:\s*.+)$/, // es,

// NL
/^Verzonden vanaf (?:\s*.+)$/, // nl - e.g. Verzonden vanaf Outlook voor Android<https://aka.ms/12345>
]);
}

Expand All @@ -62,4 +81,4 @@ class RegexList {
}
}

module.exports = new RegexList();
module.exports = new RegexList();
Loading

0 comments on commit ff295b9

Please sign in to comment.