Topic RSS
6:19 am
I'm trying to create a Trickler filter that selects messages that are older than a certain time according to how I tag them, for example if I tag with Day and 3 then when the filter runs and a message is 3 days old it selects the message which I can manipulate. I'm using javascript search filter so I don't need to create a separate filter for every case of 1..7 days and 1..4 weeks I plan to use.
My javascript is rusty as I'm a .net developer, can anyone look at this code below and see where I went wrong, The result of the filter is that it always evaluates true selecting all messages
let tags = message.getStringProperty('keywords');
let now = new Date();
let mdate = message.getProperty("Date");
let diff = (now.getTime() – mdate.getTime()) ;
diff = Math.floor( diff / (1000 * 60 * 60 * 24) );
((/Day/.test(tags) && (/1/.test(tags) && diff > 1 ) || ((/Day/.test(tags) && (/2/.test(tags) && diff > 2 ) || ((/Day/.test(tags) && (/3/.test(tags) && diff > 3 );
It's exciting to see someone trying to use the javascript search term, as this is a new feature.
The issue with your js is not obvious to me, but let me give you some pointers on how to debug this, and other issues.
I debug javascript with lots of prints. There are two easy ways to do this. First, this statement:
Cu.reportError('some text');
will put a line of text on the Error Console, which you can view from the Tools menu. Second, this statement:
dump('some text\n');
will put a line of text on the DOS console. But to see the DOS console, you will need to start thunderbird with the -console option.
Then, some cautions. The 'keywords' string is a list of space-separated tag keys. For tag numbers greater than 5, the key is the same as the original name that you gave the tag (not sure of capitalization though) and it does not change if you rename the tag. But for tags 1 – 5, for legacy reasons the tag keys are "$label1" – "$label5". That means that your keywords will contain "1" if it is assigned the first tag, which defaults to "Important". (Another issue with "keywords" is that it may contain deleted tag keys, and under some circumstances IMAP flags like "Junk" and "NonJunk" get added.) So normal practice in production code would be to cleanup these issues, and there are various examples I could point you to to do this. It takes about 10 lines of js. But if this is just for private use, you could work around this fairly simply. For example, make sure that your new tags are number 6 or greater, and give them slightly more complex names, like '1Day" and '2Days' that would avoid collision with '$label1' in the regex search.
Most Users Ever Online: 18
Currently Online:
7 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Member Stats:
Guest Posters: 130
Members: 565
Moderators: 1
Admins: 1
Forum Stats:
Groups: 1
Forums: 7
Topics: 231
Posts: 802
Newest Members: Matteo, p.dobrogost, gaute, Mythobeast, terry, Livraria Notre Dame
Moderators: rkent (323)
Administrators: rkent (323)
Log In
Register
Members
Home
Add Reply
Add Topic
Quote
Offline

Recent Comments