news2mail gateway headers

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

news2mail gateway headers

Postby Martin Clayton » Sat Jun 21st, 2008 1:27pm

This script can be used to tidy up messages travelling through news2mail gateways. It adds a Received header and deletes Path, Lines & Newsgroups. Trigger on Outbound Mail, filter as appropriate, e.g., Newsgroups=local.* or (Any) 'To'=gateway-destination.

Code: Select all
<@LANGUAGE=JavaScript@>
<%
/* n2m-gate.mtq
   Outbound mail handling for news2mail gateway messages
   - Headers; Add Received & drop unwanted
*/

function SoftwareVersion() {
  var mtq;
  try {
      mtq = Server.Software + "/" + Server.Version;
  }  catch ( e )  {
      mtq = "Mailtraq/[prior to 2.7.1.1942]";
  }
  return mtq;
}

  var hdr_drop_list = "Path,Lines,Newsgroups".split(",");

  var mid = Request.GetHeader("Message-ID");
  var id = mid.replace(/<(.*?)@.*/, "$1");
  var lhost = Config.LocalHost;
  var mtq = SoftwareVersion();
  var timestamp = Toolkit.MessageTimestamp;
  var rcpt0 = Request.Recipients.Get(0);
  var hdr_rec = "Received: from (localhost [127.0.0.1]) by " + lhost  + "\r\n" +
                "          via news2mail gateway (" + mtq + ") id " + id + "\r\n" +
                "          for " + rcpt0 + "; " + timestamp;
  // prepend first header line
  var hdr_line_1 = Request.Headers.Get(0);
  Request.Headers.Set(0, hdr_rec + "\r\n" + hdr_line_1);

  // drop unwanted headers
  var hdr_unwanted = '';
  for (var i=0; i < hdr_drop_list.length; i++) {
    if (hdr_unwanted = hdr_drop_list[i]) {
      Request.SetHeader(hdr_unwanted, '');
      Request.Headers.Remove(hdr_unwanted + ": ");   
    }
  }

%>
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: No registered users and 1 guest

cron