Skip to content

Commit

Permalink
Improve parsing of From address, now supporting parts of the obsolete…
Browse files Browse the repository at this point in the history
… Syntax
  • Loading branch information
lieser committed Feb 7, 2021
1 parent 8e72417 commit 87d6874
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions modules/rfcParser.mjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ export default class RfcParser {
//// 3.2.3. Atom
static get atext() { return "[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]"; }
static get atom() { return `(?:${this.CFWS_op}${this.atext}+${this.CFWS_op})`; }
// Note: helper only, not part of the RFC: an atom without the optional surrounding CFWS
static get atom_b() { return `(?:${this.atext}+)`; }
// Note: helper only, not part of the RFC: an atom without the optional surrounding CFWS. dot is included for obs-phrase
static get atom_b_obs() { return `(?:(?:${this.atext}|\\.)+)`; }
static get dot_atom_text() { return `(?:${this.atext}+(?:\\.${this.atext}+)*)`; }
static get dot_atom() { return `(?:${this.CFWS_op}${this.dot_atom_text}${this.CFWS_op})`; }
//// 3.2.4. Quoted Strings
Expand All @@ -56,8 +56,8 @@ export default class RfcParser {
static get quoted_string() { return `(?:${this.CFWS_op}"(?:${this.FWS_op}${this.qcontent})*${this.FWS_op}"${this.CFWS_op})`; }
//// 3.2.5. Miscellaneous Tokens
static get word() { return `(?:${this.atom}|${this.quoted_string})`; }
// Note: helper only, not part of the RFC: chain of word without whitespace between
static get word_chain() { return `(?:(?:${this.atom_b}|(?:${this.atom_b}?${this.quoted_string})+${this.atom_b}?))`; }
// Note: helper only, not part of the RFC: chain of word (including dot for obs-phrase) without whitespace between, or quoted string chain
static get word_chain() { return `(?:(?:${this.atom_b_obs}|(?:${this.atom_b_obs}?${this.quoted_string})+${this.atom_b_obs}?))`; }
// Note: this is incomplete (obs-phrase is missing)
// Note: this is rewritten to avoid backtracking issues (in RFC specified as `1*word / obs-phrase`)
static get phrase() { return `(?:${this.CFWS_op}${this.word_chain}(?:${this.CFWS}${this.word_chain})*${this.CFWS_op})`; }
Expand Down
6 changes: 3 additions & 3 deletions test/unittest/msgParserSpec.mjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,12 @@ describe("Message parser [unittest]", function () {
).to.be.equal("c@public.example");
});
it("RFC 5322 Appendix A - Obsolete", function () {
// Obsolete syntax is not supported and should fail
// Obsolete syntax is only partly supported

// Appendix A.6.1. Obsolete Addressing
expect(() =>
expect(
MsgParser.parseFromHeader("From: Joe Q. Public <john.q.public@example.com>\r\n")
).to.throw();
).to.be.equal("john.q.public@example.com");
// Appendix A.6.3. Obsolete White Space and Comments
expect(() =>
MsgParser.parseFromHeader("From : John Doe <jdoe@machine(comment). example>\r\n")
Expand Down

0 comments on commit 87d6874

Please sign in to comment.