mirror of
https://github.com/eleith/emailjs.git
synced 2024-07-05 20:10:37 +00:00
formatting pass
This commit is contained in:
parent
4b66f854e4
commit
6cbc25d0cd
@ -27,9 +27,11 @@ class Client {
|
|||||||
this._sendmail(this.queue.shift());
|
this._sendmail(this.queue.shift());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// wait around 1 seconds in case something does come in, otherwise close out SMTP connection if still open
|
// wait around 1 seconds in case something does come in,
|
||||||
else if (this.smtp.state() == smtp.state.CONNECTED)
|
// otherwise close out SMTP connection if still open
|
||||||
|
else if (this.smtp.state() == smtp.state.CONNECTED) {
|
||||||
this.timer = setTimeout(() => this.smtp.quit(), 1000);
|
this.timer = setTimeout(() => this.smtp.quit(), 1000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_connect(stack) {
|
_connect(stack) {
|
||||||
@ -48,8 +50,11 @@ class Client {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!this.smtp.authorized()) this.smtp.login(begin);
|
if (!this.smtp.authorized()) {
|
||||||
else this.smtp.ehlo_or_helo_if_needed(begin);
|
this.smtp.login(begin);
|
||||||
|
} else {
|
||||||
|
this.smtp.ehlo_or_helo_if_needed(begin);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
stack.callback(err, stack.message);
|
stack.callback(err, stack.message);
|
||||||
|
|
||||||
@ -69,8 +74,9 @@ class Client {
|
|||||||
msg.from &&
|
msg.from &&
|
||||||
(msg.to || msg.cc || msg.bcc) &&
|
(msg.to || msg.cc || msg.bcc) &&
|
||||||
(msg.text !== undefined || this._containsInlinedHtml(msg.attachment))
|
(msg.text !== undefined || this._containsInlinedHtml(msg.attachment))
|
||||||
)
|
) {
|
||||||
msg = message.create(msg);
|
msg = message.create(msg);
|
||||||
|
}
|
||||||
|
|
||||||
if (msg instanceof message.Message) {
|
if (msg instanceof message.Message) {
|
||||||
msg.valid((valid, why) => {
|
msg.valid((valid, why) => {
|
||||||
@ -82,19 +88,22 @@ class Client {
|
|||||||
callback: (callback || function() {}).bind(this),
|
callback: (callback || function() {}).bind(this),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (msg.header.cc)
|
if (msg.header.cc) {
|
||||||
stack.to = stack.to.concat(addressparser(msg.header.cc));
|
stack.to = stack.to.concat(addressparser(msg.header.cc));
|
||||||
|
}
|
||||||
|
|
||||||
if (msg.header.bcc)
|
if (msg.header.bcc) {
|
||||||
stack.to = stack.to.concat(addressparser(msg.header.bcc));
|
stack.to = stack.to.concat(addressparser(msg.header.bcc));
|
||||||
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
msg.header['return-path'] &&
|
msg.header['return-path'] &&
|
||||||
addressparser(msg.header['return-path']).length
|
addressparser(msg.header['return-path']).length
|
||||||
)
|
) {
|
||||||
stack.returnPath = addressparser(
|
stack.returnPath = addressparser(
|
||||||
msg.header['return-path']
|
msg.header['return-path']
|
||||||
)[0].address;
|
)[0].address;
|
||||||
|
}
|
||||||
|
|
||||||
this.queue.push(stack);
|
this.queue.push(stack);
|
||||||
this._poll();
|
this._poll();
|
||||||
|
@ -140,11 +140,13 @@ class Message {
|
|||||||
this.attachments.forEach(attachment => {
|
this.attachments.forEach(attachment => {
|
||||||
if (attachment.path) {
|
if (attachment.path) {
|
||||||
// migrating path->fs for existsSync)
|
// migrating path->fs for existsSync)
|
||||||
if (!(fs.existsSync || path.existsSync)(attachment.path))
|
if (!(fs.existsSync || path.existsSync)(attachment.path)) {
|
||||||
failed.push(`${attachment.path} does not exist`);
|
failed.push(`${attachment.path} does not exist`);
|
||||||
|
}
|
||||||
} else if (attachment.stream) {
|
} else if (attachment.stream) {
|
||||||
if (!attachment.stream.readable)
|
if (!attachment.stream.readable) {
|
||||||
failed.push('attachment stream is not readable');
|
failed.push('attachment stream is not readable');
|
||||||
|
}
|
||||||
} else if (!attachment.data) {
|
} else if (!attachment.data) {
|
||||||
failed.push('attachment has no data associated with it');
|
failed.push('attachment has no data associated with it');
|
||||||
}
|
}
|
||||||
@ -363,7 +365,9 @@ class MessageStream extends Stream {
|
|||||||
output(data.substring(MIMECHUNK * loop, MIMECHUNK * (loop + 1)) + CRLF);
|
output(data.substring(MIMECHUNK * loop, MIMECHUNK * (loop + 1)) + CRLF);
|
||||||
loop++;
|
loop++;
|
||||||
}
|
}
|
||||||
if (callback) callback();
|
if (callback) {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const output_text = message => {
|
const output_text = message => {
|
||||||
@ -455,7 +459,9 @@ class MessageStream extends Stream {
|
|||||||
if (bytes + this.bufferIndex < this.buffer.length) {
|
if (bytes + this.bufferIndex < this.buffer.length) {
|
||||||
this.buffer.write(data, this.bufferIndex);
|
this.buffer.write(data, this.bufferIndex);
|
||||||
this.bufferIndex += bytes;
|
this.bufferIndex += bytes;
|
||||||
if (callback) callback.apply(null, args);
|
if (callback) {
|
||||||
|
callback.apply(null, args);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// we can't buffer the data, so ship it out!
|
// we can't buffer the data, so ship it out!
|
||||||
else if (bytes > this.buffer.length) {
|
else if (bytes > this.buffer.length) {
|
||||||
|
@ -76,7 +76,9 @@ class SMTPResponse {
|
|||||||
stream.removeListener('close', close);
|
stream.removeListener('close', close);
|
||||||
stream.removeListener('error', error);
|
stream.removeListener('error', error);
|
||||||
|
|
||||||
if (err && typeof onerror === 'function') onerror(err);
|
if (err && typeof onerror === 'function') {
|
||||||
|
onerror(err);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
stream.on('data', watch);
|
stream.on('data', watch);
|
||||||
|
22
smtp/smtp.js
22
smtp/smtp.js
@ -120,7 +120,14 @@ class SMTP extends EventEmitter {
|
|||||||
this.ssl = options.ssl || this.ssl;
|
this.ssl = options.ssl || this.ssl;
|
||||||
|
|
||||||
if (this._state != SMTPState.NOTCONNECTED) {
|
if (this._state != SMTPState.NOTCONNECTED) {
|
||||||
this.quit(() => this.connect(callback, port, host, options));
|
this.quit(() =>
|
||||||
|
this.connect(
|
||||||
|
callback,
|
||||||
|
port,
|
||||||
|
host,
|
||||||
|
options
|
||||||
|
)
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,10 +185,19 @@ class SMTP extends EventEmitter {
|
|||||||
log(`connecting: ${this.host}:${this.port}`);
|
log(`connecting: ${this.host}:${this.port}`);
|
||||||
|
|
||||||
if (this.ssl) {
|
if (this.ssl) {
|
||||||
this.sock = tls.connect(this.port, this.host, this.ssl, connected);
|
this.sock = tls.connect(
|
||||||
|
this.port,
|
||||||
|
this.host,
|
||||||
|
this.ssl,
|
||||||
|
connected
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
this.sock = new net.Socket();
|
this.sock = new net.Socket();
|
||||||
this.sock.connect(this.port, this.host, connected);
|
this.sock.connect(
|
||||||
|
this.port,
|
||||||
|
this.host,
|
||||||
|
connected
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.monitor = SMTPResponse.monitor(this.sock, this.timeout, () =>
|
this.monitor = SMTPResponse.monitor(this.sock, this.timeout, () =>
|
||||||
|
@ -18,7 +18,9 @@ describe('authorize plain', function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
server.send(message, function(err) {
|
server.send(message, function(err) {
|
||||||
if (err) throw err;
|
if (err) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -18,7 +18,9 @@ describe('authorize ssl', function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
server.send(message, function(err) {
|
server.send(message, function(err) {
|
||||||
if (err) throw err;
|
if (err) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -21,7 +21,9 @@ describe('messages', function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
server.send(message, function(err) {
|
server.send(message, function(err) {
|
||||||
if (err) throw err;
|
if (err) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user