Archive a message and then get its URI
8 posts
• Page 1 of 1
I am using this JavaScript code to obtain the URI of a message selected:
var msgHdr = gFolderDisplay.selectedMessage; var msgUri = msgHdr.folder.getUriForMsg(msgHdr); The problem with this is that the URI changes once the message is archived (as the folder where the message is stored changes). So I have to manually archive the message, find the message in the destination folder, select it, and then execute the previous code in order to have the final URI. I would like to avoid all this process. Is there any way to perform the archiving (i.e., emulate that the user clicked on the "Archive" button) and then retrieve the URI automatically? It would be something like this: var msgHdr = gFolderDisplay.selectedMessage; var msgUri = magicMethodThatArchivesTheMessageAndReturnsItsURIonceArchived(msgHdr) I'm confused about how magicMethodThatArchivesTheMessageAndReturnsItsURIonceArchived could be implemented. Any idea would be very welcome! I can't get the new messageKey from the archiver object.
I tried using the nsIMsgFolderNotificationService listener, but it doesn't work. Reference (comm-release is not available) http://searchfox.org/comm-central/search?q=MsgArchiveSelectedMessages http://searchfox.org/comm-central/source/mail/base/modules/MessageArchiver.jsm http://searchfox.org/comm-central/source/mail/config/version.txt Testing in error console...
Similar thread: viewtopic.php?f=19&t=3041933 ThunderKdB search results http://github.com/cleidigh/ThunderKdB/search?q=msgDatabase+path:/xall/x68+filename:.js http://github.com/cleidigh/ThunderKdB/search?q=getMsgHdrForMessageID+path:/xall/x68+filename:.js Thank you for all the ideas. I am trying to find a solution to the problem.
In one of my attempts, I stumped at the following problem. The archiving of the message is asynchronous. Is there any way to block the code and wait for the oncomplete function to execute before continuing the execution? I tried to set a variable "end" to true when executing oncomplete and test its value with a loop, but it seems there is no sleep method that I could execute between sleeps (a busy loop with no sleep freezes TB, as expected). The above code works for me with a selected message in the Inbox folder.
After running the code, I checked the messageId of the selected message in the All Mail folder.
Are you asking how to force an asynchronous call to behave synchronously? Asynchronous JavaScript http://developer.mozilla.org/docs/Learn/JavaScript/Asynchronous Thank you very much for this code! This seems very useful and promising.
However, with most messages I get an error executing that code: Exception: TypeError: archiveFolder is null In other words, the execution of the line to initialize the variable archiveFolder seems to return null. However, there is an archive folder, as I can click on the "Archive" button and the message goes to my archive folder (in this case, Archives -> ARCHIVED - Local Folders). Regarding the other question, yes I was querying about how to make an asynchronous call synchronous. I looked a the URL that you provided and I concluded that the trick was to use await. However, I tried with: await archiver.archiveMessages(gFolderDisplay.selectedMessages); but this leads to an error: Exception: SyntaxError: await is only valid in async functions and async generators Thanks a lot for any suggestion.
Try this:
Thank you very much. This avoids the previous error but a new one is shown in the console:
TypeError: archiveMsgHdr is null I see that probably the problem is that the archived folder retrieved is "mailbox://nobody@Local%20Folders/ARCHIVED" (this is the text shown in the console, but it should be "mailbox-message://nobody@Local%20Folders/ARCHIVED/2020/2020-02". Any further ideas? I still also have the problem of how to make the main code wait until the archiving of the message has completed (end of the execution of archiver.oncomplete). If the msgHdr is null, then I guess the message isn't in the folder.
If the nsMsgFolderFlags.Archive flag doesn't work, then use the folder url.
I'm only a hobbyist. Ask someone else about asynchronous programming. It's too hard for me to explain.
8 posts
• Page 1 of 1
Return to Extension Development Who is onlineUsers browsing this forum: No registered users and 2 guests |
![]() |