store message entry to messagelog

This commit is contained in:
Andris Reinman 2017-10-27 11:50:37 +03:00
parent 50ed3fa4d7
commit a1b4431fb7
4 changed files with 66 additions and 62 deletions

View file

@ -364,6 +364,7 @@ indexes:
name: messagelog_id_hashed
key:
id: hashed
- collection: messagelog
index:
name: messagelog_autoexpire

View file

@ -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,

View file

@ -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 || []);
}

View file

@ -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'
});
}
);
});
});
});
});