Skip to content

Commit

Permalink
Add new metadata values
Browse files Browse the repository at this point in the history
  • Loading branch information
jm-mailosaur committed Dec 2, 2021
1 parent 1fd1bc4 commit 64ff108
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
28 changes: 20 additions & 8 deletions lib/models/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,26 @@ export interface Metadata {
* Message headers
*/
headers?: MessageHeader[];
/**
* The fully-qualified domain name or IP address that was provided with the
* Extended HELLO (EHLO) or HELLO (HELO) command. This value is generally
* used to identify the SMTP client.
* https://datatracker.ietf.org/doc/html/rfc5321#section-4.1.1.1
*/
ehlo: string;
/**
* The source mailbox/email address, referred to as the 'reverse-path',
* provided via the MAIL command during the SMTP transaction.
* https://datatracker.ietf.org/doc/html/rfc5321#section-4.1.1.2
*/
mailFrom?: string;
/**
* The recipient email addresses, each referred to as a 'forward-path',
* provided via the RCPT command during the SMTP transaction.
* https://datatracker.ietf.org/doc/html/rfc5321#section-4.1.1.3
*/
rcptTo?: MessageAddress[];

}

/**
Expand Down Expand Up @@ -165,10 +185,6 @@ export interface Message {
* An array of attachment metadata for any attached files.
*/
attachments?: Attachment[];
/**
* The email recipient given to Mailosaur by the sending server.
*/
rcpt?: MessageAddress[];
/**
* Further metadata related to the message, including email headers.
*/
Expand Down Expand Up @@ -221,10 +237,6 @@ export interface MessageSummary {
* The number of attachments associated with the message.
*/
attachments?: number;
/**
* The email recipient given to Mailosaur by the sending server.
*/
rcpt?: MessageAddress[];
/**
* Identifier for the server in which the message is located.
*/
Expand Down
4 changes: 4 additions & 0 deletions lib/models/metadata.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
const MessageAddress = require('./messageAddress');
const MessageHeader = require('./messageHeader');

class Metadata {
constructor(data = {}) {
this.headers = (data.headers || []).map((i) => (new MessageHeader(i)));
this.ehlo = data.ehlo;
this.mailFrom = data.mailFrom;
this.rcptTo = (data.rcptTo || []).map((i) => (new MessageAddress(i)));
}
}

Expand Down
3 changes: 3 additions & 0 deletions test/emails.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ const validateEmail = (email) => {
validateAttachments(email);
validateHtml(email);
validateText(email);
assert.isOk(email.metadata.ehlo, 'ehlo is empty');
assert.isOk(email.metadata.mailFrom, 'mailFrom is empty');
assert.equal(email.metadata.rcptTo.length, 1);
};

const validateEmailSummary = (email) => {
Expand Down
2 changes: 1 addition & 1 deletion test/servers.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ describe('servers', () => {
assert.equal(err.message, 'Request had one or more invalid parameters.');
assert.equal(err.errorType, 'invalid_request');
assert.equal(err.httpStatusCode, 400);
assert.isTrue(err.httpResponseBody.indexOf('"type":') !== -1);
assert.isTrue(err.httpResponseBody.indexOf('{"type":') !== -1);
done();
});
});
Expand Down

0 comments on commit 64ff108

Please sign in to comment.