Bug 1762688 - Enable test_imapFolderCopy.js for imap-js. r=mkmelin,benc

Implement ImapService.moveFolder.

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

--HG--
extra : amend_source : 7e932c7758deb8f2bc1700519bb32caa890114c8
This commit is contained in:
Ping Chen 2022-09-01 20:44:15 +10:00
Родитель 70adc96ace
Коммит 05ec66220c
7 изменённых файлов: 61 добавлений и 12 удалений

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

@ -86,6 +86,7 @@ class ImapClient {
this.channel = null;
this._urlListener = null;
this._msgWindow = null;
this._authenticating = false;
}
/**
@ -178,6 +179,19 @@ class ImapClient {
this._sendTagged(`RENAME "${oldName}" "${newName}"`);
}
/**
* Move a source folder to be a child of another folder.
* @param {nsIMsgFolder} srcFolder - The source folder to move.
* @param {nsIMsgFolder} dstFolder - The target parent folder.
*/
moveFolder(srcFolder, dstFolder) {
this._logger.debug("moveFolder", srcFolder.URI, dstFolder.URI);
let oldName = this._getServerFolderName(srcFolder);
let newName = this._getServerSubFolderName(dstFolder, srcFolder.name);
this._nextAction = this._actionRenameResponse(oldName, newName);
this._sendTagged(`RENAME "${oldName}" "${newName}"`);
}
/**
* Ensure a folder exists on the server. Create one if not already exists.
* @param {nsIMsgFolder} parent - The parent folder to check.
@ -560,6 +574,16 @@ class ImapClient {
}
this._response.parse(stringPayload);
this._logger.debug("Parsed:", this._response);
if (
!this._authenticating &&
this._response.done &&
this._response.status &&
this._response.tag != "+" &&
!["OK", "+"].includes(this._response.status)
) {
this._actionDone(ImapUtils.NS_MSG_ERROR_IMAP_COMMAND_FAILED);
return;
}
if (!this._capabilities || this._idling || this._response.done) {
this._nextAction?.(this._response);
}
@ -608,9 +632,11 @@ class ImapClient {
}
if (this._socket?.readyState != "open") {
this._logger.warn(
`Failed to send because socket state is ${this._socket?.readyState}`
);
if (!str.includes("LOGOUT")) {
this._logger.warn(
`Failed to send because socket state is ${this._socket?.readyState}`
);
}
return;
}
@ -722,6 +748,8 @@ class ImapClient {
return;
}
this._authenticating = true;
this._currentAuthMethod = this._nextAuthMethod;
this._nextAuthMethod = this._possibleAuthMethods[
this._possibleAuthMethods.indexOf(this._currentAuthMethod) + 1
@ -796,6 +824,8 @@ class ImapClient {
* @param {ImapResponse} res - Response received from the server.
*/
_actionAuthResponse = res => {
this._authenticating = false;
if (res.status == "OK") {
if (res.capabilities) {
this._capabilities = res.capabilities;
@ -813,6 +843,7 @@ class ImapClient {
let action = this._authenticator.promptAuthFailed();
if (action == 1) {
// Cancel button pressed.
this._socket.close();
this._actionDone(Cr.NS_ERROR_FAILURE);
return;
}
@ -1242,6 +1273,15 @@ class ImapClient {
this._actionAfterSelectFolder = this._actionUidFetch;
this._nextAction = this._actionSelectResponse;
this._sendTagged(`SELECT "${this.folder.name}"`);
} else if (res.messages.length || res.exists) {
let outFolderInfo = {};
this.folder.getDBFolderInfoAndDB(outFolderInfo);
let highestUid = outFolderInfo.value.getUint32Property(
"highestRecordedUID",
0
);
this._nextAction = this._actionUidFetchResponse;
this._sendTagged(`UID FETCH ${highestUid + 1}:* (FLAGS)`);
} else {
this._actionDone();
}
@ -1270,9 +1310,6 @@ class ImapClient {
*/
_actionDone = (status = Cr.NS_OK) => {
this._logger.debug(`Done with status=${status}`);
if (status != Cr.NS_OK) {
this._socket.close();
}
this._nextAction = null;
this._urlListener?.OnStopRunningUrl(this.runningUrl, status);
this.runningUrl.SetUrlState(false, status);

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

@ -104,7 +104,7 @@ class ImapResponse {
this.supportedUserFlags =
ImapUtils.FLAG_LABEL |
ImapUtils.FLAG_MDN_SENT |
ImapUtils.FLAG_FORWARDED |
ImapUtils.FLAG_SUPPORT_FORWARDED_FLAG |
ImapUtils.FLAG_SUPPORT_USER_FLAG;
}
break;
@ -143,7 +143,7 @@ class ImapResponse {
this.supportedUserFlags =
ImapUtils.FLAG_LABEL |
ImapUtils.FLAG_MDN_SENT |
ImapUtils.FLAG_FORWARDED |
ImapUtils.FLAG_SUPPORT_FORWARDED_FLAG |
ImapUtils.FLAG_SUPPORT_USER_FLAG;
}
break;

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

@ -245,6 +245,17 @@ class ImapService {
});
}
moveFolder(srcFolder, dstFolder, urlListener, msgWindow) {
this._withClient(srcFolder, client => {
let runningUrl = client.startRunningUrl(urlListener, msgWindow);
runningUrl.QueryInterface(Ci.nsIImapUrl).imapAction =
Ci.nsIImapUrl.nsImapMoveFolderHierarchy;
client.onReady = () => {
client.moveFolder(srcFolder, dstFolder);
};
});
}
storeCustomKeywords(folder, msgWindow, flagsToAdd, flagsToSubtract, uids) {
return this._withClient(folder, (client, runningUrl) => {
client.startRunningUrl(null, msgWindow, runningUrl);

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

@ -8,6 +8,8 @@ const EXPORTED_SYMBOLS = ["ImapUtils"];
* Collection of helper functions for IMAP.
*/
var ImapUtils = {
NS_MSG_ERROR_IMAP_COMMAND_FAILED: 0x80550021,
/** @see nsImapCore.h */
FLAG_NONE: 0x0000,
/** mailbox flags */
@ -45,6 +47,7 @@ var ImapUtils = {
FLAG_MDN_SENT: 0x0080,
FLAG_CUSTOM_KEYWORD: 0x0100,
FLAG_LABEL: 0x0e00,
FLAG_SUPPORT_FORWARDED_FLAG: 0x4000,
FLAG_SUPPORT_USER_FLAG: 0x8000,
logger: console.createInstance({

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

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

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

@ -18,6 +18,8 @@
[test_imapCopyTimeout.js]
[test_imapFilterActions.js]
[test_imapFilterActionsPostplugin.js]
[test_imapFlagChange.js]
[test_imapFolderCopy.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_imapFlagChange.js]
[test_imapFolderCopy.js]
[test_imapHdrChunking.js]
[test_imapHdrStreaming.js]
[test_imapHighWater.js]