Open digisyn opened 2 years ago
I have 70+ rules in Thunderbird. Every so often an email will be moved to a folder it does not belong to. Can the email, either separately or even at the bottom of the body include all the rules that modified or moved the message.
I'm thinking this is more of a diagnostic feature and the user should be able to turn it on or off.
I think the best way of finding out which filters were applied is built in: it's the "filter log" button on the message filters dialog. If you are wondering which filter may have moved mail to a specific folder, you can also use an advanced feature of quickFilters Pro: right-click the folder in folder tree and select "Find Filters" to quickly list all filters that move mail to this specific folder
Is this even doable given the way Thunderbird handles rules? Thank you for a great product and your time/attention to this.
The only thing I can imagine would be by adding an "x-" header (something like "x-filter-applied") as a new filter action. Or you could use a tag...
I'm
The only thing I can imagine would be by adding an "x-" header (something like "x-filter-applied") as a new filter action. Or you could use a tag...
I've been trying to do exactly this. I have an action that runs on incoming emails when the javascript criteria message.getStringProperty('X-first-folder-URI').length == 0
is satisfied:
/* console.log ("starting");
console.log (msgHdrs);
console.log("was",msgHdrs[0].getStringProperty("X-first-folder-URI").length); */
msgHdrs[0].setStringProperty("X-first-folder-URI", msgHdrs[0].folder.URI);
/* console.log("set");
console.log("is",msgHdrs[0].getStringProperty("X-first-folder-URI"));
console.log ("done"); */
I've also aded X-first-folder-URI to mailnews.customDBheaders, mailnews.customHeader, mail.compose.other.header, and mailnews.headers.extraExpandedHeaders, and added it to Tbird's built-in "customize..." option in the criteria header list.
By uncommenting the console.log lines, I can see the javascript is working as expected. But the custom x-header isn't written to the emails. Does msgHdrs not point to the original email? Is there a way to get it to save this so it stays with the emails? I can't use tags, I have too many folders and they change too frequently to set up a tag for each one.
I found the filterbutton add-on to be helpful: https://github.com/ChristophKaser/FilterButton
it attempts to indicate what filters apply to an email, even after it was moved.
I'm
The only thing I can imagine would be by adding an "x-" header (something like "x-filter-applied") as a new filter action. Or you could use a tag...
I've been trying to do exactly this. I have an action that runs on incoming emails when the javascript criteria
message.getStringProperty('X-first-folder-URI').length == 0
is satisfied:/* console.log ("starting"); console.log (msgHdrs); console.log("was",msgHdrs[0].getStringProperty("X-first-folder-URI").length); */ msgHdrs[0].setStringProperty("X-first-folder-URI", msgHdrs[0].folder.URI); /* console.log("set"); console.log("is",msgHdrs[0].getStringProperty("X-first-folder-URI")); console.log ("done"); */
I've also aded X-first-folder-URI to mailnews.customDBheaders, mailnews.customHeader, mail.compose.other.header, and mailnews.headers.extraExpandedHeaders, and added it to Tbird's built-in "customize..." option in the criteria header list.
By uncommenting the console.log lines, I can see the javascript is working as expected. But the custom x-header isn't written to the emails. Does msgHdrs not point to the original email? Is there a way to get it to save this so it stays with the emails? I can't use tags, I have too many folders and they change too frequently to set up a tag for each one.
I do not think it is possible.
I think the javascript message object is: https://udn.realityripple.com/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIMsgDBHdr
adding a header requires commit with: https://udn.realityripple.com/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIMsgFolder
asynchronous operation which I think is not possible in the context of the javascript filter action we receive.
I do not think it is possible.
I think the javascript message object is: https://udn.realityripple.com/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIMsgDBHdr
adding a header requires commit with: https://udn.realityripple.com/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIMsgFolder
asynchronous operation which I think is not possible in the context of the javascript filter action we receive.
We might be able to investigate this - actually there is a flag in filter actions that can make it asynchronous (not in filter conditions / search terms though). So if the action would be to add an "x-" header through script it may be possible but we might have to change the async flag somehow.
At the moment this is the javaScriptAction definition:
self.javascriptAction =
{
id: "filtaquilla@mesquilla.com#javascriptAction",
name: util.getBundleString("filtaquilla.javascriptAction.name"),
applyAction: function(msgHdrs, actionValue, copyListener, filterType, msgWindow) {
return eval(actionValue);
},
apply: function(aMsgHdrs, aActionValue, aListener, aType, aMsgWindow)
{
let msgHdrs = [];
for (var i = 0; i < aMsgHdrs.length; i++) {
msgHdrs.push (aMsgHdrs.queryElementAt(i, Ci.nsIMsgDBHdr));
}
this.applyAction(msgHdrs, aActionValue, aListener, aType, aMsgWindow);
},
isValidForType: function(type, scope) {return javascriptActionEnabled;},
validateActionValue: function(value, folder, type) { return null;},
allowDuplicates: true,
needsBody: false
};
I could add the "isAsync" property and make this configurable. Also I see that there is a "needsBody" attribute set to false, I could try to make this configurable through a global variables too and require the body to be downloaded for a javascript action?
PS: one of the main obstacles with the filtering services is that the UI is not conducive to add a lot of settings to a particular line in the filter definition - having global parameters for stuff like isAsync
/ needsBody
seems like a very low resolution way of addressing this problem, but I cannot think of another way at the moment. Unfortunately filters do not allow storing additional properties that are outside of the narrow filterCondition / filterAction definitions, and filters are still stored by the compiled layer which cannot be changed by any script.
We might be able to investigate this - actually there is a flag in filter actions that can make it asynchronous (not in filter conditions / search terms though). So if the action would be to add an "x-" header through script it may be possible but we might have to change the async flag somehow.
At the moment this is the javaScriptAction definition:
self.javascriptAction = { id: "filtaquilla@mesquilla.com#javascriptAction", name: util.getBundleString("filtaquilla.javascriptAction.name"), applyAction: function(msgHdrs, actionValue, copyListener, filterType, msgWindow) { return eval(actionValue); }, apply: function(aMsgHdrs, aActionValue, aListener, aType, aMsgWindow) { let msgHdrs = []; for (var i = 0; i < aMsgHdrs.length; i++) { msgHdrs.push (aMsgHdrs.queryElementAt(i, Ci.nsIMsgDBHdr)); } this.applyAction(msgHdrs, aActionValue, aListener, aType, aMsgWindow); }, isValidForType: function(type, scope) {return javascriptActionEnabled;}, validateActionValue: function(value, folder, type) { return null;}, allowDuplicates: true, needsBody: false };
I could add the "isAsync" property and make this configurable. Also I see that there is a "needsBody" attribute set to false, I could try to make this configurable through a global variables too and require the body to be downloaded for a javascript action?
create new filter action: expermental-JavaScriptActionWithAsyncAndBody
* add isAsync * needsBody attribute to true * this is my primary interest
I just need to find out a little more. there is a listener argument which I have seen used in encryption elsewhere in the Tb source code, and it might have 2 callbacks onStartCopy
and onStopCopy
(tb128) / respectively OnStartCopy
and OnStopCopy
in 115 and earlier. I need to find out what exactly happens here and whether I have to implement these and when they are being called. My intuition is that onStopCopy(idx)
might be called when the email has been successfully moved (?), that might be the correct point in time for executing the JavaScript and the hope is that the number (I have only seen it with hardcoded 0) will tell me which of the messages is ready for processing. This is all speculation at this stage, I would need a Thunderbird developer to find out whether (and how) this can be used in the way I described:
see: https://searchfox.org/comm-esr128/source/mail/extensions/openpgp/content/modules/filtersWrapper.sys.mjs#78 and https://searchfox.org/comm-esr128/source/mailnews/base/public/nsIMsgCopyServiceListener.idl from that interface I found:
/**
* Notify the observer that the message has started to be copied. This
* method is called only once, at the beginning of a message
* copyoperation.
*/
void onStartCopy();
/**
* Notify the observer that the message copied operation has completed.
* This method is called regardless of whether the the operation was
* successful.
* @param aStatus - indicate whether the operation was succeeded
*/
void onStopCopy(in nsresult aStatus);
My hope is that the aStatus==0 means that the message was moved successfully, and that then operating on headers and adding data there is safe. This is me guessing, as usual.
there is also this one, but I am not sure whether it applies to the case when the filter is moving messages:
/**
* Getting the file message message ID. This method is tailored
* specifically for nsIMsgCopyService::copyFileMessage() when saving
* Drafts/Templates. In order to work with imap server which doesn't
* support uidplus we have to use search command to retrieve the key of
* newly created message. Message ID generated by the compose guarantee its
* uniqueness.
* NOTE: The only real implementor is nsImapMailFolder::GetMessageId
*/
AUTF8String getMessageId();
I have 70+ rules in Thunderbird. Every so often an email will be moved to a folder it does not belong to. Can the email, either separately or even at the bottom of the body include all the rules that modified or moved the message.
I'm thinking this is more of a diagnostic feature and the user should be able to turn it on or off.
Is this even doable given the way Thunderbird handles rules? Thank you for a great product and your time/attention to this.
-- Larry Crouch larry@larkat.com