mirror of
https://github.com/nodemailer/wildduck.git
synced 2024-12-27 02:10:52 +08:00
update header search
This commit is contained in:
parent
1a9f182575
commit
e858263381
7 changed files with 63 additions and 9 deletions
|
@ -3,6 +3,7 @@
|
|||
'use strict';
|
||||
|
||||
const recipient = process.argv[2];
|
||||
const total = Number(process.argv[3]) || 1;
|
||||
|
||||
if (!recipient) {
|
||||
console.error('Usage: node example.com username@exmaple.com'); // eslint-disable-line no-console
|
||||
|
@ -22,7 +23,6 @@ const transporter = nodemailer.createTransport({
|
|||
});
|
||||
|
||||
let sent = 0;
|
||||
let total = 1;
|
||||
let startTime = Date.now();
|
||||
|
||||
function send() {
|
||||
|
@ -74,7 +74,7 @@ function send() {
|
|||
if (sent >= total) {
|
||||
console.log('Sent %s messages in %s s', sent, (Date.now() - startTime) / 1000);
|
||||
return transporter.close();
|
||||
}else {
|
||||
} else {
|
||||
send();
|
||||
}
|
||||
});
|
||||
|
|
|
@ -246,6 +246,7 @@ class Indexer {
|
|||
* @return {Object} Parsed mime tree
|
||||
*/
|
||||
storeAttachments(messageId, mimeTree, sizeLimit, callback) {
|
||||
mimeTree.attachments = [];
|
||||
let walk = (node, next) => {
|
||||
|
||||
let continueProcessing = () => {
|
||||
|
@ -307,6 +308,16 @@ class Indexer {
|
|||
}
|
||||
});
|
||||
|
||||
if (!['text/plain', 'text/html'].includes(contentType) || disposition === 'attachment') {
|
||||
mimeTree.attachments.push({
|
||||
id: attachmentId,
|
||||
fileName,
|
||||
contentType,
|
||||
disposition,
|
||||
transferEncoding
|
||||
});
|
||||
}
|
||||
|
||||
store.once('error', err => {
|
||||
if (returned) {
|
||||
return;
|
||||
|
|
16
imap.js
16
imap.js
|
@ -1213,6 +1213,22 @@ server.onSearch = function (path, options, session, callback) {
|
|||
});
|
||||
}
|
||||
break;
|
||||
case 'header':
|
||||
{
|
||||
if (!query.$and) {
|
||||
query.$and = [];
|
||||
}
|
||||
query.$and.push(term.value ? {
|
||||
'headers.key': term.header,
|
||||
'headers.value': {
|
||||
// FIXME: this does not match unicode symbols for whatever reason
|
||||
$regex: Buffer.from(term.value, 'binary').toString().replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&')
|
||||
}
|
||||
} : {
|
||||
'headers.key': term.header
|
||||
});
|
||||
}
|
||||
break;
|
||||
case 'not':
|
||||
[].concat(term.value || []).forEach(term => {
|
||||
switch (term.key) {
|
||||
|
|
|
@ -102,6 +102,12 @@
|
|||
"key": {
|
||||
"uid": 1
|
||||
}
|
||||
}, {
|
||||
"name": "by_headers",
|
||||
"key": {
|
||||
"headers.key": 1,
|
||||
"headers.value": 1
|
||||
}
|
||||
}]
|
||||
}, {
|
||||
"collection": "attachment.files",
|
||||
|
|
|
@ -7,6 +7,7 @@ const RedFour = require('redfour');
|
|||
const Indexer = require('../imap-core/lib/indexer/indexer');
|
||||
const ImapNotifier = require('./imap-notifier');
|
||||
const tools = require('./tools');
|
||||
const libmime = require('libmime');
|
||||
|
||||
class MessageHandler {
|
||||
|
||||
|
@ -63,6 +64,23 @@ class MessageHandler {
|
|||
|
||||
let messageId = envelope[9] || ('<' + uuidV1() + '@wildduck.email>');
|
||||
|
||||
let headers = (mimeTree.header || []).map(line => {
|
||||
line = Buffer.from(line, 'binary').toString();
|
||||
|
||||
let key = line.substr(0, line.indexOf(':')).trim().toLowerCase();
|
||||
let value = line.substr(line.indexOf(':') + 1).trim().toLowerCase().replace(/\s*\r?\n\s*/g, ' ');
|
||||
|
||||
try {
|
||||
value = libmime.decodeWords(value);
|
||||
} catch (E) {
|
||||
// ignore
|
||||
}
|
||||
return {
|
||||
key,
|
||||
value
|
||||
};
|
||||
});
|
||||
|
||||
this.getMailbox(options, (err, mailbox) => {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
|
@ -157,6 +175,7 @@ class MessageHandler {
|
|||
|
||||
meta: options.meta || {},
|
||||
|
||||
headers,
|
||||
mimeTree,
|
||||
envelope,
|
||||
bodystructure,
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
"joi": "^10.3.4",
|
||||
"libbase64": "^0.1.0",
|
||||
"libmime": "^3.1.0",
|
||||
"mailparser": "^2.0.2",
|
||||
"mongodb": "^2.2.25",
|
||||
"nodemailer": "^3.1.8",
|
||||
"npmlog": "^4.0.2",
|
||||
|
|
15
server.js
15
server.js
|
@ -10,12 +10,15 @@ log.level = config.log.level;
|
|||
require('./logger');
|
||||
|
||||
let printLogo = () => {
|
||||
log.info('App', '.##...##..######..##......#####...#####...##..##...####...##..##.');
|
||||
log.info('App', '.##...##....##....##......##..##..##..##..##..##..##..##..##.##..');
|
||||
log.info('App', '.##.#.##....##....##......##..##..##..##..##..##..##......####...');
|
||||
log.info('App', '.#######....##....##......##..##..##..##..##..##..##..##..##.##..');
|
||||
log.info('App', '..##.##...######..######..#####...#####....####....####...##..##.');
|
||||
log.info('App', ' --- v' + packageData.version + ' ---');
|
||||
log.info('App', '');
|
||||
log.info('App', ' ## ## ###### ## ##### ##### ## ## #### ## ##');
|
||||
log.info('App', ' ## ## ## ## ## ## ## ## ## ## ## ## ## ##');
|
||||
log.info('App', ' ## # ## ## ## ## ## ## ## ## ## ## ####');
|
||||
log.info('App', ' ####### ## ## ## ## ## ## ## ## ## ## ## ##');
|
||||
log.info('App', ' ## ## ###### ###### ##### ##### #### #### ## ##');
|
||||
log.info('App', '');
|
||||
log.info('App', ' --- v' + packageData.version + ' ---');
|
||||
log.info('App', '');
|
||||
};
|
||||
|
||||
if (!config.processes || config.processes <= 1) {
|
||||
|
|
Loading…
Reference in a new issue