@@ -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 ( / A U T H (?: \s + [ ^ \n ] * \s + | \s + ) P L A I N / i) ) {
581+ if ( command . data . match ( / A U T H (?: \s + [ ^ \n ] * \s + | \s + ) P L A I N / 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 ( / A U T H (?: \s + [ ^ \n ] * \s + | \s + ) L O G I N / i) ) {
587+ if ( command . data . match ( / A U T H (?: \s + [ ^ \n ] * \s + | \s + ) L O G I N / 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 ( / A U T H (?: \s + [ ^ \n ] * \s + | \s + ) X O A U T H 2 / i) ) {
593+ if ( command . data . match ( / A U T H (?: \s + [ ^ \n ] * \s + | \s + ) X O A U T H 2 / 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 ( / S I Z E ( \d + ) / i) ) && Number ( match [ 1 ] ) ) {
599+ if ( ( match = command . data . match ( / S I Z E ( \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 ( / [ - ] S T A R T T L S \s ? $ / mi) && ! this . options . ignoreTLS ) || ! ! this . options . requireTLS ) {
606+ if ( ( command . data . match ( / S T A R T T L S \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