make applyFiltersToFolders() take a filterType argument
Categories
(MailNews Core :: Filters, task)
Tracking
(Not tracked)
People
(Reporter: aceman, Assigned: aceman)
References
Details
In function MsgApplyFilters() (https://searchfox.org/comm-central/rev/68306e54cddea95b96f572cae989d3a21afa1daf/mail/base/content/mailWindowOverlay.js#2047), we have this code:
function MsgApplyFilters() {
let preselectedFolder = GetFirstSelectedMsgFolder();
let selectedFolders = Cc["@mozilla.org/array;1"]
.createInstance(Ci.nsIMutableArray);
selectedFolders.appendElement(preselectedFolder);
let curFilterList = preselectedFolder.getFilterList(msgWindow);
// create a new filter list and copy over the enabled filters to it.
// We do this instead of having the filter after the fact code ignore
// disabled filters because the Filter Dialog filter after the fact
// code would have to clone filters to allow disabled filters to run,
// and we don't support cloning filters currently.
let tempFilterList = MailServices.filters.getTempFilterList(preselectedFolder);
let numFilters = curFilterList.filterCount;
// make sure the temp filter list uses the same log stream
tempFilterList.logStream = curFilterList.logStream;
tempFilterList.loggingEnabled = curFilterList.loggingEnabled;
let newFilterIndex = 0;
for (let i = 0; i < numFilters; i++) {
let curFilter = curFilterList.getFilterAt(i);
// only add enabled, UI visible filters that are in the manual context
if (curFilter.enabled && !curFilter.temporary &&
(curFilter.filterType & Ci.nsMsgFilterType.Manual)) {
tempFilterList.insertFilterAt(newFilterIndex, curFilter);
newFilterIndex++;
}
}
MailServices.filters.applyFiltersToFolders(tempFilterList, selectedFolders, msgWindow);
}
Thus, we manually construct the filter list in JS, searching for enabled filters of the needed type (here Manual).
This is ugly and worse, in the filter logging from bug 697522 we do not know, why filtering was started (we just know it was a local run on existing messages) as nsMsgFilterService::ApplyFiltersToFolders() is executed.
This will become worse with bug 864187 where again filters will run locally and the Manual and Periodic "triggers" will be hard to distinguish. The patch has to use similar code as MsgApplyFilters() above.
Compare to
nsMsgApplyFiltersToMessages::nsMsgApplyFiltersToMessages(nsIMsgWindow *aMsgWindow,
nsIMsgFilterList *aFilterList,
nsIArray *aFolderList, nsIArray *aMsgHdrList,
nsMsgFilterTypeType aFilterType,
nsIMsgOperationListener *aCallback);)
which does take a filterType and does selecting the right type (and enabled) filters automatically.
It should be possible to make nsMsgFilterService::ApplyFiltersToFolders() honor a filterType argument and solve the use case in Filter list dialog (where we want to run even disabled filters, mentioned in the comment) in a cleaner way.
Note to myself:
The comment at https://searchfox.org/comm-central/rev/5a670c59f9004ef9be4874cfbfe57ec2ef3b260f/mailnews/base/search/src/nsMsgFilterService.cpp#729 may be affected by this bug and we may want to disable the filter there.
Comment hidden (off-topic) |
Comment hidden (off-topic) |
Updated•2 years ago
|
Description
•