Closed Bug 1627604 Opened 5 years ago Closed 3 years ago

Need an API for listening to message add/update/remove events

Categories

(Thunderbird :: Add-Ons: Extensions API, enhancement)

enhancement
Not set
normal

Tracking

(thunderbird_esr78 wontfix)

RESOLVED FIXED
91 Branch
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

does this still exist? (post from 2011): notificationService.msgAdded

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: nobody → john
Target Milestone: --- → 91 Branch

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

Status: NEW → RESOLVED
Closed: 3 years ago
Resolution: --- → FIXED

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.

Status: RESOLVED → REOPENED
Resolution: FIXED → ---

Pushed by mkmelin@iki.fi:
https://hg.mozilla.org/comm-central/rev/bcbb5e1780e0
follow-up - Clean up listeners at shutdown. r=john.bieling

Status: REOPENED → RESOLVED
Closed: 3 years ago3 years ago
Resolution: --- → FIXED

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

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.

@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?

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.

... by using the regex for whitespace, the 'extra tags' disappear

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: