diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /comm/mailnews/local/test/unit/head_maillocal.js | |
parent | Initial commit. (diff) | |
download | thunderbird-upstream.tar.xz thunderbird-upstream.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'comm/mailnews/local/test/unit/head_maillocal.js')
-rw-r--r-- | comm/mailnews/local/test/unit/head_maillocal.js | 214 |
1 files changed, 214 insertions, 0 deletions
diff --git a/comm/mailnews/local/test/unit/head_maillocal.js b/comm/mailnews/local/test/unit/head_maillocal.js new file mode 100644 index 0000000000..dff897b36e --- /dev/null +++ b/comm/mailnews/local/test/unit/head_maillocal.js @@ -0,0 +1,214 @@ +var { MailServices } = ChromeUtils.import( + "resource:///modules/MailServices.jsm" +); +var { XPCOMUtils } = ChromeUtils.importESModule( + "resource://gre/modules/XPCOMUtils.sys.mjs" +); +var { mailTestUtils } = ChromeUtils.import( + "resource://testing-common/mailnews/MailTestUtils.jsm" +); +var { localAccountUtils } = ChromeUtils.import( + "resource://testing-common/mailnews/LocalAccountUtils.jsm" +); + +var test = null; + +// WebApps.jsm called by ProxyAutoConfig (PAC) requires a valid nsIXULAppInfo. +var { getAppInfo, newAppInfo, updateAppInfo } = ChromeUtils.importESModule( + "resource://testing-common/AppInfo.sys.mjs" +); +updateAppInfo(); + +// Ensure the profile directory is set up +do_get_profile(); + +var gDEPTH = "../../../../"; + +// Import the pop3 server scripts +/* import-globals-from ../../../test/fakeserver/Maild.jsm */ +/* import-globals-from ../../../test/fakeserver/Auth.jsm */ +/* import-globals-from ../../../test/fakeserver/Pop3d.jsm */ +var { + nsMailServer, + gThreadManager, + fsDebugNone, + fsDebugAll, + fsDebugRecv, + fsDebugRecvSend, +} = ChromeUtils.import("resource://testing-common/mailnews/Maild.jsm"); +var { AuthPLAIN, AuthLOGIN, AuthCRAM } = ChromeUtils.import( + "resource://testing-common/mailnews/Auth.jsm" +); +var { + Pop3Daemon, + POP3_RFC1939_handler, + POP3_RFC2449_handler, + POP3_RFC5034_handler, +} = ChromeUtils.import("resource://testing-common/mailnews/Pop3d.jsm"); + +// Setup the daemon and server +// If the debugOption is set, then it will be applied to the server. +function setupServerDaemon(debugOption) { + var daemon = new Pop3Daemon(); + var extraProps = {}; + function createHandler(d) { + var handler = new POP3_RFC5034_handler(d); + for (var prop in extraProps) { + handler[prop] = extraProps[prop]; + } + return handler; + } + var server = new nsMailServer(createHandler, daemon); + if (debugOption) { + server.setDebugLevel(debugOption); + } + return [daemon, server, extraProps]; +} + +function createPop3ServerAndLocalFolders(port, hostname = "localhost") { + localAccountUtils.loadLocalMailAccount(); + let server = localAccountUtils.create_incoming_server( + "pop3", + port, + "fred", + "wilma", + hostname + ); + return server; +} + +var gCopyListener = { + callbackFunction: null, + copiedMessageHeaderKeys: [], + OnStartCopy() {}, + OnProgress(aProgress, aProgressMax) {}, + SetMessageKey(aKey) { + try { + this.copiedMessageHeaderKeys.push(aKey); + } catch (ex) { + dump(ex); + } + }, + GetMessageId(aMessageId) {}, + OnStopCopy(aStatus) { + if (this.callbackFunction) { + mailTestUtils.do_timeout_function(0, this.callbackFunction, null, [ + this.copiedMessageHeaderKeys, + aStatus, + ]); + } + }, +}; + +/** + * copyFileMessageInLocalFolder + * A utility wrapper of nsIMsgCopyService.copyFileMessage to copy a message + * into local inbox folder. + * + * @param aMessageFile An instance of nsIFile to copy. + * @param aMessageFlags Message flags which will be set after message is + * copied + * @param aMessageKeyword Keywords which will be set for newly copied + * message + * @param aMessageWindow Window for notification callbacks, can be null + * @param aCallback Callback function which will be invoked after + * message is copied + */ +function copyFileMessageInLocalFolder( + aMessageFile, + aMessageFlags, + aMessageKeywords, + aMessageWindow, + aCallback +) { + // Set up local folders + localAccountUtils.loadLocalMailAccount(); + + gCopyListener.callbackFunction = aCallback; + // Copy a message into the local folder + MailServices.copy.copyFileMessage( + aMessageFile, + localAccountUtils.inboxFolder, + null, + false, + aMessageFlags, + aMessageKeywords, + gCopyListener, + aMessageWindow + ); +} + +function do_check_transaction(real, expected) { + // If we don't spin the event loop before starting the next test, the readers + // aren't expired. In this case, the "real" real transaction is the last one. + if (Array.isArray(real)) { + real = real[real.length - 1]; + } + + // real.them may have an extra QUIT on the end, where the stream is only + // closed after we have a chance to process it and not them. We therefore + // excise this from the list + if (real.them[real.them.length - 1] == "QUIT") { + real.them.pop(); + } + + if (expected[0] == "AUTH") { + // We don't send initial AUTH command now. + expected = expected.slice(1); + } + + Assert.equal(real.them.join(","), expected.join(",")); + dump("Passed test " + test + "\n"); +} + +function create_temporary_directory() { + let directory = Services.dirsvc.get("TmpD", Ci.nsIFile); + directory.append("mailFolder"); + directory.createUnique(Ci.nsIFile.DIRECTORY_TYPE, parseInt("0700", 8)); + return directory; +} + +function create_sub_folders(parent, subFolders) { + parent.leafName = parent.leafName + ".sbd"; + parent.create(Ci.nsIFile.DIRECTORY_TYPE, parseInt("0700", 8)); + + for (let folder in subFolders) { + let subFolder = parent.clone(); + subFolder.append(subFolders[folder].name); + subFolder.create(Ci.nsIFile.NORMAL_FILE_TYPE, parseInt("0600", 8)); + if (subFolders[folder].subFolders) { + create_sub_folders(subFolder, subFolders[folder].subFolders); + } + } +} + +function create_mail_directory(subFolders) { + let root = create_temporary_directory(); + + for (let folder in subFolders) { + if (!subFolders[folder].subFolders) { + continue; + } + let directory = root.clone(); + directory.append(subFolders[folder].name); + create_sub_folders(directory, subFolders[folder].subFolders); + } + + return root; +} + +function setup_mailbox(type, mailboxPath) { + let user = Services.uuid.generateUUID().toString(); + let incomingServer = MailServices.accounts.createIncomingServer( + user, + "Local Folder", + type + ); + incomingServer.localPath = mailboxPath; + + return incomingServer.rootFolder; +} + +registerCleanupFunction(function () { + load(gDEPTH + "mailnews/resources/mailShutdown.js"); +}); |