diff --git a/indexes.yaml b/indexes.yaml index 42bf70c6..5dfbbc95 100644 --- a/indexes.yaml +++ b/indexes.yaml @@ -364,6 +364,7 @@ indexes: name: messagelog_id_hashed key: id: hashed + - collection: messagelog index: name: messagelog_autoexpire diff --git a/lib/api/messages.js b/lib/api/messages.js index dba0bbd2..adf514c4 100644 --- a/lib/api/messages.js +++ b/lib/api/messages.js @@ -826,19 +826,7 @@ module.exports = (db, server, messageHandler) => { let response = { success: true, id: messageData._id, - events: [ - { - id: messageData.meta.queueId, - action: 'STORE', - messageId: messageData.msgid, - source: messageData.meta.source, - origin: messageData.meta.origin, - from: messageData.meta.from, - to: messageData.meta.to, - transtype: messageData.meta.transtype, - time: messageData.meta.time - } - ] + events: [] .concat( logEntries.map(entry => ({ id: entry.id, diff --git a/lib/filter-handler.js b/lib/filter-handler.js index 3c8ef544..60c8bde0 100644 --- a/lib/filter-handler.js +++ b/lib/filter-handler.js @@ -179,6 +179,29 @@ class FilterHandler { let mailboxQueryKey = 'path'; let mailboxQueryValue = 'INBOX'; + let meta = options.meta || {}; + + let received = [].concat((prepared.mimeTree.parsedHeader && prepared.mimeTree.parsedHeader.received) || []); + if (received.length) { + let receivedData = parseReceived(received[0]); + + if (!receivedData.has('id') && received.length > 1) { + receivedData = parseReceived(received[1]); + } + + if (receivedData.has('with')) { + meta.transtype = receivedData.get('with'); + } + + if (receivedData.has('id')) { + meta.queueId = receivedData.get('id'); + } + + if (receivedData.has('from')) { + meta.origin = receivedData.get('from'); + } + } + db.database .collection('filters') .find({ @@ -403,7 +426,7 @@ class FilterHandler { prepared, maildata, - meta: options.meta, + meta, filters: matchingFilters, @@ -414,27 +437,6 @@ class FilterHandler { skipExisting: true }; - let received = [].concat((prepared.mimeTree.parsedHeader && prepared.mimeTree.parsedHeader.received) || []); - if (received.length) { - let receivedData = parseReceived(received[0]); - - if (!receivedData.has('id') && received.length > 1) { - receivedData = parseReceived(received[1]); - } - - if (receivedData.has('with')) { - messageOpts.meta.transtype = receivedData.get('with'); - } - - if (receivedData.has('id')) { - messageOpts.meta.queueId = receivedData.get('id'); - } - - if (receivedData.has('from')) { - messageOpts.meta.origin = receivedData.get('from'); - } - } - if (outbound && outbound.length) { messageOpts.outbound = [].concat(outbound || []); } diff --git a/lib/message-handler.js b/lib/message-handler.js index 1f8779d1..a86c3edb 100644 --- a/lib/message-handler.js +++ b/lib/message-handler.js @@ -296,35 +296,48 @@ class MessageHandler { return rollback(err); } - let uidValidity = mailboxData.uidValidity; - let uid = messageData.uid; + this.database.collection('messagelog').insertOne({ + id: messageData.meta.queueId, + action: 'STORE', + parentId: messageData._id, + messageId: messageData.msgid, + source: messageData.meta.source, + origin: messageData.meta.origin, + from: messageData.meta.from, + to: messageData.meta.to, + transtype: messageData.meta.transtype, + time: messageData.meta.time || new Date() + }, () => { + let uidValidity = mailboxData.uidValidity; + let uid = messageData.uid; - if (options.session && options.session.selected && options.session.selected.mailbox === mailboxData.path) { - options.session.writeStream.write(options.session.formatResponse('EXISTS', messageData.uid)); - } - - this.notifier.addEntries( - mailboxData, - false, - { - command: 'EXISTS', - uid: messageData.uid, - ignore: options.session && options.session.id, - message: messageData._id, - modseq: messageData.modseq, - unseen: messageData.unseen - }, - () => { - this.notifier.fire(mailboxData.user, mailboxData.path); - return cleanup(null, true, { - uidValidity, - uid, - id: messageData._id, - mailbox: mailboxData._id, - status: 'new' - }); + if (options.session && options.session.selected && options.session.selected.mailbox === mailboxData.path) { + options.session.writeStream.write(options.session.formatResponse('EXISTS', messageData.uid)); } - ); + + this.notifier.addEntries( + mailboxData, + false, + { + command: 'EXISTS', + uid: messageData.uid, + ignore: options.session && options.session.id, + message: messageData._id, + modseq: messageData.modseq, + unseen: messageData.unseen + }, + () => { + this.notifier.fire(mailboxData.user, mailboxData.path); + return cleanup(null, true, { + uidValidity, + uid, + id: messageData._id, + mailbox: mailboxData._id, + status: 'new' + }); + } + ); + }); }); }); });