Forum

Or log in with
 
Current User: Guest Login Register
Please consider registering


Register? | Lost Your Password?

Javascript help on filter to create a tickler filter

Reply to Post Add a New Topic
UserPost

6:19 am
December 16, 2009


Jonathan Garrett

Guest

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 );

8:00 am
December 16, 2009


rkent

Admin

posts 279

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.

Reply to Post

Reply to Topic:
Javascript help on filter to create a tickler filter

Guest Name (Required):

Guest Email (Required):

NOTE: New Posts are subject to administrator approval before being displayed

Smileys
Confused Cool Cry Embarassed Frown Kiss Laugh Smile Surprised Wink Yell
Post New Reply

Guest URL (required)

Math Required!
What is the sum of:
10 + 9
   


 
Share