mirror of
https://github.com/nodemailer/wildduck.git
synced 2025-03-01 10:24:40 +08:00
fix message parsing for too large messages
This commit is contained in:
parent
69c904ca50
commit
34cf55d500
3 changed files with 73 additions and 2 deletions
59
examples/append.js
Normal file
59
examples/append.js
Normal file
|
@ -0,0 +1,59 @@
|
|||
/* eslint no-console:0 */
|
||||
|
||||
'use strict';
|
||||
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
|
||||
const rawpath = process.argv[2];
|
||||
|
||||
const config = require('wild-config');
|
||||
const BrowserBox = require('browserbox');
|
||||
|
||||
const raw = require('fs').readFileSync(rawpath);
|
||||
console.log('Processing %s of %s bytes', rawpath, raw.length);
|
||||
|
||||
const client = new BrowserBox('localhost', config.imap.port, {
|
||||
useSecureTransport: config.imap.secure,
|
||||
auth: {
|
||||
user: 'myuser',
|
||||
pass: 'verysecret'
|
||||
},
|
||||
id: {
|
||||
name: 'My Client',
|
||||
version: '0.1'
|
||||
},
|
||||
tls: {
|
||||
rejectUnauthorized: false
|
||||
}
|
||||
});
|
||||
|
||||
client.onerror = function(err) {
|
||||
console.log(err);
|
||||
process.exit(1);
|
||||
};
|
||||
|
||||
client.onauth = function() {
|
||||
client.upload('INBOX', raw, false, err => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return process.exit(1);
|
||||
}
|
||||
|
||||
client.selectMailbox('INBOX', (err, mailbox) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return process.exit(1);
|
||||
}
|
||||
console.log(mailbox);
|
||||
|
||||
client.listMessages(mailbox.exists, ['BODY.PEEK[]', 'BODYSTRUCTURE'], (err, data) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return process.exit(1);
|
||||
}
|
||||
console.log('<<<%s>>>', data[0]['body[]']);
|
||||
return process.exit(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
client.connect();
|
|
@ -140,6 +140,14 @@ module.exports = {
|
|||
logdata._response = err.response;
|
||||
this._server.loggelf(logdata);
|
||||
|
||||
if (err.code === 10334) {
|
||||
// 10334 is Mongodb BSONObjectTooLarge
|
||||
return callback(null, {
|
||||
response: 'NO',
|
||||
message: 'Message text too large'
|
||||
});
|
||||
}
|
||||
|
||||
// do not return actual error to user
|
||||
return callback(null, {
|
||||
response: 'NO',
|
||||
|
|
|
@ -13,6 +13,8 @@ const he = require('he');
|
|||
const htmlToText = require('html-to-text');
|
||||
const crypto = require('crypto');
|
||||
|
||||
const MAX_HTML_PARSE_LENGTH = 2 * 1024 * 1024; // do not parse HTML messages larger than 2MB to plaintext
|
||||
|
||||
class Indexer {
|
||||
constructor(options) {
|
||||
this.options = options || {};
|
||||
|
@ -347,8 +349,10 @@ class Indexer {
|
|||
htmlContent.push(content.trim());
|
||||
if (!alternative) {
|
||||
try {
|
||||
if (content && content.length < MAX_HTML_PARSE_LENGTH) {
|
||||
let text = htmlToText.fromString(content);
|
||||
textContent.push(text.trim());
|
||||
}
|
||||
} catch (E) {
|
||||
// ignore
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue