-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: optimize MX server by switching to
striptags
instead of `html-…
…to-text` and improved performance of parseAddresses helper function, discovered bug where ARC broken due to DKIM on MX (will fix)
- Loading branch information
Showing
12 changed files
with
58 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,30 +3,54 @@ | |
* SPDX-License-Identifier: BUSL-1.1 | ||
*/ | ||
|
||
const _ = require('lodash'); | ||
const addressParser = require('nodemailer/lib/addressparser'); | ||
const addrs = require('email-addresses'); | ||
const isSANB = require('is-string-and-not-blank'); | ||
|
||
const isEmail = require('#helpers/is-email'); | ||
|
||
// | ||
// NOTE: if we ever use `email-regex-safe` in future | ||
// we need to ensure `tlds` are considered against punycode toASCII cases | ||
// | ||
|
||
// <https://github.com/validatorjs/validator.js/issues/2508> | ||
function parseAddresses(input) { | ||
if (!isSANB(input)) return []; | ||
|
||
// <[email protected]> | ||
if ( | ||
input.startsWith('<') && | ||
input.endsWith('>') && | ||
isEmail(input.slice(1, -1)) | ||
) | ||
return [input.slice(1, -1)]; | ||
|
||
// [email protected] | ||
if (isEmail(input)) return [input]; | ||
|
||
// more complex stuff here | ||
// `"Adobe Acrobat" <[email protected]>` | ||
// `"[email protected]" <[email protected]>, "[email protected]" <[email protected]>` | ||
let addresses = addrs.parseAddressList({ input, partial: true }) || []; | ||
|
||
// | ||
// NOTE: we can't use `email-regex-safe` for values with quotes and such because it returns the wrong values (and dups) | ||
// | ||
// > const emailRegexSafe = require('email-regex-safe') | ||
// > `"[email protected]" <[email protected]>, "[email protected]" <[email protected]>`.match(emailRegexSafe()) | ||
// [ '[email protected]', '[email protected]', '[email protected]', '[email protected]' ] | ||
// | ||
|
||
if (addresses.length === 0) | ||
addresses = addrs.parseAddressList({ input }) || []; | ||
|
||
// safeguard | ||
if (addresses.length === 0) addresses = addressParser(input); | ||
|
||
addresses = addresses.filter( | ||
(addr) => _.isObject(addr) && isSANB(addr.address) && isEmail(addr.address) | ||
); | ||
|
||
return addresses; | ||
return addresses | ||
.filter((addr) => isEmail(addr?.address)) | ||
.map((addr) => addr.address); | ||
} | ||
|
||
module.exports = parseAddresses; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters