Bug 1762690 - Enable test_filterCustomHeaders.js for imap-js. r=mkmelin
Improve literal string parsing in ImapResponse.jsm. Differential Revision: https://phabricator.services.mozilla.com/D154479 --HG-- extra : amend_source : 97680f7f1c103b0b447b9ef5a7657f592e0e49d3
This commit is contained in:
Родитель
b2b2952daa
Коммит
3a57c93d66
|
@ -204,7 +204,7 @@ class ImapResponse {
|
|||
let tokens = [];
|
||||
while (line) {
|
||||
// Find the first separator.
|
||||
let match = line.match(/[()\[\] ]/);
|
||||
let match = line.match(/[()\[\]" ]/);
|
||||
if (!match) {
|
||||
tokens.push(line);
|
||||
break;
|
||||
|
@ -215,7 +215,27 @@ class ImapResponse {
|
|||
if (token) {
|
||||
tokens.push(token);
|
||||
}
|
||||
if (sep != " ") {
|
||||
if (sep == '"') {
|
||||
// Parse the whole string as a token.
|
||||
line = line.slice(index + 1);
|
||||
let str = "";
|
||||
while (true) {
|
||||
index = line.indexOf('"');
|
||||
if (line[index - 1] == "\\") {
|
||||
// Not the ending quote.
|
||||
str += line.slice(0, index + 1);
|
||||
line = line.slice(index + 1);
|
||||
continue;
|
||||
} else {
|
||||
// The ending quote.
|
||||
str += line.slice(0, index);
|
||||
tokens.push(str.replaceAll('\\"', '"'));
|
||||
line = line.slice(index + 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
} else if (sep != " ") {
|
||||
tokens.push(sep);
|
||||
}
|
||||
line = line.slice(index + 1);
|
||||
|
@ -325,10 +345,10 @@ class MessageData {
|
|||
*/
|
||||
class MailboxData {
|
||||
constructor(tokens) {
|
||||
let [, , attributes, delimiter, ...rest] = tokens;
|
||||
let [, , attributes, delimiter, name] = tokens;
|
||||
this.flags = this._stringsToFlags(attributes);
|
||||
this.delimiter = delimiter.replace(/(^"|"$)/g, "");
|
||||
this.name = unescapeMailboxName(rest);
|
||||
this.delimiter = delimiter;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -381,7 +401,7 @@ class StatusData {
|
|||
|
||||
// The first two tokens are ["*", "STATUS"], the last token is the attribute
|
||||
// list, the middle part is the mailbox name.
|
||||
this.attributes.mailbox = unescapeMailboxName(tokens.slice(2, -1));
|
||||
this.attributes.mailbox = tokens[2];
|
||||
|
||||
let attributes = tokens.at(-1);
|
||||
for (let i = 0; i < attributes.length; i += 2) {
|
||||
|
@ -390,15 +410,3 @@ class StatusData {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore the mailbox name from tokens.
|
||||
* @params {string[]} tokens - E.g. "sub folder" may be tokenized as
|
||||
* ["\"sub", "folder\""]
|
||||
*/
|
||||
function unescapeMailboxName(tokens) {
|
||||
return tokens
|
||||
.join(" ")
|
||||
.replace(/(^"|"$)/g, "")
|
||||
.replaceAll('\\"', '"');
|
||||
}
|
||||
|
|
|
@ -202,6 +202,29 @@ add_task(function test_ListResponse() {
|
|||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* Test folder names containg [] or () or "" can be correctly parsed.
|
||||
*/
|
||||
add_task(function test_parseFolderNames() {
|
||||
let response = new ImapResponse();
|
||||
response.parse(
|
||||
[
|
||||
'* LSUB () "/" "[Gmail]"',
|
||||
'* LSUB () "/" "[Gmail]/All Mail"',
|
||||
'* LSUB () "/" "[Gmail]/Sent"',
|
||||
'* LSUB () "/" "[a(b)])"',
|
||||
'* LSUB () "/" "a \\"b \\"c\\""',
|
||||
"84 OK LSUB completed",
|
||||
"",
|
||||
].join("\r\n")
|
||||
);
|
||||
equal(response.mailboxes.length, 5);
|
||||
deepEqual(
|
||||
response.mailboxes.map(x => x.name),
|
||||
["[Gmail]", "[Gmail]/All Mail", "[Gmail]/Sent", "[a(b)])", 'a "b "c"']
|
||||
);
|
||||
});
|
||||
|
||||
/**
|
||||
* Test STATUS response can be correctly parsed.
|
||||
*/
|
||||
|
|
|
@ -61,10 +61,6 @@ add_task(async function setupTest() {
|
|||
add_task(function checkFilterResults() {
|
||||
let msgHdr = mailTestUtils.firstMsgHdr(IMAPPump.inbox);
|
||||
Assert.ok(msgHdr.isRead);
|
||||
});
|
||||
|
||||
// Cleanup
|
||||
add_task(function endTest() {
|
||||
IMAPPump.server.performTest("UID STORE");
|
||||
teardownIMAPPump();
|
||||
});
|
||||
|
|
|
@ -7,8 +7,6 @@ prefs =
|
|||
mailnews.imap.jsmodule=false
|
||||
|
||||
[test_customCommandReturnsFetchResponse.js]
|
||||
[test_filterCustomHeaders.js]
|
||||
[test_filterNeedsBody.js]
|
||||
[test_folderOfflineFlags.js]
|
||||
[test_gmailAttributes.js]
|
||||
[test_gmailOfflineMsgStore.js]
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
[test_dontStatNoSelect.js]
|
||||
[test_downloadOffline.js]
|
||||
[test_fetchCustomAttribute.js]
|
||||
[test_filterCustomHeaders.js]
|
||||
[test_filterNeedsBody.js]
|
||||
[test_mailboxes.js]
|
||||
[test_imapPasswordFailure.js]
|
||||
[test_starttlsFailure.js]
|
||||
|
|
|
@ -7,8 +7,6 @@ prefs =
|
|||
mailnews.imap.jsmodule=false
|
||||
|
||||
[test_customCommandReturnsFetchResponse.js]
|
||||
[test_filterCustomHeaders.js]
|
||||
[test_filterNeedsBody.js]
|
||||
[test_folderOfflineFlags.js]
|
||||
[test_gmailAttributes.js]
|
||||
[test_gmailOfflineMsgStore.js]
|
||||
|
|
Загрузка…
Ссылка в новой задаче