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

Differential Revision: https://phabricator.services.mozilla.com/D154953
This commit is contained in:
Ping Chen 2022-08-18 01:14:32 +00:00
Родитель 64e1bcf931
Коммит bc5488ca86
5 изменённых файлов: 69 добавлений и 9 удалений

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

@ -61,6 +61,17 @@ class ImapClient {
this._charsetManager = Cc[
"@mozilla.org/charset-converter-manager;1"
].getService(Ci.nsICharsetConverterManager);
this._loadPrefs();
}
/**
* Load imap related preferences, many behaviors depend on these pref values.
*/
_loadPrefs() {
this._prefs = {
tcpTimeout: Services.prefs.getIntPref("mailnews.tcptimeout"),
};
}
/**
@ -172,13 +183,7 @@ class ImapClient {
*/
ensureFolderExists(parent, folderName) {
this._logger.debug("ensureFolderExists", parent.URI, folderName);
let mailboxName = this._getServerFolderName(parent);
if (folderName) {
let delimiter =
parent.QueryInterface(Ci.nsIMsgImapMailFolder).hierarchyDelimiter ||
"/";
mailboxName += delimiter + folderName;
}
let mailboxName = this._getServerSubFolderName(parent, folderName);
this._nextAction = res => {
if (res.mailboxes.length) {
// Already exists.
@ -193,6 +198,19 @@ class ImapClient {
this._sendTagged(`LIST "" "${mailboxName}"`);
}
/**
* Create a folder on the server.
* @param {nsIMsgFolder} parent - The parent folder to check.
* @param {string} folderName - The folder name.
*/
createFolder(parent, folderName) {
this._logger.debug("createFolder", parent.URI, folderName);
let mailboxName = this._getServerSubFolderName(parent, folderName);
this._actionCreateAndSubscribe(mailboxName, res => {
this._actionList(mailboxName, () => this._actionDone());
});
}
/**
* Fetch the attribute of messages.
* @param {nsIMsgFolder} folder - The folder to check.
@ -236,6 +254,10 @@ class ImapClient {
* @returns {string}
*/
_getServerFolderName(folder) {
if (folder.isServer) {
return "";
}
if (folder.onlineName) {
return folder.onlineName;
}
@ -247,6 +269,24 @@ class ImapClient {
);
}
/**
* Get the server name of a sub folder. The sub folder may or may not exist on
* the server.
* @param {nsIMsgFolder} parent - The parent folder.
* @param {string} folderName - The sub folder name.
* @returns {string}
*/
_getServerSubFolderName(parent, folderName) {
let mailboxName = this._getServerFolderName(parent);
if (mailboxName) {
let delimiter =
parent.QueryInterface(Ci.nsIMsgImapMailFolder).hierarchyDelimiter ||
"/";
return mailboxName + delimiter + folderName;
}
return folderName;
}
/**
* Fetch the full content of a message by UID.
* @param {nsIMsgFolder} folder - The associated folder.
@ -446,6 +486,11 @@ class ImapClient {
this._socket.ondata = this._onData;
this._socket.onclose = this._onClose;
this._nextAction = this._actionCapabilityResponse;
this._socket.transport.setTimeout(
Ci.nsISocketTransport.TIMEOUT_READ_WRITE,
this._prefs.tcpTimeout
);
};
/**
@ -473,6 +518,11 @@ class ImapClient {
*/
_onError = event => {
this._logger.error(event, event.name, event.message, event.errorCode);
if (event.errorCode == Cr.NS_ERROR_NET_TIMEOUT) {
this._actionError("imapNetTimeoutError");
this._actionDone(event.errorCode);
return;
}
this.logout();
let secInfo = event.target.transport?.securityInfo;
if (secInfo) {

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

@ -233,6 +233,17 @@ class ImapService {
});
}
createFolder(parent, folderName, urlListener) {
return this._withClient(parent, (client, runningUrl) => {
client.startRunningUrl(urlListener, null, runningUrl);
runningUrl.QueryInterface(Ci.nsIImapUrl).imapAction =
Ci.nsIImapUrl.nsImapCreateFolder;
client.onReady = () => {
client.createFolder(parent, folderName);
};
});
}
/**
* Do some actions with a connection.
* @param {nsIMsgFolder} folder - The associated folder.

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

@ -11,7 +11,6 @@ prefs =
[test_gmailAttributes.js]
[test_imapAutoSync.js]
[test_imapClientid.js]
[test_imapCopyTimeout.js]
[test_imapFilterActions.js]
[test_imapFilterActionsPostplugin.js]
[test_imapFlagChange.js]

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

@ -15,6 +15,7 @@
[test_imapAttachmentSaves.js]
[test_imapChunks.js]
[test_imapContentLength.js]
[test_imapCopyTimeout.js]
[test_imapPasswordFailure.js]
[test_mailboxes.js]
[test_starttlsFailure.js]

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

@ -10,7 +10,6 @@ prefs =
[test_folderOfflineFlags.js]
[test_gmailAttributes.js]
[test_imapAutoSync.js]
[test_imapCopyTimeout.js]
[test_imapFilterActions.js]
[test_imapFilterActionsPostplugin.js]
[test_imapFlagChange.js]