filters.js
file. This file contains the JavaScript functions that perform the mail filtering. These functions can use all features of client-side JavaScript. The location of this file depends on your platform, as shown in the following table.
Platform |
File location
where \Program Files\Communicator\Users\<username>\Mail\filters.js
| |
---|
// filters.js file.
function MomFilter(message) {
if (message.from.indexOf("my_mom@mothers.net") != -1) {
message.priority = "High";
message.folder = "mailbox:FromMom";
}
else if (message.subject.indexOf("my_sister@sisters.net") != -1) {
message.trash();
}
}
NOTE:
There is no way to specify an IMAP folder using the mailbox:
syntax. So, if
you refile things using IMAP, they all end up on your local machine.
Once you've written the JavaScript filter function, you add a reference to the filter in your mail rules file. The location of your rules file is also platform dependent, as shown in the following table.
Platform |
File location
$(HOME)/.netscape/mailrule
Where
|
| |
---|
name="filterName"Where:
enabled="yes"
type="2"
scriptName="scriptName"
name="filterName" | |
enabled="yes" |
Says to use this filter. To turn off the filter, change this line to |
type="2" | |
scriptName="scriptName" |
name="Filter for Mom"You can add multiple groups of the above lines to your rules file to add multiple filters. They are executed in the order listed in the file until one of them performs an action on the message (sets a property or calls a method). If you don't already have a mail rule file, you'll need to add the following two lines at the top (before any filter references):
enabled="yes"
type="2"
scriptName="MomFilter"
version="6"
logging="no"
type
line. With mail filters, you use type="2"
. For news filters, you use type="8"
.
Method |
Description
killThread()
| watchThread()
| trash()
| |
---|
Property |
Description
folder
| read
| priority
| |
---|
folder
property of the message object. You can use either a full path or the mailbox:
URL syntax to specify the destination.
The priority property can be set using either an integer or a string. The possible values are:
message.subject
and the CC list as message.cc
. Headers with hyphens in their names (such as Resent-from
) cannot be retrieved with the dot syntax. Instead, retrieve them using the array syntax for a property value (such as message["Resent-from"]
).
Method |
Description
killThread()
| watchThread()
| |
---|
Property |
Description
group
| read
| sender
| subject
| |
---|
field | Which message field to use to match against (such as From or Resent-From). |
probe | |
folder | |
trash | |
priority |
ApplyFilters
for a message, it searches for a match in the MyFilters
array. If it finds one, the function either puts the message in the trash, moves it to a new folder, or changes its priority.
var MyFilters = [
{field:"From", probe:"cltbld@netscape.com", folder:"mailbox:Client Build"},
{field:"From", probe:"scopus@netscape.com", folder:"mailbox:Scopus"},
{field:"Resent-From", probe:"bonsai-hook@warp.mcom.com", trash:true"},
{field:"Resent-From", probe:"xheads@netscape.com", folder:"mailbox:X Heads"},
{field:"Resent-From", probe:"layers@netscape.com", priority:"High"}
];
// Initialize by compiling a regular expression for each filter
for (var i = 0; i < MyFilters.length; i++) {
var f = MyFilters[i];
f.regexp = new RegExp("^" + f.field + " *:.*" + f.probe, "i");
}
function ApplyFilters(message)
{
trace("Applying mail filters");
for (var i = 0; i < MyFilters.length; i++) {
var f = MyFilters[i];
if (f.regexp.test()) {
if (f.trash) {
message.trash();
} else if (f.folder) {
message.folder = f.folder;
} else {
message.priority = f.priority;
continue;
}
break;
}
}
}
Last Updated: 05/27/99 21:21:48
Any sample code included above is provided for your use on an "AS IS" basis, under the Netscape License Agreement - Terms of Use