From 8c68fcc23dc3650aa23c66c4e14d924b85106b40 Mon Sep 17 00:00:00 2001 From: mscdex Date: Thu, 18 Jul 2013 10:36:32 -0400 Subject: [PATCH] Parser: relax continuation response checking for broken IMAP server implementations --- lib/Parser.js | 4 ++-- test/test-parser.js | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/Parser.js b/lib/Parser.js index 468b717..3398059 100644 --- a/lib/Parser.js +++ b/lib/Parser.js @@ -10,14 +10,14 @@ var CH_LF = 10, LITPLACEHOLDER = String.fromCharCode(0), EMPTY_READCB = function(n) {}, RE_INTEGER = /^\d+$/, - RE_PRECEDING = /^(?:\*|A\d+|\+) /, + RE_PRECEDING = /^(?:(?:\*|A\d+) )|\+ ?/, RE_BODYLITERAL = /BODY\[(.*)\] \{(\d+)\}$/i, RE_SEQNO = /^\* (\d+)/, RE_LISTCONTENT = /^\((.*)\)$/, RE_LITERAL = /\{(\d+)\}$/, RE_UNTAGGED = /^\* (?:(OK|NO|BAD|BYE|FLAGS|LIST|LSUB|SEARCH|STATUS|CAPABILITY|NAMESPACE|PREAUTH|SORT|THREAD|ESEARCH|QUOTA|QUOTAROOT)|(\d+) (EXPUNGE|FETCH|RECENT|EXISTS))(?: (?:\[([^\]]+)\] )?(.+))?$/i, RE_TAGGED = /^A(\d+) (OK|NO|BAD) (?:\[([^\]]+)\] )?(.+)$/i, - RE_CONTINUE = /^\+ (?:\[([^\]]+)\] )?(.+)$/i, + RE_CONTINUE = /^\+(?: (?:\[([^\]]+)\] )?(.+))?$/i, RE_CRLF = /\r\n/g, RE_HDR = /^([^:]+):[ \t]?(.+)?$/, RE_ENCWORD = /=\?([^?]*?)\?([qb])\?(.*?)\?=/gi, diff --git a/test/test-parser.js b/test/test-parser.js index 9f2802f..333983c 100644 --- a/test/test-parser.js +++ b/test/test-parser.js @@ -34,6 +34,13 @@ var CR = '\r', LF = '\n', CRLF = CR + LF; ], what: 'Continuation with text code' }, + { source: ['+', CRLF], + expected: [ { textCode: undefined, + text: undefined + } + ], + what: 'Continuation (broken -- RFC violation) sent by AOL IMAP' + }, { source: ['* NAMESPACE ', '(("" "/")) ', '(("~" "/")) ',