mirror of
https://github.com/nodemailer/wildduck.git
synced 2025-09-14 00:54:36 +08:00
do not explode on missing attachment
This commit is contained in:
parent
1cfa273b7f
commit
b56d527276
5 changed files with 33 additions and 10 deletions
|
@ -1,4 +1,4 @@
|
||||||
/* eslint no-console: 0, new-cap: 0 */
|
/* eslint new-cap: 0 */
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
@ -59,6 +59,13 @@ module.exports = function(response, isLogging) {
|
||||||
if (!value.expectedLength) {
|
if (!value.expectedLength) {
|
||||||
return emit();
|
return emit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (value.stream && value.stream.errored) {
|
||||||
|
let err = value.stream.errored;
|
||||||
|
value.stream.errored = false;
|
||||||
|
return output.emit('error', err);
|
||||||
|
}
|
||||||
|
|
||||||
waiting = true;
|
waiting = true;
|
||||||
let expectedLength = value.maxLength ? Math.min(value.expectedLength, value.startFrom + value.maxLength) : value.expectedLength;
|
let expectedLength = value.maxLength ? Math.min(value.expectedLength, value.startFrom + value.maxLength) : value.expectedLength;
|
||||||
let startFrom = value.startFrom;
|
let startFrom = value.startFrom;
|
||||||
|
@ -70,11 +77,11 @@ module.exports = function(response, isLogging) {
|
||||||
});
|
});
|
||||||
|
|
||||||
// pass errors to output
|
// pass errors to output
|
||||||
value.stream.on('error', err => {
|
value.stream.once('error', err => {
|
||||||
output.emit('error', err);
|
output.emit('error', err);
|
||||||
});
|
});
|
||||||
|
|
||||||
limiter.on('end', () => {
|
limiter.once('end', () => {
|
||||||
waiting = false;
|
waiting = false;
|
||||||
return emit();
|
return emit();
|
||||||
});
|
});
|
||||||
|
|
|
@ -31,8 +31,8 @@ class IMAPComposer extends Transform {
|
||||||
obj.pipe(this.connection[!this.connection.compression ? '_socket' : '_deflate'], {
|
obj.pipe(this.connection[!this.connection.compression ? '_socket' : '_deflate'], {
|
||||||
end: false
|
end: false
|
||||||
});
|
});
|
||||||
obj.on('error', err => this.emit('error', err));
|
obj.once('error', err => this.emit('error', err));
|
||||||
obj.on('end', () => {
|
obj.once('end', () => {
|
||||||
this.push('\r\n');
|
this.push('\r\n');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
|
@ -251,6 +251,9 @@ class IMAPConnection extends EventEmitter {
|
||||||
* @param {Error} err Error object
|
* @param {Error} err Error object
|
||||||
*/
|
*/
|
||||||
_onError(err) {
|
_onError(err) {
|
||||||
|
if (err.processed) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (err.code === 'ECONNRESET' || err.code === 'EPIPE') {
|
if (err.code === 'ECONNRESET' || err.code === 'EPIPE') {
|
||||||
this.close(); // mark connection as 'closing'
|
this.close(); // mark connection as 'closing'
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -184,10 +184,11 @@ class Indexer {
|
||||||
if (mimeTree.attachmentMap && mimeTree.attachmentMap[node.attachmentId]) {
|
if (mimeTree.attachmentMap && mimeTree.attachmentMap[node.attachmentId]) {
|
||||||
attachmentId = mimeTree.attachmentMap[node.attachmentId];
|
attachmentId = mimeTree.attachmentMap[node.attachmentId];
|
||||||
}
|
}
|
||||||
|
|
||||||
let attachmentStream = this.attachmentStorage.createReadStream(attachmentId);
|
let attachmentStream = this.attachmentStorage.createReadStream(attachmentId);
|
||||||
|
|
||||||
attachmentStream.once('error', err => {
|
attachmentStream.once('error', err => {
|
||||||
res.emit('error', err);
|
res.errored = err;
|
||||||
});
|
});
|
||||||
|
|
||||||
attachmentStream.once('end', () => finalize());
|
attachmentStream.once('end', () => finalize());
|
||||||
|
|
|
@ -127,10 +127,22 @@ module.exports = (server, messageHandler) => (path, options, session, callback)
|
||||||
|
|
||||||
stream.description = util.format('* FETCH #%s uid=%s size=%sB ', ++rowCount, message.uid, message.size);
|
stream.description = util.format('* FETCH #%s uid=%s size=%sB ', ++rowCount, message.uid, message.size);
|
||||||
|
|
||||||
stream.on('error', err => {
|
stream.once('error', err => {
|
||||||
session.socket.write('* BYE INTERNAL ERROR\n');
|
err.processed = true;
|
||||||
session.socket.destroy(); // ended up in erroneus state, kill the connection to abort
|
server.logger.error(
|
||||||
return cursor.close(() => done(err));
|
{
|
||||||
|
err,
|
||||||
|
tnx: 'fetch',
|
||||||
|
cid: session.id
|
||||||
|
},
|
||||||
|
'[%s] FETCHFAIL %s. %s',
|
||||||
|
session.id,
|
||||||
|
message._id,
|
||||||
|
err.message
|
||||||
|
);
|
||||||
|
|
||||||
|
session.socket.end('\n* BYE Internal Server Error\n');
|
||||||
|
return cursor.close(() => done());
|
||||||
});
|
});
|
||||||
|
|
||||||
// send formatted response to socket
|
// send formatted response to socket
|
||||||
|
|
Loading…
Add table
Reference in a new issue