mirror of
https://github.com/nodemailer/wildduck.git
synced 2025-01-01 05:06:44 +08:00
40 lines
988 B
JavaScript
40 lines
988 B
JavaScript
'use strict';
|
|
|
|
const config = require('wild-config');
|
|
const maildrop = require('./maildrop');
|
|
|
|
module.exports = (options, callback) => {
|
|
if (!config.sender.enabled) {
|
|
return callback(null, false);
|
|
}
|
|
|
|
let message = maildrop(
|
|
{
|
|
from: options.sender,
|
|
to: options.recipient,
|
|
|
|
forward: options.forward,
|
|
http: !!options.targetUrl,
|
|
targeUrl: options.targetUrl,
|
|
|
|
interface: 'forwarder'
|
|
},
|
|
callback
|
|
);
|
|
|
|
setImmediate(() => {
|
|
let pos = 0;
|
|
let writeNextChunk = () => {
|
|
if (pos >= options.chunks.length) {
|
|
return message.end();
|
|
}
|
|
let chunk = options.chunks[pos++];
|
|
if (!message.write(chunk)) {
|
|
return message.once('drain', writeNextChunk);
|
|
} else {
|
|
setImmediate(writeNextChunk);
|
|
}
|
|
};
|
|
setImmediate(writeNextChunk);
|
|
});
|
|
};
|