Skip to content

Commit

Permalink
Introduced deliverability reporting request/models
Browse files Browse the repository at this point in the history
  • Loading branch information
ey-mailosaur authored Sep 30, 2024
1 parent e2f14a3 commit 7797107
Show file tree
Hide file tree
Showing 11 changed files with 294 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/models/blockListResult.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class BlockListResult {
constructor(data = {}) {
this.id = data.id;
this.name = data.name;
this.result = data.result;
}
}

module.exports = BlockListResult;
15 changes: 15 additions & 0 deletions lib/models/content.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Content {
constructor(data = {}) {
this.embed = data.embed;
this.iframe = data.iframe;
this.object = data.object;
this.script = data.script;
this.shortUrls = data.shortUrls;
this.textSize = data.textSize;
this.totalSize = data.totalSize;
this.missingAlt = data.missingAlt;
this.missingListUnsubscribe = data.missingListUnsubscribe;
}
}

module.exports = Content;
19 changes: 19 additions & 0 deletions lib/models/deliverabilityReport.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const EmailAuthenticationResult = require('./emailAuthenticationResult');
const BlockListResult = require('./blockListResult');
const Content = require('./content');
const DnsRecords = require('./dnsRecords');
const SpamAssassinResult = require('./spamAssassinResult');

class DeliverabilityReport {
constructor(data = {}) {
this.spf = new EmailAuthenticationResult(data.spf);
this.dkim = (data.dkim || []).map((i) => (new EmailAuthenticationResult(i)));
this.dmarc = new EmailAuthenticationResult(data.dmarc);
this.blockLists = (data.blockLists || []).map((i) => (new BlockListResult(i)));
this.content = new Content(data.content);
this.dnsRecords = new DnsRecords(data.dnsRecords);
this.spamAssassin = new SpamAssassinResult(data.spamAssassin);
}
}

module.exports = DeliverabilityReport;
9 changes: 9 additions & 0 deletions lib/models/dnsRecords.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class DnsRecords {
constructor(data = {}) {
this.a = data.a;
this.mx = data.mx;
this.ptr = data.ptr;
}
}

module.exports = DnsRecords;
10 changes: 10 additions & 0 deletions lib/models/emailAuthenticationResult.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class EmailAuthenticationResult {
constructor(data = {}) {
this.result = data.result;
this.description = data.description;
this.rawValue = data.rawValue;
this.tags = data.tags;
}
}

module.exports = EmailAuthenticationResult;
153 changes: 153 additions & 0 deletions lib/models/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,159 @@ export interface SpamAnalysisResult {
score?: number;
}


/**
* The results of deliverability report performed by Mailosaur.
*/
export interface DeliverabilityReport {
/**
* The result of checking for SPF issues
*/
spf?: EmailAuthenticationResult;
/**
* The result of checking for DKIM issues
*/
dkim?: EmailAuthenticationResult[];
/**
* The result of checking for DMARC issues
*/
dmarc?: EmailAuthenticationResult;
/**
* The result of each blocklist that was checked
*/
blockLists?: BlockListResult[];
/**
* The result of content checks made on the email
*/
content?: Content;
/**
* The DNS records checks made against the sender's domain
*/
dnsRecords?: DnsRecords;
/**
* The result of spam analysis performed by Mailosaur
*/
spamAssassin?: SpamAssassinResult;
}

/**
* The result of an email domain check
*/
export interface EmailAuthenticationResult {
/**
* The result of the check
*/
result: string;
/**
* A description of any issue/notes found
*/
description: string;
/**
* The raw values returned from the check
*/
rawValue: string;
/**
* The seperated tags returned from the check
*/
tags: { [key: string]: string};
}

/**
* The result of an domain check against a blocklist checker
*/
export interface BlockListResult{
/**
* The identifier of the blocklist
*/
id: string;
/**
* The name of the blocklist
*/
name: string;
/**
* The result of the blocklist check
*/
result: string;
}

/**
* The results of email content analysis
*/
export interface Content{
/**
* The content contained embed tags
*/
embed: boolean;
/**
* The content contained Iframe tags
*/
iframe: boolean;
/**
* The content contained object tags
*/
object: boolean;
/**
* The content contained script tags
*/
script: boolean;
/**
* The content contained URL's that have been shortened
*/
shortUrls: boolean;
/**
* The length of all text that the content contained
*/
textSize: number;
/**
* The length of all HTML that the content contained
*/
totalSize: number;
/**
* Image(s) were missing "alt" properties
*/
missingAlt: boolean;
/**
* The message is missing a "List-Unsubscribe" header
*/
missingListUnsubscribe: boolean;
}

