Looking for a small script

This forum is for discussing Mailtraq's Scripting features. Get help with Mailtraq scripts, templates and external ActiveX scripting.

Looking for a small script

Postby Gbn » Mon Oct 30th, 2006 6:46am

Gd All,

have checked a lot of items / scripting items etc, but cannot find an item which I need.

We use a company wide spam box, where all caught spam is delivered.
a couple of external POP3 accounts are routed in this spam box too.
We use Black lists, which when denied end up in the spam box.
(Yes, we do not want to miss any message......)

We see a lot of spam with incorrect email addresses in the TO: / CC: lines, which is not strange since a lot of emails are collected in this spam box.
I would like some script, which can check if the TO: or CC: used address is a valid address on our mailtraq server.
If it is, the mail is allowed to the spam folder, if it is not dev/nul is a nice place to store the message.

Any idea's on this subject ?

Gerard
Gbn
 
Posts: 7
Joined: Fri Sep 30th, 2005 5:51am

Re: Looking for a small script

Postby Martin Clayton » Wed Nov 08th, 2006 1:43pm

Hi Gerard,

Gbn wrote:I would like some script, which can check if the TO: or CC: used address is a valid address on our mailtraq server.

The following script only tests for addresses with a valid local domain. It should be run on a test mailslot first as it permanently deletes non-locals.

Code: Select all
<@LANGUAGE=Javascript@>
<%

// hdrs-not-local.mtq
// Delete messages without an address with a local domain in specified headers

  var mailslot_name = "test";
  var header_list = "To,Cc";

//-------------------------

  var mailslot = Config.GetMailslot(mailslot_name);

  // count (max) number of slot messages for QueryMessages()
  var MsgCount = 0;
  var FolderInfoArray = new String(mailslot.QueryFolders()).split(",");
  for(var i = 2; i < FolderInfoArray.length; i += 6) { 
    MsgCount += (+FolderInfoArray[i]);
  }

  // create QueryMessages() template, "|" separates id from field(s') contents
  var template = "$id|";
  var HeaderFieldArray = new String(header_list).split(",");
  for(var i = 0; i < HeaderFieldArray.length; i++) {
    template += ", $header(" + HeaderFieldArray[i] + ")";
  }

  var NonLocal = new Array();
  var querylist = mailslot.QueryMessages(0, 0, MsgCount, template, "", "", "\t").split("\t");

  // loop through all message results
  for(var i = 0; i < querylist.length; i++) {
    var mid = querylist[i].replace(/^(.*?)\|.*/, "$1");
    var HdrAddressList = Toolkit.ExtractEmailAddresses(querylist[i]);
    var HdrAddressArray = new String(HdrAddressList).split(",");
    var HdrAddDomain = "";
    var LocalDomain = false;
    // loop through all header addresses
    for (var j = 0; j < HdrAddressArray.length && !LocalDomain; j++) {
      HdrAddDomain = Toolkit.DomainOfEmail(HdrAddressArray[j]);
      if(HdrAddDomain != '' && SameAddress("x", "x@" + HdrAddDomain))
        LocalDomain = true;
    }
    if(!LocalDomain)
      NonLocal.push(mid);
  }
 
  // purge
  if(NonLocal.length > 0)
    mailslot.DeleteMessage(NonLocal.join(","));
 
%>


Some notes:
  • The JS script reference suggests that SameAddress() resolves mailslot aliases but I couldn't get it to work. Above, it's only used to resolve domain aliases.
  • As far as I can see, there's no javascript equivalent of mtq's proprietary language IsUserLocal(). The functionality would be really useful if it takes account of the aliases file, rewriting, mailslot aliases, etc.
  • A mailslot.Aliases property would be useful (although it's not too much work to read mailslot config files directly).

To stop messages at the gate you could use mailslot filters using something like To: *@domain*, To: *@domain-alias1*, Cc: *@domain, etc.

Cheers, Martin
User avatar
Martin Clayton
Expert User
 
Posts: 529
Joined: Sat Jan 15th, 2005 8:20am
Location: London, UK


Return to Mailtraq Scripting

Who is online

Users browsing this forum: Bing [Bot] and 2 guests

cron