RealRaven2000 / quickFilters

Thunderbird Add-on: quickFilters
http://quickfilters.quickfolders.org/
Other
46 stars 11 forks source link

Mails previously moved to folder are not automatically filtered. #230

Open sachaweb opened 5 months ago

sachaweb commented 5 months ago

I keep running into mails that I have to move several times to the same folder. So these mails keep just going to the inbox rather than the folder that I assigned them to in the past.

Quickfilters is enabled to start with TB. I did deactivate popping the window open when moving a mail, because I find it quicker this way.

Also, it would be nice to have a non-intrusive confirmation when a filter has been created, not requiring user intervention. That would help feel sure that a filter was made.

RealRaven2000 commented 5 months ago

Quickfilters is enabled to start with TB. I did deactivate popping the window open when moving a mail, because I find it quicker this way.

Not sure what the first sentence means, I guess you mean the assistant. This means that you create new filters every time you move a mail manually. If you move to a folder that already has a filter that moves mail to it, it should display the "merge filter" dialog. In the other case you get a choice on which template to use. I guess that's the one click you have disabled? Maybe post a screenshot of your settings. I highly recommend activating these 2 options in any case:

image

because the editor makes sure that the filter does what you want (and if you merge new recipients with an existing filter, you can check that the operator "match any of the following" is enabled). Displaying the filter list afterwards makes sure the filter is actually stored (there is no API for storing a filter, I guess if you leave out this step you might have lost the filter after creating it?)

The filters will do their work independently of whether quickFilters is installed (it's a core feature of Thunderbird).

Also, it would be nice to have a non-intrusive confirmation when a filter has been created, not requiring user intervention. That would help feel sure that a filter was made.

That was the whole point of popping up the filters list. I am still not sure whether there is a problem with disabling all the UI for actually persisting the filter. There is no filter.save() method that forces the filters to be persisted in the Thunderbird owned msgFilterRules.dat. The essential steps (from quickFilters.Worker.createQuickFilter() ), in an extremely minimized nutshell:

filtersList = sourceFolder.getEditableFilterList(msgWindow)
this.buildFilter(sourceFolder, targetFolder, messageList, messageDb, filterAction, matchingFilters, filtersList, mergeFilterIndex, emailAddress, ccAddress, bccAddress, filterActionExt)

...

// line 808.
 buildFilter: async function (sourceFolder, targetFolder, messageList, messageDb, filterAction, matchingFilters, filtersList, mergeFilterIndex, emailAddress, ccAddress, bccAddress, filterActionExt) { 

...
    if (mergeFilterIndex>=0) {
      targetFilter = matchingFilters[mergeFilterIndex];
      isMerge = true;
    }
    else {
      targetFilter = filtersList.createFilter(folderName);
    }

     searchTerm = createTerm(targetFilter, typeAttrib.Keywords, typeOperator.Contains, msgKeyArray[i]);
     addTerm(targetFilter, searchTerm);

    theAction = targetFilter.createAction();
    targetFilter.appendAction(theAction);

    if (!isMerge) {
      targetFilter.enabled = true;
      filtersList.insertFilterAt(0, targetFilter);
    }

   // controls whether the filters list is shown after creation:
    if (!showList) {
        // put filter in alphabetic order [Bug 26653]
        if (isAlpha) {
          filtersList.removeFilterAt(0);
          let numFilters = filtersList.filterCount;
          for (let idx=0; idx<numFilters; idx++) { 
            if (targetFilter.filterName.toLocaleLowerCase() < filtersList.getFilterAt(idx).filterName.toLocaleLowerCase()) {
              filtersList.insertFilterAt(idx, targetFilter); // we still may have to force storing the list!
              break;
            }
          }
        } 
// line 1623 - yes the function is THAT long, because it contains a number of helper functions for adding / merging search terms and actions

So basically I have to rely on the function filtersList.insertFilterAt(..) to persist the information in Thunderbird's filters (which they store in msgFilterrules.dat at some stage - I do not know when)

So this is a just a technical summary what I steps quickFilters is executing when a new filter is generated (or one is merged).

RealRaven2000 commented 5 months ago

Another thought - the operation of creating the filter will run asynchronously - it is not instigated directly after you move your email. On IMAP, the server decides when it moves the mail and THunderbird decides when it downloads the new email, so it can take a couple of seconds or longer until quickFilters is even notified; then it has to wait for the message database to stabilize and allow access to the message header before it can even evaluate the emails headers such as the sender. If you move more emails to the same folder in the meantime, you might trigger the assistant multiple times or the data from the successive emails may not be detected by the assistant for this round. That's another reason why it is a good idea to at least enable the filter editor to see the filter and click OK.