Skip to content

allow using custom regexes #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ declare module "node-email-reply-parser" {
}
type ReplyParserRegular = (emailContent: string) => Email;
type ReplyParserVisibleTextOnly = (emailContent: string, visibleTextOnly: true) => string;
const replyParser: ReplyParserRegular & ReplyParserVisibleTextOnly;
type ReplyParserWithOptions = (emailContent: string, visibleTextOnly: boolean, options: { signatureRegex?: RegExp; quotedLineRegex?: RegExp; quoteHeadersRegex?: RegExp[] }) => Email;

const replyParser: ReplyParserRegular & ReplyParserVisibleTextOnly & ReplyParserWithOptions;
export = replyParser;
}
8 changes: 6 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ var Parser = require("./lib/Parser");
* Parses the given text into an email
* @param {string} text the email text to parse
* @param {boolean} [visibleTextOnly] if true, the visible text will be returned instead of an Email
* @param {object} [options] the options to pass to the parser
* @param {RegExp} [options.signatureRegex] the regular expression used to match signatures
* @param {RegExp} [options.quotedLineRegex] the regular expression used to match quoted lines
* @param {RegExp[]} [options.quoteHeadersRegex] the regular expressions used to find quoted sections based on the header
* @returns {Email|string} the parsed Email or visible text, depending on the second argument
*/
function parse(text, visibleTextOnly) {
var parser = new Parser();
function parse(text, visibleTextOnly, options) {
var parser = new Parser(options?.signatureRegex, options?.quotedLineRegex, options?.quoteHeadersRegex);
var email = parser.parse(text);

if (visibleTextOnly) {
Expand Down