1
0
mirror of https://github.com/eleith/emailjs.git synced 2024-07-03 11:38:50 +00:00

formatting pass

This commit is contained in:
Zack Schuster 2018-06-04 09:40:23 -07:00
parent 4b66f854e4
commit 6cbc25d0cd
7 changed files with 58 additions and 19 deletions

View File

@ -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();

View File

@ -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) {

View File

@ -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);

View File

@ -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, () =>

View File

@ -18,7 +18,9 @@ describe('authorize plain', function() {
};
server.send(message, function(err) {
if (err) throw err;
if (err) {
throw err;
}
});
};

View File

@ -18,7 +18,9 @@ describe('authorize ssl', function() {
};
server.send(message, function(err) {
if (err) throw err;
if (err) {
throw err;
}
});
};

View File

@ -21,7 +21,9 @@ describe('messages', function() {
};
server.send(message, function(err) {
if (err) throw err;
if (err) {
throw err;
}
});
};