Bug 1762688 - Enable test_imapFilterActions.js for imap-js. r=mkmelin

Implement ImapMessageService.CopyMessage and ImapService.storeCustomKeywords.

Differential Revision: https://phabricator.services.mozilla.com/D155559

Depends on D155778

--HG--
extra : histedit_source : 66ae8bce6a45ebbfd47d654966375f7cfa9b2086
This commit is contained in:
Ping Chen 2022-08-27 11:51:36 +00:00
Родитель 9926265fa5
Коммит 81be03390e
9 изменённых файлов: 156 добавлений и 12 удалений

Просмотреть файл

@ -428,7 +428,7 @@ class ImapClient {
.UpdateImapMailboxStatus(this, {
QueryInterface: ChromeUtils.generateQI(["nsIMailboxSpec"]),
nextUID: res.attributes.uidnext,
numMessages: res.attributes.messages,
numMessages: res.attributes.messages.length,
numUnseenMessages: res.attributes.unseen,
});
folder.msgDatabase = null;
@ -440,6 +440,57 @@ class ImapClient {
);
}
/**
* Update message flags.
* @param {nsIMsgFolder} folder - The associated folder.
* @param {string} flagsToAdd - The flags to add.
* @param {string} flagsToSubtract - The flags to subtract.
* @param {string} uids - The message uids.
*/
storeCustomKeywords(folder, flagsToAdd, flagsToSubtract, uids) {
this._logger.debug(
"storeCustomKeywords",
folder.URI,
flagsToAdd,
flagsToSubtract,
uids
);
this._msgSink = this.folder.QueryInterface(Ci.nsIImapMessageSink);
let handleResponse = res => {
for (let msg of res.messages) {
let uid = this._messageUids[msg.sequence];
this._msgSink.notifyMessageFlags(
msg.flags,
msg.keywords,
uid,
this._folderState.highestmodseq
);
}
};
let subtractFlags = () => {
if (flagsToSubtract) {
this._nextAction = res => {
handleResponse(res);
this._actionDone();
};
this._sendTagged(`UID STORE ${uids} -FLAGS (${flagsToAdd})`);
} else {
this._actionDone();
}
};
this._actionFolderCommand(folder, () => {
if (flagsToAdd) {
this._nextAction = res => {
handleResponse(res);
subtractFlags();
};
this._sendTagged(`UID STORE ${uids} +FLAGS (${flagsToAdd})`);
} else {
subtractFlags();
}
});
}
/**
* Send IDLE command to the server.
*/
@ -1081,7 +1132,7 @@ class ImapClient {
.QueryInterface(Ci.nsIImapMessageSink)
.notifyMessageFlags(
msg.flags,
"",
msg.keywords,
msg.uid,
this._folderState.highestmodseq
);
@ -1109,6 +1160,10 @@ class ImapClient {
QueryInterface: ChromeUtils.generateQI(["nsIMailboxSpec"]),
folder_UIDVALIDITY: this._folderState.uidvalidity,
box_flags: this._folderState.flags,
supportedUserFlags: this._folderState.supportedUserFlags,
nextUID: this._folderState.attributes.uidnext,
numMessages: this._messages.size,
numUnseenMessages: this._folderState.attributes.unseen,
flagState: this.flagAndUidState,
};
}
@ -1119,8 +1174,8 @@ class ImapClient {
*/
_actionUidFetchBodyResponse(res) {
this._msgSink = this.folder.QueryInterface(Ci.nsIImapMessageSink);
this._folderSink = this.folder.QueryInterface(Ci.nsIImapMailFolderSink);
for (let msg of res.messages) {
this._folderSink = this.folder.QueryInterface(Ci.nsIImapMailFolderSink);
this._folderSink.StartMessage(this.runningUrl);
let hdrXferInfo = {
numHeaders: 1,
@ -1148,6 +1203,7 @@ class ImapClient {
this._folderSink.EndMessage(this.runningUrl, msg.uid);
this.onData?.(msg.body);
}
this._folderSink.headerFetchCompleted(this);
this.onData?.();
this._actionDone();
}
@ -1172,7 +1228,7 @@ class ImapClient {
.QueryInterface(Ci.nsIImapMessageSink)
.notifyMessageFlags(
msg.flags,
"",
msg.keywords,
uid,
this._folderState.highestmodseq
);
@ -1225,12 +1281,26 @@ class ImapClient {
};
/** @see nsIImapProtocol */
NotifyBodysToDownload(keys) {
this._logger.debug("NotifyBodysToDownload", keys);
}
GetRunningUrl() {
this._logger.debug("GetRunningUrl");
}
get flagAndUidState() {
// The server sequence is 1 based, nsIImapFlagAndUidState sequence is 0 based.
let getUidOfMessage = index => this._messageUids[index + 1];
let getMessageFlagsByUid = uid => this._messages.get(uid)?.flags;
return {
QueryInterface: ChromeUtils.generateQI(["nsIImapFlagAndUidState"]),
numberOfMessages: this._messages.size,
getUidOfMessage: index => this._messageUids[index],
getMessageFlagsByUid: uid => this._messages.get(uid)?.flags,
getUidOfMessage,
getMessageFlags: index => getMessageFlagsByUid(getUidOfMessage(index)),
hasMessage: uid => this._messages.has(uid),
getMessageFlagsByUid,
getCustomFlags: uid => this._messages.get(uid)?.keywords,
};
}

Просмотреть файл

@ -26,6 +26,44 @@ class BaseMessageService {
_logger = ImapUtils.logger;
CopyMessage(
messageUri,
copyListener,
moveMessage,
urlListener,
msgWindow,
outUrl
) {
this._logger.debug("CopyMessage", messageUri, moveMessage);
let { host, folderName, key } = this._decomposeMessageUri(messageUri);
let imapUrl = Services.io
.newURI(`imap://${host}/fetch>UID>/${folderName}>${key}`)
.QueryInterface(Ci.nsIImapUrl);
let folder = lazy.MailUtils.getOrCreateFolder(
`imap://${host}/${folderName}`
);
if (urlListener) {
imapUrl
.QueryInterface(Ci.nsIMsgMailNewsUrl)
.RegisterListener(urlListener);
}
return MailServices.imap.fetchMessage(
imapUrl,
moveMessage
? Ci.nsIImapUrl.nsImapOnlineToOfflineMove
: Ci.nsIImapUrl.nsImapOnlineToOfflineCopy,
folder,
folder.QueryInterface(Ci.nsIImapMessageSink),
msgWindow,
copyListener,
key,
false,
{}
);
}
DisplayMessage(
messageUri,
displayConsumer,

Просмотреть файл

@ -100,6 +100,13 @@ class ImapResponse {
case "FLAGS":
// * FLAGS (\Seen \Draft $Forwarded)
this.flags = ImapUtils.stringsToFlags(tokens[2]);
if (tokens[2].includes("\\*")) {
this.supportedUserFlags =
ImapUtils.FLAG_LABEL |
ImapUtils.FLAG_MDN_SENT |
ImapUtils.FLAG_FORWARDED |
ImapUtils.FLAG_SUPPORT_USER_FLAG;
}
break;
case "LIST":
case "LSUB":
@ -132,6 +139,13 @@ class ImapResponse {
case "PERMANENTFLAGS":
// * OK [PERMANENTFLAGS (\\Seen \\Draft $Forwarded \\*)]
this.permanentflags = ImapUtils.stringsToFlags(tokens[2][1]);
if (tokens[2][1].includes("\\*")) {
this.supportedUserFlags =
ImapUtils.FLAG_LABEL |
ImapUtils.FLAG_MDN_SENT |
ImapUtils.FLAG_FORWARDED |
ImapUtils.FLAG_SUPPORT_USER_FLAG;
}
break;
default:
let field = type.toLowerCase();
@ -319,6 +333,9 @@ class MessageData {
break;
case "FLAGS":
this.flags = ImapUtils.stringsToFlags(tokens[i + 1]);
this.keywords = tokens[i + 1]
.filter(x => !x.startsWith("\\"))
.join(" ");
break;
case "BODY": {
// bodySection is the part between [ and ].

Просмотреть файл

@ -119,6 +119,7 @@ class ImapService {
msgIds,
convertDataToText
) {
imapUrl.imapAction = imapAction;
if (displayConsumer instanceof Ci.nsIDocShell) {
imapUrl
.QueryInterface(Ci.nsIMsgMailNewsUrl)
@ -244,6 +245,17 @@ class ImapService {
});
}
storeCustomKeywords(folder, msgWindow, flagsToAdd, flagsToSubtract, uids) {
return this._withClient(folder, (client, runningUrl) => {
client.startRunningUrl(null, msgWindow, runningUrl);
runningUrl.QueryInterface(Ci.nsIImapUrl).imapAction =
Ci.nsIImapUrl.nsImapMsgStoreCustomKeywords;
client.onReady = () => {
client.storeCustomKeywords(folder, flagsToAdd, flagsToSubtract, uids);
};
});
}
/**
* Do some actions with a connection.
* @param {nsIMsgFolder} folder - The associated folder.

Просмотреть файл

@ -8319,8 +8319,14 @@ nsImapMailFolder::StoreCustomKeywords(nsIMsgWindow* aMsgWindow,
NS_ENSURE_SUCCESS(rv, rv);
nsAutoCString msgIds;
AllocateUidStringFromKeys(aKeysToStore, msgIds);
return imapService->StoreCustomKeywords(this, aMsgWindow, aFlagsToAdd,
aFlagsToSubtract, msgIds, _retval);
nsCOMPtr<nsIURI> retUri;
rv = imapService->StoreCustomKeywords(this, aMsgWindow, aFlagsToAdd,
aFlagsToSubtract, msgIds,
getter_AddRefs(retUri));
if (_retval) {
retUri.forget(_retval);
}
return rv;
}
NS_IMETHODIMP nsImapMailFolder::NotifyIfNewMail() {

Просмотреть файл

@ -50,16 +50,19 @@ add_task(function test_FetchResponse_flags() {
uid: 500,
flags:
ImapUtils.FLAG_ANSWERED | ImapUtils.FLAG_SEEN | ImapUtils.FLAG_FORWARDED,
keywords: "$Forwarded",
});
deepEqual(response.messages[1], {
sequence: 2,
uid: 600,
flags: ImapUtils.FLAG_SEEN,
keywords: "",
});
deepEqual(response.messages[2], {
sequence: 3,
uid: 601,
flags: 0,
keywords: "",
});
});

Просмотреть файл

@ -11,8 +11,6 @@ prefs =
[test_gmailAttributes.js]
[test_imapAutoSync.js]
[test_imapClientid.js]
[test_imapFilterActions.js]
[test_imapFilterActionsPostplugin.js]
[test_imapFlagChange.js]
[test_imapFolderCopy.js]
[test_imapHdrChunking.js]

Просмотреть файл

@ -16,6 +16,8 @@
[test_imapChunks.js]
[test_imapContentLength.js]
[test_imapCopyTimeout.js]
[test_imapFilterActions.js]
[test_imapFilterActionsPostplugin.js]
[test_imapPasswordFailure.js]
[test_mailboxes.js]
[test_starttlsFailure.js]

Просмотреть файл

@ -10,8 +10,6 @@ prefs =
[test_folderOfflineFlags.js]
[test_gmailAttributes.js]
[test_imapAutoSync.js]
[test_imapFilterActions.js]
[test_imapFilterActionsPostplugin.js]
[test_imapFlagChange.js]
[test_imapFolderCopy.js]
[test_imapHdrChunking.js]