Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

smtp-address-parser

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

smtp-address-parser - npm Package Compare versions

Comparing version 1.0.4 to 1.0.6

5

dist/lib/index.d.ts
export declare function parse(address: string): any;
/**
* Apply common address normalization rules, strip "+something" and
* remove interior "."s in a dotString. Fold case.
*/
export declare function normalize(address: string): string;

37

dist/lib/index.js

@@ -1,2 +0,2 @@

'use strict';
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -6,7 +6,7 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

Object.defineProperty(exports, "__esModule", { value: true });
exports.parse = void 0;
exports.normalize = exports.parse = void 0;
// const punycode = require('punycode');
const nearley = require('nearley');
const nearley = require("nearley");
const grammar_1 = __importDefault(require("./grammar"));
grammar_1.default.ParserStart = 'Mailbox';
grammar_1.default.ParserStart = "Mailbox";
const grammar = nearley.Grammar.fromCompiled(grammar_1.default);

@@ -23,2 +23,31 @@ // <https://tools.ietf.org/html/rfc5321#section-4.1.2>

exports.parse = parse;
/**
* Apply common address normalization rules, strip "+something" and
* remove interior "."s in a dotString. Fold case.
*/
function normalize(address) {
const a = parse(address);
const domain = (function () {
if (a.domainPart.AddressLiteral)
return a.domainPart.AddressLiteral;
return a.domainPart.DomainName.toLowerCase();
})();
const local = (function () {
if (a.localPart.QuotedString) {
// Should normalize quoted string.
return a.localPart.QuotedString;
}
const tagless = (function () {
const plus_loc = a.localPart.DotString.indexOf("+");
if (plus_loc === -1) {
return a.localPart.DotString;
}
return a.localPart.DotString.substr(0, plus_loc);
})();
const dotless = tagless.replace(/\./g, "");
return dotless.toLowerCase();
})();
return `${local}@${domain}`;
}
exports.normalize = normalize;
//# sourceMappingURL=index.js.map

2

dist/test/addresses.test.d.ts
declare const assert: any;
declare const parse: any;
declare const normalize: any, parse: any;
declare function _check(address: string, dot?: string, quote?: string, name?: string, addr?: string): void;
"use strict";
const assert = require("assert");
const { parse } = require("../lib/index.js");
const { normalize, parse } = require("../lib/index.js");
function _check(address, dot, quote, name, addr) {

@@ -58,3 +58,3 @@ const a = parse(address);

});
it('Another IPv6 address literal', function () {
it("Another IPv6 address literal", function () {
_check("simple@[IPv6:68:1c:a2:12:4a:e5]", "simple", undefined, undefined, "[IPv6:68:1c:a2:12:4a:e5]");

@@ -68,3 +68,3 @@ });

});
it('General address literal', function () {
it("General address literal", function () {
_check("simple@[tag:Can-Be-Anything]", "simple", undefined, undefined, "[tag:Can-Be-Anything]");

@@ -162,2 +162,22 @@ });

});
describe("test normalize", function () {
it("foo@example.org", function () {
assert.equal(normalize("foo@example.org"), "foo@example.org");
});
it("foo+bar@example.org", function () {
assert.equal(normalize("foo+bar@example.org"), "foo@example.org");
});
it("foo+@example.org", function () {
assert.equal(normalize("foo+@example.org"), "foo@example.org");
});
it("foo.bar@example.org", function () {
assert.equal(normalize("foo.bar@example.org"), "foobar@example.org");
});
it("foo.bar+baz@example.org", function () {
assert.equal(normalize("foo.bar+baz@example.org"), "foobar@example.org");
});
it("Foo.Bar+Baz@Example.Org", function () {
assert.equal(normalize("Foo.Bar+Baz@Example.Org"), "foobar@example.org");
});
});
//# sourceMappingURL=addresses.test.js.map

@@ -1,8 +0,8 @@

'use strict';
"use strict";
// const punycode = require('punycode');
const nearley = require('nearley');
const nearley = require("nearley");
import { default as myGrammar } from './grammar';
myGrammar.ParserStart = 'Mailbox';
import { default as myGrammar } from "./grammar";
myGrammar.ParserStart = "Mailbox";
const grammar = nearley.Grammar.fromCompiled(myGrammar);

@@ -22,1 +22,29 @@

}
/**
* Apply common address normalization rules, strip "+something" and
* remove interior "."s in a dotString. Fold case.
*/
export function normalize(address: string) {
const a = parse(address);
const domain = (function () {
if (a.domainPart.AddressLiteral) return a.domainPart.AddressLiteral;
return a.domainPart.DomainName.toLowerCase();
})();
const local = (function () {
if (a.localPart.QuotedString) {
// Should normalize quoted string.
return a.localPart.QuotedString;
}
const tagless = (function () {
const plus_loc = a.localPart.DotString.indexOf("+");
if (plus_loc === -1) {
return a.localPart.DotString;
}
return a.localPart.DotString.substr(0, plus_loc);
})();
const dotless = tagless.replace(/\./g, "");
return dotless.toLowerCase();
})();
return `${local}@${domain}`;
}
{
"name": "smtp-address-parser",
"version": "1.0.4",
"version": "1.0.6",
"description": "Parse an SMTP (RFC-5321) address",

@@ -5,0 +5,0 @@ "main": "dist/lib/index.js",

@@ -24,2 +24,2 @@ # smtp-address-parser

“To the maximum extent possible, implementation techniques that impose
no limits on the length of these objects should be used.”
no limits on the length of these objects should be used.”

@@ -5,3 +5,3 @@ "use strict";

const { parse } = require("../lib/index.js");
const { normalize, parse } = require("../lib/index.js");

@@ -70,3 +70,3 @@ function _check(address: string, dot?: string, quote?: string, name?: string, addr?: string) {

});
it('Another IPv6 address literal', function () {
it("Another IPv6 address literal", function () {
_check("simple@[IPv6:68:1c:a2:12:4a:e5]", "simple", undefined, undefined, "[IPv6:68:1c:a2:12:4a:e5]");

@@ -80,3 +80,3 @@ });

});
it('General address literal', function () {
it("General address literal", function () {
_check("simple@[tag:Can-Be-Anything]", "simple", undefined, undefined, "[tag:Can-Be-Anything]");

@@ -175,1 +175,22 @@ });

});
describe("test normalize", function () {
it("foo@example.org", function () {
assert.equal(normalize("foo@example.org"), "foo@example.org");
});
it("foo+bar@example.org", function () {
assert.equal(normalize("foo+bar@example.org"), "foo@example.org");
});
it("foo+@example.org", function () {
assert.equal(normalize("foo+@example.org"), "foo@example.org");
});
it("foo.bar@example.org", function () {
assert.equal(normalize("foo.bar@example.org"), "foobar@example.org");
});
it("foo.bar+baz@example.org", function () {
assert.equal(normalize("foo.bar+baz@example.org"), "foobar@example.org");
});
it("Foo.Bar+Baz@Example.Org", function () {
assert.equal(normalize("Foo.Bar+Baz@Example.Org"), "foobar@example.org");
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc