mirror of
https://github.com/nodemailer/wildduck.git
synced 2025-09-07 05:35:12 +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';
|
||||
|
||||
|
@ -59,6 +59,13 @@ module.exports = function(response, isLogging) {
|
|||
if (!value.expectedLength) {
|
||||
return emit();
|
||||
}
|
||||
|
||||
if (value.stream && value.stream.errored) {
|
||||
let err = value.stream.errored;
|
||||
value.stream.errored = false;
|
||||
return output.emit('error', err);
|
||||
}
|
||||
|
||||
waiting = true;
|
||||
let expectedLength = value.maxLength ? Math.min(value.expectedLength, value.startFrom + value.maxLength) : value.expectedLength;
|
||||
let startFrom = value.startFrom;
|
||||
|
@ -70,11 +77,11 @@ module.exports = function(response, isLogging) {
|
|||
});
|
||||
|
||||
// pass errors to output
|
||||
value.stream.on('error', err => {
|
||||
value.stream.once('error', err => {
|
||||
output.emit('error', err);
|
||||
});
|
||||
|
||||
limiter.on('end', () => {
|
||||
limiter.once('end', () => {
|
||||
waiting = false;
|
||||
return emit();
|
||||
});
|
||||
|
|
|
@ -31,8 +31,8 @@ class IMAPComposer extends Transform {
|
|||
obj.pipe(this.connection[!this.connection.compression ? '_socket' : '_deflate'], {
|
||||
end: false
|
||||
});
|
||||
obj.on('error', err => this.emit('error', err));
|
||||
obj.on('end', () => {
|
||||
obj.once('error', err => this.emit('error', err));
|
||||
obj.once('end', () => {
|
||||
this.push('\r\n');
|
||||
done();
|
||||
});
|
||||
|
|
|
@ -251,6 +251,9 @@ class IMAPConnection extends EventEmitter {
|
|||
* @param {Error} err Error object
|
||||
*/
|
||||
_onError(err) {
|
||||
if (err.processed) {
|
||||
return;
|
||||
}
|
||||
if (err.code === 'ECONNRESET' || err.code === 'EPIPE') {
|
||||
this.close(); // mark connection as 'closing'
|
||||
return;
|
||||
|
|
|
@ -184,10 +184,11 @@ class Indexer {
|
|||
if (mimeTree.attachmentMap && mimeTree.attachmentMap[node.attachmentId]) {
|
||||
attachmentId = mimeTree.attachmentMap[node.attachmentId];
|
||||
}
|
||||
|
||||
let attachmentStream = this.attachmentStorage.createReadStream(attachmentId);
|
||||
|
||||
attachmentStream.once('error', err => {
|
||||
res.emit('error', err);
|
||||
res.errored = err;
|
||||
});
|
||||
|
||||
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.on('error', err => {
|
||||
session.socket.write('* BYE INTERNAL ERROR\n');
|
||||
session.socket.destroy(); // ended up in erroneus state, kill the connection to abort
|
||||
return cursor.close(() => done(err));
|
||||
stream.once('error', err => {
|
||||
err.processed = true;
|
||||
server.logger.error(
|
||||
{
|
||||
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
|
||||
|
|
Loading…
Add table
Reference in a new issue