Added missing index and address handler

This commit is contained in:
Andris Reinman 2020-07-21 19:31:23 +03:00
parent 408aadc07f
commit 0587c2934f
2 changed files with 47 additions and 0 deletions

View file

@ -611,3 +611,20 @@ indexes:
name: audit_files_expire
key:
metadata.info.expires: 1
- collection: audit.files
type: gridfs # index applies to gridfs database
index:
name: audit_files_addresses
key:
metadata.audit: 1
metadata.addresses.type: 1
metadata.addresses.name: 1
metadata.addresses.address: 1
- collection: audit.files
type: gridfs # index applies to gridfs database
index:
name: audit_files_subject
key:
metadata.subject: 1

View file

@ -3,6 +3,8 @@
const ObjectID = require('mongodb').ObjectID;
const GridFSBucket = require('mongodb').GridFSBucket;
const log = require('npmlog');
const libmime = require('libmime');
const { normalizeAddress } = require('./tools');
class AuditHandler {
constructor(options) {
@ -117,6 +119,34 @@ class AuditHandler {
metadata.audit = metadata.audit || audit;
metadata.date = metadata.date || new Date();
const headers = metadata.header || {};
metadata.subject = ([].concat(headers.subject || []).pop() || '').trim();
try {
metadata.subject = libmime.decodeWords(metadata.subject);
} catch (E) {
// ignore
}
metadata.addresses = [];
[('from', 'to', 'cc', 'bcc')].forEach(type => {
if (headers[type] && headers[type].length) {
headers[type].forEach(addr => {
let entry = {
name: addr.name,
address: normalizeAddress(addr.address),
type
};
try {
entry.name = libmime.decodeWords(entry.name);
} catch (E) {
// ignore
}
metadata.addresses.push(entry);
});
}
});
let result = await new Promise((resolve, reject) => {
let stream = this.gridstore.openUploadStreamWithId(id, null, {
contentType: 'message/rfc822',