Skip to content

Commit

Permalink
Merge pull request #8 from shaunwarman/honor-report-size
Browse files Browse the repository at this point in the history
fix: honor report size in dmarc URI
  • Loading branch information
c0bra committed Apr 30, 2020
2 parents 14f4789 + 52036d7 commit e8ef5d5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
13 changes: 12 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ const validators = {
throw new Error(`Invalid value for '${term}': ${value}, must be a list of DMARC URIs such as 'mailto:some.email@somedomain.com'`);
}
let email = matches[1];
const limitRE = /!(.+)$/;
const limitMatch = email.match(limitRE);
if (limitMatch) {
const sizeLimit = limitMatch[0];
email = email.replace(sizeLimit, '');
}
if (!validator.validate(email)) {
throw new Error(`Invalid email address in '${term}': '${email}'`);
}
Expand All @@ -90,6 +96,12 @@ const validators = {
throw new Error(`Invalid value for '${term}': ${value}, must be a list of DMARC URIs such as 'mailto:some.email@somedomain.com'`);
}
let email = matches[1];
const limitRE = /!(.+)$/;
const limitMatch = email.match(limitRE);
if (limitMatch) {
const sizeLimit = limitMatch[0];
email = email.replace(sizeLimit, '');
}
if (!validator.validate(email)) {
throw new Error(`Invalid email address in '${term}': '${email}'`);
}
Expand Down Expand Up @@ -157,7 +169,6 @@ function parse(policy) {
let settings = validators[validatorTerm];

// Term matches validaor
debugger;
let termRegex = new RegExp(`^${validatorTerm}$`, 'i');
if (termRegex.test(term)) {
found = true;
Expand Down
4 changes: 4 additions & 0 deletions test/rua.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ test('rua with a good email succeeds', t => {
t.true(d('v=DMARC1; rua=mailto:word.up@wordup.co').messages === undefined);
});

test('rua with a good email and report size succeeds', t => {
t.true(d('v=DMARC1; rua=mailto:word.up@wordup.co!10m').messages === undefined);
});

test('rua with bad email fails', t => {
let ret = d('v=DMARC1; rua=mailto:bob@bob');
// console.log(ret);
Expand Down
4 changes: 4 additions & 0 deletions test/ruf.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ test('ruf with a good email succeeds', t => {
t.true(d('v=DMARC1; ruf=mailto:word.up@wordup.co').messages === undefined);
});

test('ruf with a good email and report size succeeds', t => {
t.true(d('v=DMARC1; ruf=mailto:word.up@wordup.co!10m').messages === undefined);
});

test('ruf with bad email fails', t => {
let ret = d('v=DMARC1; ruf=mailto:bob@bob');
// console.log(ret);
Expand Down

0 comments on commit e8ef5d5

Please sign in to comment.