diff --git a/smtp/client.js b/smtp/client.js index d5e7c73..ab706c4 100644 --- a/smtp/client.js +++ b/smtp/client.js @@ -55,6 +55,64 @@ class Client { this.ready = false; } + /** + * @param {Message|MessageStack} msg msg + * @param {function(Error, MessageStack): void} callback callback + * @returns {void} + */ + send(msg, callback) { + /** + * @type {Message} + */ + const message = + msg instanceof Message + ? msg + : this._canMakeMessage(msg) + ? create(msg) + : null; + + if (message == null) { + callback( + new Error('message is not a valid Message instance'), + /** @type {MessageStack} */ (msg) + ); + return; + } + + message.valid((valid, why) => { + if (valid) { + const stack = { + message, + to: addressparser(message.header.to), + from: addressparser(message.header.from)[0].address, + callback: (callback || function() {}).bind(this), + }; + + if (message.header.cc) { + stack.to = stack.to.concat(addressparser(message.header.cc)); + } + + if (message.header.bcc) { + stack.to = stack.to.concat(addressparser(message.header.bcc)); + } + + if ( + message.header['return-path'] && + addressparser(message.header['return-path']).length + ) { + stack.returnPath = addressparser( + message.header['return-path'] + )[0].address; + } + + this.queue.push(stack); + this._poll(); + } else { + callback(new Error(why), /** @type {MessageStack} */ (msg)); + } + }); + } + /** * @private * @returns {void} @@ -123,64 +181,6 @@ class Client { this.smtp.connect(connect); } - /** - * @param {Message|MessageStack} msg msg - * @param {function(Error, MessageStack): void} callback callback - * @returns {void} - */ - send(msg, callback) { - /** - * @type {Message} - */ - const message = - msg instanceof Message - ? msg - : this._canMakeMessage(msg) - ? create(msg) - : null; - - if (message == null) { - callback( - new Error('message is not a valid Message instance'), - /**@type {MessageStack}*/ (msg) - ); - return; - } - - message.valid((valid, why) => { - if (valid) { - const stack = { - message, - to: addressparser(message.header.to), - from: addressparser(message.header.from)[0].address, - callback: (callback || function() {}).bind(this), - }; - - if (message.header.cc) { - stack.to = stack.to.concat(addressparser(message.header.cc)); - } - - if (message.header.bcc) { - stack.to = stack.to.concat(addressparser(message.header.bcc)); - } - - if ( - message.header['return-path'] && - addressparser(message.header['return-path']).length - ) { - stack.returnPath = addressparser( - message.header['return-path'] - )[0].address; - } - - this.queue.push(stack); - this._poll(); - } else { - callback(new Error(why), /**@type {MessageStack}*/ (msg)); - } - }); - } - /** * @private * @param {MessageStack} msg message stack diff --git a/smtp/smtp.js b/smtp/smtp.js index e9fd951..f3240c3 100644 --- a/smtp/smtp.js +++ b/smtp/smtp.js @@ -684,7 +684,7 @@ class SMTP extends EventEmitter { ); /** - * see: https://developers.google.com/gmail/xoauth2_protocol + * @see https://developers.google.com/gmail/xoauth2_protocol * @returns {string} base64 xoauth2 auth token */ const encode_xoauth2 = () =>