mirror of
https://github.com/nodemailer/wildduck.git
synced 2024-11-15 13:57:17 +08:00
c9b9442de6
v1.0.11
48 lines
1.3 KiB
JavaScript
48 lines
1.3 KiB
JavaScript
'use strict';
|
|
|
|
let imapHandler = require('./handler/imap-handler');
|
|
let Transform = require('stream').Transform;
|
|
|
|
class IMAPComposer extends Transform {
|
|
|
|
constructor(options) {
|
|
super();
|
|
Transform.call(this, {
|
|
writableObjectMode: true
|
|
});
|
|
this.connection = options.connection;
|
|
}
|
|
|
|
_transform(obj, encoding, done) {
|
|
if (!obj) {
|
|
return done();
|
|
}
|
|
|
|
if (typeof obj.pipe === 'function') {
|
|
// pipe stream to socket and wait until it finishes before continuing
|
|
this.connection._server.logger.debug('[%s] S: %s<pipe message stream to socket>', this.connection.id, obj.description || '');
|
|
obj.pipe(this.connection[!this.connection.compression ? '_socket' : '_deflate'], {
|
|
end: false
|
|
});
|
|
obj.on('error', err => this.emit('error', err));
|
|
obj.on('end', () => {
|
|
this.push('\r\n');
|
|
done();
|
|
});
|
|
return;
|
|
}
|
|
|
|
let compiled = imapHandler.compiler(obj);
|
|
|
|
this.connection._server.logger.debug('[%s] S:', this.connection.id, compiled);
|
|
this.push(new Buffer(compiled + '\r\n', 'binary'));
|
|
done();
|
|
}
|
|
|
|
_flush(done) {
|
|
done();
|
|
}
|
|
|
|
}
|
|
|
|
module.exports.IMAPComposer = IMAPComposer;
|