Need an API for listening to message add/update/remove events
Categories
(Thunderbird :: Add-Ons: Extensions API, enhancement)
Tracking
(thunderbird_esr78 wontfix)
Tracking | Status | |
---|---|---|
thunderbird_esr78 | --- | wontfix |
People
(Reporter: standard8, Assigned: TbSync)
References
Details
Attachments
(2 files)
Currently add-ons have no way to know if a particular message was added, modified or deleted.
This is useful to know for various message information display purposes, e.g. if a message is now marked as read, or if it has been removed, then the add-on would know to remove it.
we need folderlistener:
add/remove:
OnItemAdded(parentItem, item) {},
OnItemRemoved(parentItem, item) {},
for tags, we need a folderlistener with:
OnItemPropertyFlagChanged(item, property, oldFlag, newFlag) {
if (
property == "Keywords"
surprisingly (for me), oldFlag/newFlag does not indicate the keywords, but:
adding a keyword: oldFlag ==0, newFlag==1
removing a keyword: vice versa.
The listener also fires on msg/rightclick/tags etc., as expected.
Also, the listerner fires on keyword change with keyboard (like 1,2,3 to set tag), and not on S (star), as would be expected.
For other msg updates, probably need to use the other onItem...changed functions.
According to legacy code, care needs to be taken on what object to register the listener on (server, local storage etc.). Most universal seems to be (according to some comments in searchfox, but forgot where to find):
MailServices.mailSession.AddFolderListener(
folderListener,
Ci.nsIFolderListener.propertyFlagChanged
);
other Ci.nsIFolderListener...something...Changed
see https://searchfox.org/comm-esr78/source/mailnews/base/public/nsIFolderListener.idl
see also comments here and _folderlistener:
central/source/mailnews/db/gloda/modules/IndexMsg.jsm#2123
yes:
// message-specific functions
// single message for added, array for delete/move/copy
void notifyMsgAdded(in nsIMsgDBHdr aMsg);
void notifyMsgsClassified(in Array<nsIMsgDBHdr> aMsgs,
in boolean aJunkProcessed,
in boolean aTraitProcessed);
void notifyMsgsJunkStatusChanged(in Array<nsIMsgDBHdr> messages);
void notifyMsgsDeleted(in Array<nsIMsgDBHdr> aMsgs);
void notifyMsgsMoveCopyCompleted(in boolean aMove,
in Array<nsIMsgDBHdr> aSrcMsgs,
in nsIMsgFolder aDestFolder,
in Array<nsIMsgDBHdr> aDestMsgs);
/**
- Notify listeners that the msg key for a header has changed. Currently,
- this is used when we create a header for an offline imap move result,
- without knowing what the ultimate UID will be. When we download the
- headers for the new message, we replace the old "pseudo" header with
- a new header that has the correct UID/message key, by cloning the pseudo
- header, which maintains all the existing header attributes.
- @param aOldKey The fake UID. The header with this key has been removed
-
by the time this is called.
- @param aNewHdr The header that replaces the header with aOldKey.
*/
void notifyMsgKeyChanged(in nsMsgKey aOldKey, in nsIMsgDBHdr aNewHdr);
void notifyMsgUnincorporatedMoved(in nsIMsgFolder srcFolder, in nsIMsgDBHdr msg);
// folder specific functions
// single folders, all the time
void notifyFolderAdded(in nsIMsgFolder aFolder);
void notifyFolderDeleted(in nsIMsgFolder aFolder);
void notifyFolderMoveCopyCompleted(in boolean aMove,
in nsIMsgFolder aSrcFolder,
in nsIMsgFolder aDestFolder);
void notifyFolderRenamed(in nsIMsgFolder aOrigFolder,
in nsIMsgFolder aNewFolder);
void notifyFolderCompactStart(in nsIMsgFolder folder);
void notifyFolderCompactFinish(in nsIMsgFolder folder);
void notifyFolderReindexTriggered(in nsIMsgFolder folder);
Assignee | ||
Updated•3 years ago
|
Assignee | ||
Comment 5•3 years ago
|
||
Assignee | ||
Updated•3 years ago
|
Updated•3 years ago
|
Pushed by mkmelin@iki.fi:
https://hg.mozilla.org/comm-central/rev/58d779e4cc24
Add event listeners for messages being moved, copied, deleted, and modified. r=darktrojan
Comment 8•3 years ago
|
||
It turns out we DO need to clean this up at shutdown. The debug tests had a bunch of shutdown issues.
Plus removed a bunch of aArg-style variable names.
Updated•3 years ago
|
Assignee | ||
Updated•3 years ago
|
Pushed by mkmelin@iki.fi:
https://hg.mozilla.org/comm-central/rev/bcbb5e1780e0
follow-up - Clean up listeners at shutdown. r=john.bieling
Comment 10•3 years ago
|
||
for me, this tags.split(" ") : []; does not always work.
On removing tags by keyboard number key, sometimes extra spaces stay in the keywords string.
then, I get an array ["label2", "label3", "", "label4"], for example.
After looking on stackoverflow, I would use an regex for whitespace (multiple \s) in split
Comment 11•3 years ago
|
||
some more observations on the stringproperty keywords:
after changing tags by keyboard, labels can change their order in the prop (e.g. label1 suddenly at the end). Don't know whether that might be relevant for the code.
Assignee | ||
Comment 12•3 years ago
|
||
@klaus: The API is using tags.filter(MailServices.tags.isValidKey)
after the split and that removes any non-valid tag (including ""). Have you seen this API returning "" as a valid tag, or are you describing your own experience splitting tags in your own Experiment, but not this API in particular?
Comment 13•3 years ago
|
||
this was just meant as an information, it is not saying that anything might habe been implemented wrongly. I had a look at the code before posting but it felt too long to verify.
In the recent days, I have been doing 'a lot' with tags in an experiment and just noticed that the native handling of adding/removing tags sometimes feels peculiar. So it felt unexpected that the keyword string still has remnants of deleted keys (even if only " ") and splits into 4 tags if it is 3 in reality.
Comment 14•3 years ago
|
||
... by using the regex for whitespace, the 'extra tags' disappear
Description
•