Skip to content

Commit 234eeef

Browse files
authored
Do some formatting fixes.
1 parent a6b9484 commit 234eeef

File tree

1 file changed

+27
-26
lines changed

1 file changed

+27
-26
lines changed

sendmail.js

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ module.exports = function (options) {
2222
const dkimKeySelector = (options.dkim || {}).keySelector || 'dkim';
2323
const devPort = options.devPort || -1;
2424
const devHost = options.devHost || 'localhost';
25-
const smtpPort = options.smtpPort || 25
26-
const smtpHost = options.smtpHost || -1
25+
const smtpPort = options.smtpPort || 25;
26+
const smtpHost = options.smtpHost || -1;
2727
const rejectUnauthorized = options.rejectUnauthorized;
2828
const autoEHLO = options.autoEHLO;
2929

@@ -68,7 +68,7 @@ module.exports = function (options) {
6868
host = getHost(recipients[i]);
6969
(groups[host] || (groups[host] = [])).push(recipients[i])
7070
}
71-
return groups
71+
return groups;
7272
}
7373

7474
/**
@@ -78,16 +78,17 @@ module.exports = function (options) {
7878
if (devPort === -1) { // not in development mode -> search the MX
7979
resolveMx(domain, function (err, data) {
8080
if (err) {
81-
return callback(err)
81+
return callback(err);
8282
}
8383

8484
data.sort(function (a, b) { return a.priority > b.priority });
8585
logger.debug('mx resolved: ', data);
8686

8787
if (!data || data.length === 0) {
88-
return callback(new Error('can not resolve Mx of <' + domain + '>'))
88+
return callback(new Error('can not resolve Mx of <' + domain + '>'));
8989
}
90-
if(smtpHost !== -1)data.push({exchange:smtpHost})
90+
if(smtpHost !== -1) data.push({exchange:smtpHost});
91+
9192
function tryConnect (i) {
9293
if (i >= data.length) return callback(new Error('can not connect to any SMTP server'));
9394

@@ -101,7 +102,7 @@ module.exports = function (options) {
101102
sock.on('connect', function () {
102103
logger.debug('MX connection created: ', data[i].exchange);
103104
sock.removeAllListeners('error');
104-
callback(null, sock)
105+
callback(null, sock);
105106
})
106107
}
107108

@@ -117,7 +118,7 @@ module.exports = function (options) {
117118
sock.on('connect', function () {
118119
logger.debug('MX (development) connection created: '+ devHost +':' + devPort);
119120
sock.removeAllListeners('error');
120-
callback(null, sock)
121+
callback(null, sock);
121122
})
122123
}
123124
}
@@ -127,12 +128,12 @@ module.exports = function (options) {
127128
connectMx(domain, function (err, sock) {
128129
if (err) {
129130
logger.error('error on connectMx', err.stack);
130-
return callback(err)
131+
return callback(err);
131132
}
132133

133134
function w (s) {
134135
logger.debug('send ' + domain + '>' + s);
135-
sock.write(s + CRLF)
136+
sock.write(s + CRLF);
136137
}
137138

138139
sock.setEncoding('utf8');
@@ -142,14 +143,14 @@ module.exports = function (options) {
142143
parts = data.split(CRLF);
143144
const parts_length = parts.length - 1;
144145
for (let i = 0, len = parts_length; i < len; i++) {
145-
onLine(parts[i])
146+
onLine(parts[i]);
146147
}
147-
data = parts[parts.length - 1]
148+
data = parts[parts.length - 1];
148149
});
149150

150151
sock.on('error', function (err) {
151-
logger.error('fail to connect ' + domain)
152-
callback(err)
152+
logger.error('fail to connect ' + domain);
153+
callback(err);
153154
});
154155

155156
let data = '';
@@ -172,7 +173,7 @@ module.exports = function (options) {
172173
queue.push('MAIL FROM:<' + from + '>');
173174
const recipients_length = recipients.length;
174175
for (let i = 0; i < recipients_length; i++) {
175-
queue.push('RCPT TO:<' + recipients[i] + '>')
176+
queue.push('RCPT TO:<' + recipients[i] + '>');
176177
}
177178
queue.push('DATA');
178179
queue.push('QUIT');
@@ -227,10 +228,10 @@ module.exports = function (options) {
227228
{
228229
if (/\besmtp\b/i.test(msg) || autoEHLO) {
229230
// TODO: determin AUTH type; auth login, auth crm-md5, auth plain
230-
cmd = 'EHLO'
231+
cmd = 'EHLO';
231232
} else {
232233
upgraded = true;
233-
cmd = 'HELO'
234+
cmd = 'HELO';
234235
}
235236
w(cmd + ' ' + srcHost);
236237
break;
@@ -256,7 +257,7 @@ module.exports = function (options) {
256257
case 251: // foward
257258
if (step === queue.length - 1) {
258259
logger.info('OK:', code, msg);
259-
callback(null, msg)
260+
callback(null, msg);
260261
}
261262
w(queue[step]);
262263
step++;
@@ -315,7 +316,7 @@ module.exports = function (options) {
315316
for (let i = 0; i < addresses_length; i++) {
316317
results.push(getAddress(addresses[i]));
317318
}
318-
return results
319+
return results;
319320
}
320321

321322
/**
@@ -352,15 +353,15 @@ module.exports = function (options) {
352353
let groups;
353354
let srcHost;
354355
if (mail.to) {
355-
recipients = recipients.concat(getAddresses(mail.to))
356+
recipients = recipients.concat(getAddresses(mail.to));
356357
}
357358

358359
if (mail.cc) {
359-
recipients = recipients.concat(getAddresses(mail.cc))
360+
recipients = recipients.concat(getAddresses(mail.cc));
360361
}
361362

362363
if (mail.bcc) {
363-
recipients = recipients.concat(getAddresses(mail.bcc))
364+
recipients = recipients.concat(getAddresses(mail.bcc));
364365
}
365366

366367
groups = groupRecipients(recipients);
@@ -370,7 +371,7 @@ module.exports = function (options) {
370371

371372
mailMe.build(function (err, message) {
372373
if (err) {
373-
logger.error('Error on creating message : ', err)
374+
logger.error('Error on creating message : ', err);
374375
callback(err, null);
375376
return
376377
}
@@ -380,12 +381,12 @@ module.exports = function (options) {
380381
keySelector: dkimKeySelector,
381382
domainName: srcHost
382383
});
383-
message = signature + '\r\n' + message
384+
message = signature + '\r\n' + message;
384385
}
385386
for (let domain in groups) {
386-
sendToSMTP(domain, srcHost, from, groups[domain], message, callback)
387+
sendToSMTP(domain, srcHost, from, groups[domain], message, callback);
387388
}
388389
});
389390
}
390-
return sendmail
391+
return sendmail;
391392
};

0 commit comments

Comments
 (0)