mirror of
https://github.com/nodemailer/wildduck.git
synced 2025-10-29 07:26:26 +08:00
show targets in /addresses result
This commit is contained in:
parent
08200e4795
commit
f46f9ddfe1
8 changed files with 179 additions and 10 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -1 +1 @@
|
|||
define({
"name": "wildduck",
"version": "1.0.0",
"description": "WildDuck API docs",
"title": "WildDuck API",
"url": "https://api.wildduck.email",
"sampleUrl": false,
"defaultVersion": "0.0.0",
"apidoc": "0.3.0",
"generator": {
"name": "apidoc",
"time": "2019-09-13T12:32:24.644Z",
"url": "http://apidocjs.com",
"version": "0.17.7"
}
});
|
||||
define({
"name": "wildduck",
"version": "1.0.0",
"description": "WildDuck API docs",
"title": "WildDuck API",
"url": "https://api.wildduck.email",
"sampleUrl": false,
"defaultVersion": "0.0.0",
"apidoc": "0.3.0",
"generator": {
"name": "apidoc",
"time": "2019-09-25T13:39:26.229Z",
"url": "http://apidocjs.com",
"version": "0.17.7"
}
});
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
{
"name": "wildduck",
"version": "1.0.0",
"description": "WildDuck API docs",
"title": "WildDuck API",
"url": "https://api.wildduck.email",
"sampleUrl": false,
"defaultVersion": "0.0.0",
"apidoc": "0.3.0",
"generator": {
"name": "apidoc",
"time": "2019-09-13T12:32:24.644Z",
"url": "http://apidocjs.com",
"version": "0.17.7"
}
}
|
||||
{
"name": "wildduck",
"version": "1.0.0",
"description": "WildDuck API docs",
"title": "WildDuck API",
"url": "https://api.wildduck.email",
"sampleUrl": false,
"defaultVersion": "0.0.0",
"apidoc": "0.3.0",
"generator": {
"name": "apidoc",
"time": "2019-09-25T13:39:26.229Z",
"url": "http://apidocjs.com",
"version": "0.17.7"
}
}
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ module.exports = (db, server, userHandler) => {
|
|||
* @apiSuccess {String} results.address E-mail address string
|
||||
* @apiSuccess {String} results.user User ID this address belongs to if this is a User address
|
||||
* @apiSuccess {Boolean} results.forwarded If true then it is a forwarded address
|
||||
* @apiSuccess {String[]} [results.target] List of forwarding targets
|
||||
*
|
||||
* @apiError error Description of the error
|
||||
*
|
||||
|
|
@ -252,6 +253,7 @@ module.exports = (db, server, userHandler) => {
|
|||
address: addressData.address,
|
||||
user: addressData.user,
|
||||
forwarded: addressData.targets && true,
|
||||
targets: addressData.targets && addressData.targets.map(t => t.value),
|
||||
tags: addressData.tags || []
|
||||
}))
|
||||
};
|
||||
|
|
|
|||
60
lib/audit.js
Normal file
60
lib/audit.js
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
'use strict';
|
||||
|
||||
const ObjectID = require('mongodb').ObjectID;
|
||||
const GridFSBucket = require('mongodb').GridFSBucket;
|
||||
|
||||
class AuditHandler {
|
||||
constructor(options) {
|
||||
this.options = options || {};
|
||||
this.gridfs = options.gridfs || options.database;
|
||||
|
||||
this.bucketName = this.options.bucket || 'audit';
|
||||
this.gridstore = new GridFSBucket(this.gridfs, {
|
||||
bucketName: this.bucketName,
|
||||
chunkSizeBytes: 255 * 1024,
|
||||
writeConcern: { w: this.options.writeConcern || 1 }
|
||||
});
|
||||
}
|
||||
|
||||
async store(audit, message, metadata) {
|
||||
if (!message) {
|
||||
throw new Error('Missing message content');
|
||||
}
|
||||
|
||||
if (typeof message === 'string') {
|
||||
message = Buffer.from(message);
|
||||
}
|
||||
|
||||
let id = new ObjectID();
|
||||
|
||||
metadata = metadata || {};
|
||||
metadata.audit = metadata.audit || audit;
|
||||
metadata.date = metadata.date || new Date();
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!Buffer.isBuffer(message) && typeof message.pipe !== 'function') {
|
||||
return reject(new Error('Invalid message content'));
|
||||
}
|
||||
|
||||
let stream = this.gridstore.openUploadStreamWithId(id, null, {
|
||||
contentType: 'message/rfc822',
|
||||
metadata
|
||||
});
|
||||
|
||||
stream.once('finish', () => resolve(id));
|
||||
|
||||
if (Buffer.isBuffer(message)) {
|
||||
// store as a buffer
|
||||
return stream.end(message);
|
||||
}
|
||||
|
||||
message.on('error', err => {
|
||||
stream.emit('error', err);
|
||||
});
|
||||
|
||||
message.pipe(stream);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = AuditHandler;
|
||||
107
lib/tasks/audit.js
Normal file
107
lib/tasks/audit.js
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
'use strict';
|
||||
|
||||
const log = require('npmlog');
|
||||
const db = require('../db');
|
||||
|
||||
let run = async (taskData, options) => {
|
||||
const messageHandler = options.messageHandler;
|
||||
const auditHandler = options.auditHandler;
|
||||
|
||||
let query = {
|
||||
user: taskData.user
|
||||
};
|
||||
|
||||
if (taskData.start) {
|
||||
let start = taskData.start;
|
||||
if (['number', 'string'].includes(typeof start)) {
|
||||
start = new Date(start);
|
||||
}
|
||||
query.idate = query.idate || {};
|
||||
query.idate.$gte = start;
|
||||
}
|
||||
|
||||
if (taskData.end) {
|
||||
let end = taskData.end;
|
||||
if (['number', 'string'].includes(typeof end)) {
|
||||
end = new Date(end);
|
||||
}
|
||||
query.idate = query.idate || {};
|
||||
query.idate.$lte = end;
|
||||
}
|
||||
|
||||
let processMessage = async messageData => {
|
||||
console.log(messageData);
|
||||
|
||||
let builder = messageHandler.indexer.rebuild(messageData.mimeTree);
|
||||
if (!builder || builder.type !== 'stream' || !builder.value) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let auditMessage = await auditHandler.store(taskData.audit, builder, {});
|
||||
return auditMessage;
|
||||
};
|
||||
|
||||
let processMessages = async collection => {
|
||||
let cursor = await db.users.collection(collection).find(query, {
|
||||
projection: {
|
||||
_id: true,
|
||||
user: true,
|
||||
mimeTree: true
|
||||
}
|
||||
});
|
||||
|
||||
let messageData;
|
||||
try {
|
||||
while ((messageData = await cursor.next())) {
|
||||
try {
|
||||
let auditMessage = await processMessage(messageData);
|
||||
log.verbose(
|
||||
'Tasks',
|
||||
'task=audit id=%s user=%s coll=%s message=%s src=%s dst=%s',
|
||||
taskData._id,
|
||||
taskData.user,
|
||||
collection,
|
||||
'Stored message to audit base',
|
||||
messageData._id,
|
||||
auditMessage
|
||||
);
|
||||
} catch (err) {
|
||||
log.error(
|
||||
'Tasks',
|
||||
'task=audit id=%s user=%s coll=%s message=%s error=%s',
|
||||
taskData._id,
|
||||
taskData.user,
|
||||
collection,
|
||||
'Failed to process message',
|
||||
err.message
|
||||
);
|
||||
}
|
||||
}
|
||||
await cursor.close();
|
||||
} catch (err) {
|
||||
log.error(
|
||||
'Tasks',
|
||||
'task=audit id=%s user=%s coll=%s message=%s error=%s',
|
||||
taskData._id,
|
||||
taskData.user,
|
||||
collection,
|
||||
'Failed to fetch stored messages',
|
||||
err.message
|
||||
);
|
||||
err.code = 'InternalDatabaseError';
|
||||
throw err;
|
||||
}
|
||||
};
|
||||
|
||||
await processMessages('messages');
|
||||
await processMessages('archive');
|
||||
|
||||
log.verbose('Tasks', 'task=audit id=%s user=%s message=%s', taskData._id, taskData.user, `Cleared user specific data`);
|
||||
return true;
|
||||
};
|
||||
|
||||
module.exports = (taskData, options, callback) => {
|
||||
run(taskData, options)
|
||||
.then(response => callback(null, response))
|
||||
.catch(callback);
|
||||
};
|
||||
12
package.json
12
package.json
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "wildduck",
|
||||
"version": "1.22.1",
|
||||
"version": "1.22.2",
|
||||
"description": "IMAP/POP3 server built with Node.js and MongoDB",
|
||||
"main": "server.js",
|
||||
"scripts": {
|
||||
|
|
@ -19,7 +19,7 @@
|
|||
"apidoc": "0.17.7",
|
||||
"browserbox": "0.9.1",
|
||||
"chai": "4.2.0",
|
||||
"eslint": "6.3.0",
|
||||
"eslint": "6.4.0",
|
||||
"eslint-config-nodemailer": "1.2.0",
|
||||
"eslint-config-prettier": "6.3.0",
|
||||
"grunt": "1.0.4",
|
||||
|
|
@ -45,7 +45,7 @@
|
|||
"humanname": "0.2.2",
|
||||
"iconv-lite": "0.5.0",
|
||||
"ioredfour": "1.0.2-ioredis-02",
|
||||
"ioredis": "4.14.0",
|
||||
"ioredis": "4.14.1",
|
||||
"isemail": "3.2.0",
|
||||
"joi": "14.3.1",
|
||||
"js-yaml": "3.13.1",
|
||||
|
|
@ -57,14 +57,14 @@
|
|||
"mobileconfig": "2.3.1",
|
||||
"mongo-cursor-pagination": "7.1.0",
|
||||
"mongodb": "3.3.2",
|
||||
"mongodb-extended-json": "1.10.1",
|
||||
"mongodb-extended-json": "1.10.2",
|
||||
"node-forge": "0.9.0",
|
||||
"nodemailer": "6.3.0",
|
||||
"npmlog": "4.1.2",
|
||||
"openpgp": "4.6.2",
|
||||
"pem": "1.14.2",
|
||||
"pem": "1.14.3",
|
||||
"pwnedpasswords": "1.0.4",
|
||||
"qrcode": "1.4.1",
|
||||
"qrcode": "1.4.2",
|
||||
"restify": "8.4.0",
|
||||
"restify-logger": "2.0.1",
|
||||
"seq-index": "1.1.0",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue