From ce87915fb0a283d99ff163ded66c8ff5d00bf104 Mon Sep 17 00:00:00 2001 From: mscdex Date: Thu, 4 Apr 2013 16:34:48 -0400 Subject: [PATCH] pass base64-decoded message on continuation to callback as error for xoauth2 --- lib/imap.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/imap.js b/lib/imap.js index f45a16c..ef29b4b 100644 --- a/lib/imap.js +++ b/lib/imap.js @@ -661,13 +661,18 @@ ImapConnection.prototype.connect = function(loginCb) { var args = requests[0].cbargs, cmdstr = requests[0].cmdstr; if (!m) { - if (requests[0].cmd !== 'APPEND') { - err = new Error('Unexpected continuation'); + if (requests[0].cmd === 'APPEND') + return requests[0].callback(); + else { + var isXOAuth2 = (cmdstr.indexOf('AUTHENTICATE XOAUTH2') === 0), + msg = (isXOAuth2 + ? new Buffer(line.substr(2), 'base64').toString('utf8') + : 'Unexpected continuation'); + err = new Error(msg); err.level = 'protocol'; - err.type = 'continuation'; + err.type = (isXOAuth2 ? 'failure' : 'continuation'); err.request = cmdstr; - } else - return requests[0].callback(); + } } else if (m[1] !== 'OK') { // m[1]: error type // m[2]: resp-text-code