Skip to content

Commit c8d708e

Browse files
committed
Remove unused properties
1 parent a89ef99 commit c8d708e

File tree

2 files changed

+34
-48
lines changed

2 files changed

+34
-48
lines changed

src/client-unit.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,7 @@ describe('smtpclient unit tests', function () {
154154
smtp._parse('250 1.1.1 Ok\r\n')
155155
expect(smtp._onCommand.withArgs({
156156
statusCode: 250,
157-
enhancedStatus: '1.1.1',
158157
data: 'Ok',
159-
line: '250 1.1.1 Ok',
160158
success: true
161159
}).callCount).to.equal(1)
162160
})
@@ -170,9 +168,7 @@ describe('smtpclient unit tests', function () {
170168

171169
expect(smtp._onCommand.withArgs({
172170
statusCode: 250,
173-
enhancedStatus: null,
174171
data: 'Ok 1\nOk 2\nOk 3',
175-
line: '250-Ok 1\n250-Ok 2\n250 Ok 3',
176172
success: true
177173
}).callCount).to.equal(1)
178174
})
@@ -369,7 +365,7 @@ describe('smtpclient unit tests', function () {
369365
smtp.options.name = 'abc'
370366
smtp._actionLHLO({
371367
success: true,
372-
line: '250-AUTH PLAIN LOGIN'
368+
data: 'AUTH PLAIN LOGIN'
373369
})
374370

375371
expect(_actionEHLOStub.callCount).to.equal(1)
@@ -394,7 +390,7 @@ describe('smtpclient unit tests', function () {
394390

395391
smtp._actionEHLO({
396392
success: true,
397-
line: '250-AUTH PLAIN LOGIN'
393+
data: 'AUTH PLAIN LOGIN'
398394
})
399395

400396
expect(_authenticateUserStub.callCount).to.equal(1)
@@ -407,7 +403,7 @@ describe('smtpclient unit tests', function () {
407403
smtp._secureMode = false
408404
smtp._actionEHLO({
409405
success: true,
410-
line: '250-STARTTLS'
406+
data: 'STARTTLS'
411407
})
412408

413409
expect(_sendCommandStub.withArgs('STARTTLS').callCount).to.equal(1)
@@ -435,7 +431,7 @@ describe('smtpclient unit tests', function () {
435431
smtp.options.name = 'abc'
436432
smtp._actionSTARTTLS({
437433
success: true,
438-
line: '220 Ready to start TLS'
434+
data: 'Ready to start TLS'
439435
})
440436

441437
expect(smtp.socket.upgradeToSecure.callCount).to.equal(1)

src/client.js

Lines changed: 30 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class SmtpClient {
7575
this._socketTimeoutStart = false // Start time of sending the first packet in data mode
7676
this._socketTimeoutPeriod = false // Timeout for sending in data mode, gets extended with every send()
7777

78-
this._parseBlock = { data: [], lines: [], statusCode: null } // If the response is a list, contains previous not yet emitted lines
78+
this._parseBlock = { data: [], statusCode: null }
7979
this._parseRemainder = '' // If the complete line is not received yet, contains the beginning of it
8080

8181
const dummyLogger = ['error', 'warning', 'info', 'debug'].reduce((o, l) => { o[l] = () => {}; return o }, {})
@@ -227,57 +227,47 @@ class SmtpClient {
227227
var lines = (this._parseRemainder + (chunk || '')).split(/\r?\n/)
228228
this._parseRemainder = lines.pop() // not sure if the line has completely arrived yet
229229

230-
for (var i = 0, len = lines.length; i < len; i++) {
230+
for (let i = 0, len = lines.length; i < len; i++) {
231231
if (!lines[i].trim()) {
232232
// nothing to check, empty line
233233
continue
234234
}
235235

236-
this._parseBlock.lines.push(lines[i])
237-
238236
// possible input strings for the regex:
239-
// 250-MESSAGE
240-
// 250 MESSAGE
237+
// 250-MULTILINE REPLY
238+
// 250 LAST LINE OF REPLY
241239
// 250 1.2.3 MESSAGE
242240

243241
const match = lines[i].match(/^(\d{3})([- ])(?:(\d+\.\d+\.\d+)(?: ))?(.*)/)
242+
244243
if (match) {
245244
this._parseBlock.data.push(match[4])
246245

247246
if (match[2] === '-') {
248-
if (this._parseBlock.statusCode && this._parseBlock.statusCode !== Number(match[1])) {
249-
// dead code
250-
} else if (!this._parseBlock.statusCode) {
251-
this._parseBlock.statusCode = Number(match[1])
252-
}
247+
// this is a multiline reply
248+
this._parseBlock.statusCode = this._parseBlock.statusCode || Number(match[1])
253249
} else {
250+
const statusCode = Number(match[1]) || 0
254251
const response = {
255-
statusCode: Number(match[1]) || 0,
256-
enhancedStatus: match[3] || null,
252+
statusCode,
257253
data: this._parseBlock.data.join('\n'),
258-
line: this._parseBlock.lines.join('\n')
254+
success: statusCode >= 200 && statusCode < 300
259255
}
260-
response.success = response.statusCode >= 200 && response.statusCode < 300
261256

262257
this._onCommand(response)
263258
this._parseBlock = {
264259
data: [],
265-
lines: [],
266260
statusCode: null
267261
}
268-
this._parseBlock.statusCode = null
269262
}
270263
} else {
271264
this._onCommand({
272265
success: false,
273266
statusCode: this._parseBlock.statusCode || null,
274-
enhancedStatus: null,
275-
data: [lines[i]].join('\n'),
276-
line: this._parseBlock.lines.join('\n')
267+
data: [lines[i]].join('\n')
277268
})
278269
this._parseBlock = {
279270
data: [],
280-
lines: [],
281271
statusCode: null
282272
}
283273
}
@@ -527,7 +517,7 @@ class SmtpClient {
527517
/**
528518
* Initial response from the server, must have a status 220
529519
*
530-
* @param {Object} command Parsed command from the server {statusCode, data, line}
520+
* @param {Object} command Parsed command from the server {statusCode, data}
531521
*/
532522
_actionGreeting (command) {
533523
if (command.statusCode !== 220) {
@@ -551,7 +541,7 @@ class SmtpClient {
551541
/**
552542
* Response to LHLO
553543
*
554-
* @param {Object} command Parsed command from the server {statusCode, data, line}
544+
* @param {Object} command Parsed command from the server {statusCode, data}
555545
*/
556546
_actionLHLO (command) {
557547
if (!command.success) {
@@ -567,7 +557,7 @@ class SmtpClient {
567557
/**
568558
* Response to EHLO. If the response is an error, try HELO instead
569559
*
570-
* @param {Object} command Parsed command from the server {statusCode, data, line}
560+
* @param {Object} command Parsed command from the server {statusCode, data}
571561
*/
572562
_actionEHLO (command) {
573563
var match
@@ -588,32 +578,32 @@ class SmtpClient {
588578
}
589579

590580
// Detect if the server supports PLAIN auth
591-
if (command.line.match(/AUTH(?:\s+[^\n]*\s+|\s+)PLAIN/i)) {
581+
if (command.data.match(/AUTH(?:\s+[^\n]*\s+|\s+)PLAIN/i)) {
592582
this.logger.debug(DEBUG_TAG, 'Server supports AUTH PLAIN')
593583
this._supportedAuth.push('PLAIN')
594584
}
595585

596586
// Detect if the server supports LOGIN auth
597-
if (command.line.match(/AUTH(?:\s+[^\n]*\s+|\s+)LOGIN/i)) {
587+
if (command.data.match(/AUTH(?:\s+[^\n]*\s+|\s+)LOGIN/i)) {
598588
this.logger.debug(DEBUG_TAG, 'Server supports AUTH LOGIN')
599589
this._supportedAuth.push('LOGIN')
600590
}
601591

602592
// Detect if the server supports XOAUTH2 auth
603-
if (command.line.match(/AUTH(?:\s+[^\n]*\s+|\s+)XOAUTH2/i)) {
593+
if (command.data.match(/AUTH(?:\s+[^\n]*\s+|\s+)XOAUTH2/i)) {
604594
this.logger.debug(DEBUG_TAG, 'Server supports AUTH XOAUTH2')
605595
this._supportedAuth.push('XOAUTH2')
606596
}
607597

608598
// Detect maximum allowed message size
609-
if ((match = command.line.match(/SIZE (\d+)/i)) && Number(match[1])) {
599+
if ((match = command.data.match(/SIZE (\d+)/i)) && Number(match[1])) {
610600
const maxAllowedSize = Number(match[1])
611601
this.logger.debug(DEBUG_TAG, 'Maximum allowd message size: ' + maxAllowedSize)
612602
}
613603

614604
// Detect if the server supports STARTTLS
615605
if (!this._secureMode) {
616-
if ((command.line.match(/[ -]STARTTLS\s?$/mi) && !this.options.ignoreTLS) || !!this.options.requireTLS) {
606+
if ((command.data.match(/STARTTLS\s?$/mi) && !this.options.ignoreTLS) || !!this.options.requireTLS) {
617607
this._currentAction = this._actionSTARTTLS
618608
this.logger.debug(DEBUG_TAG, 'Sending STARTTLS')
619609
this._sendCommand('STARTTLS')
@@ -649,7 +639,7 @@ class SmtpClient {
649639
/**
650640
* Response to HELO
651641
*
652-
* @param {Object} command Parsed command from the server {statusCode, data, line}
642+
* @param {Object} command Parsed command from the server {statusCode, data}
653643
*/
654644
_actionHELO (command) {
655645
if (!command.success) {
@@ -663,7 +653,7 @@ class SmtpClient {
663653
/**
664654
* Response to AUTH LOGIN, if successful expects base64 encoded username
665655
*
666-
* @param {Object} command Parsed command from the server {statusCode, data, line}
656+
* @param {Object} command Parsed command from the server {statusCode, data}
667657
*/
668658
_actionAUTH_LOGIN_USER (command) {
669659
if (command.statusCode !== 334 || command.data !== 'VXNlcm5hbWU6') {
@@ -679,7 +669,7 @@ class SmtpClient {
679669
/**
680670
* Response to AUTH LOGIN username, if successful expects base64 encoded password
681671
*
682-
* @param {Object} command Parsed command from the server {statusCode, data, line}
672+
* @param {Object} command Parsed command from the server {statusCode, data}
683673
*/
684674
_actionAUTH_LOGIN_PASS (command) {
685675
if (command.statusCode !== 334 || command.data !== 'UGFzc3dvcmQ6') {
@@ -695,7 +685,7 @@ class SmtpClient {
695685
/**
696686
* Response to AUTH XOAUTH2 token, if error occurs send empty response
697687
*
698-
* @param {Object} command Parsed command from the server {statusCode, data, line}
688+
* @param {Object} command Parsed command from the server {statusCode, data}
699689
*/
700690
_actionAUTH_XOAUTH2 (command) {
701691
if (!command.success) {
@@ -711,7 +701,7 @@ class SmtpClient {
711701
* Checks if authentication succeeded or not. If successfully authenticated
712702
* emit `idle` to indicate that an e-mail can be sent using this connection
713703
*
714-
* @param {Object} command Parsed command from the server {statusCode, data, line}
704+
* @param {Object} command Parsed command from the server {statusCode, data}
715705
*/
716706
_actionAUTHComplete (command) {
717707
if (!command.success) {
@@ -731,11 +721,11 @@ class SmtpClient {
731721
/**
732722
* Used when the connection is idle and the server emits timeout
733723
*
734-
* @param {Object} command Parsed command from the server {statusCode, data, line}
724+
* @param {Object} command Parsed command from the server {statusCode, data}
735725
*/
736726
_actionIdle (command) {
737727
if (command.statusCode > 300) {
738-
this._onError(new Error(command.line))
728+
this._onError(new Error(command.data))
739729
return
740730
}
741731

@@ -745,7 +735,7 @@ class SmtpClient {
745735
/**
746736
* Response to MAIL FROM command. Proceed to defining RCPT TO list if successful
747737
*
748-
* @param {Object} command Parsed command from the server {statusCode, data, line}
738+
* @param {Object} command Parsed command from the server {statusCode, data}
749739
*/
750740
_actionMAIL (command) {
751741
if (!command.success) {
@@ -770,7 +760,7 @@ class SmtpClient {
770760
* as this might be related only to the current recipient, not a global error, so
771761
* the following recipients might still be valid
772762
*
773-
* @param {Object} command Parsed command from the server {statusCode, data, line}
763+
* @param {Object} command Parsed command from the server {statusCode, data}
774764
*/
775765
_actionRCPT (command) {
776766
if (!command.success) {
@@ -801,7 +791,7 @@ class SmtpClient {
801791
/**
802792
* Response to the DATA command. Server is now waiting for a message, so emit `onready`
803793
*
804-
* @param {Object} command Parsed command from the server {statusCode, data, line}
794+
* @param {Object} command Parsed command from the server {statusCode, data}
805795
*/
806796
_actionDATA (command) {
807797
// response should be 354 but according to this issue https://github.com/eleith/emailjs/issues/24
@@ -821,7 +811,7 @@ class SmtpClient {
821811
* Response from the server, once the message stream has ended with <CR><LF>.<CR><LF>
822812
* Emits `ondone`.
823813
*
824-
* @param {Object} command Parsed command from the server {statusCode, data, line}
814+
* @param {Object} command Parsed command from the server {statusCode, data}
825815
*/
826816
_actionStream (command) {
827817
var rcpt

0 commit comments

Comments
 (0)