From be8d302b82c7d23c2b19dae9b85ea43f12cbfd51 Mon Sep 17 00:00:00 2001 From: the-djmaze <> Date: Sun, 4 Feb 2024 23:25:31 +0100 Subject: [PATCH] Improved MIME email addresses parse info --- dev/Mime/Parser.js | 15 +++++++++------ dev/Mime/Utils.js | 1 - dev/Model/EmailCollection.js | 20 ++++++++++++++++++++ dev/Model/Message.js | 10 +++++----- 4 files changed, 34 insertions(+), 12 deletions(-) diff --git a/dev/Mime/Parser.js b/dev/Mime/Parser.js index ce96843515..91e744addc 100644 --- a/dev/Mime/Parser.js +++ b/dev/Mime/Parser.js @@ -16,12 +16,13 @@ export function ParseMime(text) this.boundary = ''; this.bodyText = ''; // https://datatracker.ietf.org/doc/html/rfc2822#section-3.6 + // https://datatracker.ietf.org/doc/html/rfc4021 this.headers = { // Required date = null, from = [], // mailbox-list // Optional - sender = [], // MUST occur with multi-address + sender = [], // mailbox MUST occur with multi-address 'reply-to' = [], // address-list to = [], // address-list cc = [], // address-list @@ -34,7 +35,6 @@ export function ParseMime(text) comments = [], // unstructured keywords = [], // phrase *("," phrase) // https://datatracker.ietf.org/doc/html/rfc2822#section-3.6.6 - trace = [], 'resent-date' = [], 'resent-from' = [], 'resent-sender' = [], @@ -42,13 +42,15 @@ export function ParseMime(text) 'resent-cc' = [], 'resent-bcc' = [], 'resent-msg-id' = [], + // https://datatracker.ietf.org/doc/html/rfc2822#section-3.6.7 + trace = [], + 'return-path' = '', // angle-addr + received = [], // optional others outside RFC2822 - 'mime-version' = '', + 'mime-version' = '', // RFC2045 'content-transfer-encoding' = '', 'content-type' = '', - 'delivered-to' = '', // angle-addr - 'return-path' = '', // angle-addr - 'received' = [], + 'delivered-to' = [], // RFC9228 addr-spec 'authentication-results' = '', // dkim, spf, dmarc 'dkim-signature' = '', 'x-rspamd-queue-id' = '', @@ -57,6 +59,7 @@ export function ParseMime(text) 'x-rspamd-server' = '', 'x-spamd-result' = '', 'x-remote-address' = '', + // etc. }; } */ diff --git a/dev/Mime/Utils.js b/dev/Mime/Utils.js index 0da0dc7ade..51a18b6b93 100644 --- a/dev/Mime/Utils.js +++ b/dev/Mime/Utils.js @@ -77,7 +77,6 @@ export function MimeToMessage(data, message) const text = struct.getByContentType('text/plain'); message.plain(text ? text.body : ''); message.html(html); -console.dir({message}); } else { message.plain(data); } diff --git a/dev/Model/EmailCollection.js b/dev/Model/EmailCollection.js index 8945fbe972..8722ff78e5 100644 --- a/dev/Model/EmailCollection.js +++ b/dev/Model/EmailCollection.js @@ -52,4 +52,24 @@ export class EmailCollectionModel extends AbstractCollectionModel } } + /** + * @param {array} [{name: "Name", email: "address@domain"}] + */ +/* + static fromArray(addresses) { + let list = new this(); + list.fromArray(addresses); + return list; + } + fromArray(addresses) { + addresses.forEach(item => { + item = new EmailModel(item.email, item.name); + // Make them unique + if (item.email && item.name || !this.find(address => address.email == item.email)) { + this.push(item); + } + }); + } +*/ + } diff --git a/dev/Model/Message.js b/dev/Model/Message.js index 0c886cbe55..031ab10512 100644 --- a/dev/Model/Message.js +++ b/dev/Model/Message.js @@ -235,11 +235,11 @@ export class MessageModel extends AbstractModel { this.messageId = headers.valueByName('Message-Id'); this.subject(headers.valueByName('Subject')); this.sender = EmailCollectionModel.fromString(headers.valueByName('Sender')); - this.from = EmailCollectionModel.fromString(headers.valueByName('From')); - this.replyTo = EmailCollectionModel.fromString(headers.valueByName('Reply-To')); - this.to = EmailCollectionModel.fromString(headers.valueByName('To')); - this.cc = EmailCollectionModel.fromString(headers.valueByName('Cc')); - this.bcc = EmailCollectionModel.fromString(headers.valueByName('Bcc')); + this.from = EmailCollectionModel.fromArray(headers.valueByName('From')); + this.replyTo = EmailCollectionModel.fromArray(headers.valueByName('Reply-To')); + this.to = EmailCollectionModel.fromArray(headers.valueByName('To')); + this.cc = EmailCollectionModel.fromArray(headers.valueByName('Cc')); + this.bcc = EmailCollectionModel.fromArray(headers.valueByName('Bcc')); this.inReplyTo = headers.valueByName('In-Reply-To'); this.deliveredTo = EmailCollectionModel.fromString(headers.valueByName('Delivered-To'));