From 6cbc25d0cda15ffd45f84ce543bb0782e6f1cfb4 Mon Sep 17 00:00:00 2001 From: Zack Schuster Date: Mon, 4 Jun 2018 09:40:23 -0700 Subject: [PATCH] formatting pass --- smtp/client.js | 25 +++++++++++++++++-------- smtp/message.js | 14 ++++++++++---- smtp/response.js | 4 +++- smtp/smtp.js | 22 +++++++++++++++++++--- test/authplain.js | 4 +++- test/authssl.js | 4 +++- test/message.js | 4 +++- 7 files changed, 58 insertions(+), 19 deletions(-) diff --git a/smtp/client.js b/smtp/client.js index 2007c6e..1ddbf5b 100644 --- a/smtp/client.js +++ b/smtp/client.js @@ -27,9 +27,11 @@ class Client { this._sendmail(this.queue.shift()); } } - // wait around 1 seconds in case something does come in, otherwise close out SMTP connection if still open - else if (this.smtp.state() == smtp.state.CONNECTED) + // wait around 1 seconds in case something does come in, + // otherwise close out SMTP connection if still open + else if (this.smtp.state() == smtp.state.CONNECTED) { this.timer = setTimeout(() => this.smtp.quit(), 1000); + } } _connect(stack) { @@ -48,8 +50,11 @@ class Client { } }; - if (!this.smtp.authorized()) this.smtp.login(begin); - else this.smtp.ehlo_or_helo_if_needed(begin); + if (!this.smtp.authorized()) { + this.smtp.login(begin); + } else { + this.smtp.ehlo_or_helo_if_needed(begin); + } } else { stack.callback(err, stack.message); @@ -69,8 +74,9 @@ class Client { msg.from && (msg.to || msg.cc || msg.bcc) && (msg.text !== undefined || this._containsInlinedHtml(msg.attachment)) - ) + ) { msg = message.create(msg); + } if (msg instanceof message.Message) { msg.valid((valid, why) => { @@ -82,19 +88,22 @@ class Client { callback: (callback || function() {}).bind(this), }; - if (msg.header.cc) + if (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)); + } if ( msg.header['return-path'] && addressparser(msg.header['return-path']).length - ) + ) { stack.returnPath = addressparser( msg.header['return-path'] )[0].address; + } this.queue.push(stack); this._poll(); diff --git a/smtp/message.js b/smtp/message.js index a8b317e..7da3b98 100644 --- a/smtp/message.js +++ b/smtp/message.js @@ -140,11 +140,13 @@ class Message { this.attachments.forEach(attachment => { if (attachment.path) { // 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`); + } } else if (attachment.stream) { - if (!attachment.stream.readable) + if (!attachment.stream.readable) { failed.push('attachment stream is not readable'); + } } else if (!attachment.data) { 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); loop++; } - if (callback) callback(); + if (callback) { + callback(); + } }; const output_text = message => { @@ -455,7 +459,9 @@ class MessageStream extends Stream { if (bytes + this.bufferIndex < this.buffer.length) { this.buffer.write(data, this.bufferIndex); 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! else if (bytes > this.buffer.length) { diff --git a/smtp/response.js b/smtp/response.js index ae36f91..ffbf52d 100644 --- a/smtp/response.js +++ b/smtp/response.js @@ -76,7 +76,9 @@ class SMTPResponse { stream.removeListener('close', close); stream.removeListener('error', error); - if (err && typeof onerror === 'function') onerror(err); + if (err && typeof onerror === 'function') { + onerror(err); + } }; stream.on('data', watch); diff --git a/smtp/smtp.js b/smtp/smtp.js index 06fa6a6..635aaa5 100644 --- a/smtp/smtp.js +++ b/smtp/smtp.js @@ -120,7 +120,14 @@ class SMTP extends EventEmitter { this.ssl = options.ssl || this.ssl; if (this._state != SMTPState.NOTCONNECTED) { - this.quit(() => this.connect(callback, port, host, options)); + this.quit(() => + this.connect( + callback, + port, + host, + options + ) + ); return; } @@ -178,10 +185,19 @@ class SMTP extends EventEmitter { log(`connecting: ${this.host}:${this.port}`); 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 { 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, () => diff --git a/test/authplain.js b/test/authplain.js index 8a9bcf3..0b5de2d 100644 --- a/test/authplain.js +++ b/test/authplain.js @@ -18,7 +18,9 @@ describe('authorize plain', function() { }; server.send(message, function(err) { - if (err) throw err; + if (err) { + throw err; + } }); }; diff --git a/test/authssl.js b/test/authssl.js index b52afdf..f461aa8 100644 --- a/test/authssl.js +++ b/test/authssl.js @@ -18,7 +18,9 @@ describe('authorize ssl', function() { }; server.send(message, function(err) { - if (err) throw err; + if (err) { + throw err; + } }); }; diff --git a/test/message.js b/test/message.js index 6ee84f9..1c0b275 100644 --- a/test/message.js +++ b/test/message.js @@ -21,7 +21,9 @@ describe('messages', function() { }; server.send(message, function(err) { - if (err) throw err; + if (err) { + throw err; + } }); };