/**
* The records found when checking DNS records of an email sender's domain
*/
export interface DnsRecords{
/**
* The A Records of the sender's domain
*/
a: string[];
/**
* The MX Records of the sender's domain
*/
mx: string[];
/**
* The PTR Record of the sender's domain
*/
ptr: string[];
}

/**
* The results of spam assassin check performed by Mailosaur.
*/
export interface SpamAssassinResult{
/**
* Overall Mailosaur spam score.
*/
score: number;
/**
* The result of the spam check
*/
result: string;
/**
* Spam Assassin filter rules.
*/
rules?: SpamAssassinRule[];
}

/**
* The detail of an individual account limit.
*/
Expand Down
6 changes: 6 additions & 0 deletions lib/models/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
exports.SpamAssassinRule = require('./spamAssassinRule');
exports.SpamFilterResults = require('./spamFilterResults');
exports.SpamAnalysisResult = require('./spamAnalysisResult');
exports.DeliverabilityReport = require('./deliverabilityReport');
exports.EmailAuthenticationResult = require('./emailAuthenticationResult');
exports.BlockListResult = require('./blockListResult');
exports.Content = require('./content');
exports.DnsRecords = require('./dnsRecords');
exports.SpamAssassinResult = require('./spamAssassinResult');
exports.MailosaurError = require('./mailosaurError');
exports.MessageAddress = require('./messageAddress');
exports.Link = require('./link');
Expand Down
11 changes: 11 additions & 0 deletions lib/models/spamAssassinResult.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const SpamAssassinRule = require('./spamAssassinRule');

class SpamAssassinResult {
constructor(data = {}) {
this.score = data.score;
this.result = data.result;
this.rules = (data.rules || []).map((i) => (new SpamAssassinRule(i)));
}
}

module.exports = SpamAssassinResult;
15 changes: 15 additions & 0 deletions lib/operations/analysis.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const SpamAnalysisResult = require('../models/spamAnalysisResult');
const DeliverabilityReport = require('../models/deliverabilityReport');

class Analysis {
constructor(client) {
Expand All @@ -18,6 +19,20 @@ class Analysis {
});
});
}

deliverability(messageId) {
const self = this;
const url = `api/analysis/deliverability/${messageId}`;

return new Promise((resolve, reject) => {
self.client.request.get(url, (err, response, body) => {
if (err || response.statusCode !== 200) {
return reject(err || self.client.httpError(response));
}
resolve(new DeliverabilityReport(body));
});
});
}
}

module.exports = Analysis;
10 changes: 10 additions & 0 deletions lib/operations/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ export interface Analysis {
*/
messageId: string
): Promise<models.SpamAnalysisResult>;

/**
* Perform a deliverability report of an email.
*/
deliverability(
/**
* The identifier of the message to be analyzed.
*/
messageId: string
): Promise<models.DeliverabilityReport>;
}

/**
Expand Down
37 changes: 37 additions & 0 deletions test/emails.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,43 @@ describe('emails', () => {
});
});

describe('deliverabilityReport', () => {
it('should perform a deliverability report on an email', async () => {
const targetId = emails[0].id;
const result = await client.analysis.deliverability(targetId);

assert.isOk(result.spf);

assert.isOk(result.dkim);
result.dkim.forEach((dkim) => {
assert.isOk(dkim);
});

assert.isOk(result.dmarc);

assert.isOk(result.blockLists);
result.blockLists.forEach((blockList) => {
assert.isOk(blockList);
assert.isOk(blockList.id);
assert.isOk(blockList.name);
});

assert.isOk(result.content);

assert.isOk(result.dnsRecords);
assert.isOk(result.dnsRecords.a);
assert.isOk(result.dnsRecords.mx);
assert.isOk(result.dnsRecords.ptr);

assert.isOk(result.spamAssassin);
result.spamAssassin.rules.forEach((rule) => {
assert.isNumber(rule.score);
assert.isOk(rule.rule);
assert.isOk(rule.description);
});
});
});

describe('del', () => {
it('should delete an email', async () => {
const targetEmailId = emails[4].id;
Expand Down

0 comments on commit 7797107

Please sign in to comment.