Auto-response scripts manipulating attachments?

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

Auto-response scripts manipulating attachments?

Postby ct » Mon Oct 31st, 2005 1:41pm

Not sure if this is possible, but after resarching I have not been able to find a way to have an auto-repsonse (triggered from an inbound message), automatically save any type of attachment it receives to a directory or location.

Is this level of manipulation possible?


Thanks
ct
 

Re: Auto-response scripts manipulating attachments?

Postby Elric Pedder » Mon Nov 07th, 2005 5:54pm

ct wrote:Not sure if this is possible, but after resarching I have not been able to find a way to have an auto-repsonse (triggered from an inbound message), automatically save any type of attachment it receives to a directory or location.

Is this level of manipulation possible?


It is possible, but it isn't simple (yet). You cannot do this in an auto-responder though as the tools necessary can only be used on messages already in a mailslot.

What you could do is have a script that extracts the attachments of every message in a mailslot, save them to disk and erase the source message. Then, you can have that script scheduled to run periodically.

The script would look something like this :-

Code: Select all
<@LANGUAGE=Javascript@>
<%
  var mailslot = Config.GetMailslot("MAILSLOT_NAME");
  var msglist = mailslot.QueryMessages(0, 0, 100, "$id", "", "", "\t").split("\t");
  for (var i = 0; i < msglist.length; i++) {
    var msg = Session.LoadMailslotMessage("msg", "MAILSLOT_NAME", msglist[i], false, false);
    var attachments = msg.GetAttachmentList();
    for (var j = 0; j < attachments.length; j++) {
      var att = msg.GetObject(attachments[j]);
      if (att.Filename != "") {
        att.SaveToFile("ATTACHMENT_PATH\\" + att.Filename);
      }
    }
    mailslot.DeleteMessage(msglist[i]);
  }
%>


I haven't tested this yet, but if it looks like the kind of thing you are after and you need more instruction I can assist further.

Best regards,
- Elric
Mailtraq Development and Escalation Support
Novitraq Incorporated
User avatar
Elric Pedder
Mailtraq Escalation Support
 
Posts: 2675
Joined: Tue Nov 23rd, 2004 1:16pm
Location: Montreal, Canada

Re: Auto-response scripts manipulating attachments?

Postby Martin Clayton » Wed Jan 11th, 2006 6:31am

Hi Elric & Scripters,
Elric Pedder wrote:
Code: Select all
<@LANGUAGE=Javascript@>
<%
  var mailslot = Config.GetMailslot("MAILSLOT_NAME");
  var msglist = mailslot.QueryMessages(0, 0, 100, "$id", "", "", "\t").split("\t");
  for (var i = 0; i < msglist.length; i++) {
    var msg = Session.LoadMailslotMessage("msg", "MAILSLOT_NAME", msglist[i], false, false);
    var attachments = msg.GetAttachmentList();
    for (var j = 0; j < attachments.length; j++) {
      var att = msg.GetObject(attachments[j]);
      if (att.Filename != "") {
        att.SaveToFile("ATTACHMENT_PATH\\" + att.Filename);
      }
    }
    mailslot.DeleteMessage(msglist[i]);
  }
%>


The above seems Ok under *.mtq javascript and ActiveX - until msg = Session. where "Session" is seen as undefined. Is this sort of mailslot/message manipulation only available to HTML sessions?

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

Re: Auto-response scripts manipulating attachments?

Postby Elric Pedder » Wed Jan 18th, 2006 1:00pm

Hi Martin,

Apologies for taking so long to get back to you.

Session is indeed valid in these scripts. It is created just for the duration of the script execution, and you can have sessions shared across scripts by giving them a unique identifier and recalling them. I think that is discussed in the docs.

I ran the script and if you leave the "MAILSLOT_NAME" in that line (i.e. refer to a non-existent mailslot) you will get the same error, so I suspect that is what happened. Otherwise, the script does run.

That said, it doesn't work. You need to change

Code: Select all
var attachments = msg.GetAttachmentList();
to
Code: Select all
var attachments = msg.GetAttachmentList().split(',');


Does that work for you?

Best regards,
- Elric
Mailtraq Development and Escalation Support
Novitraq Incorporated
User avatar
Elric Pedder
Mailtraq Escalation Support
 
Posts: 2675
Joined: Tue Nov 23rd, 2004 1:16pm
Location: Montreal, Canada

Re: Auto-response scripts manipulating attachments?

Postby Martin Clayton » Wed Jan 18th, 2006 2:31pm

Elric Pedder wrote:Apologies for taking so long to get back to you.

No problem, thanks.

Session is indeed valid in these scripts. It is created just for the duration of the script execution, and you can have sessions shared across scripts by giving them a unique identifier and recalling them. I think that is discussed in the docs.

Ah, that's great. Server.Session is shown as being of type HTMLSession and with the cookie & page talk, it looked like exclusive HTML territory.

I ran the script and if you leave the "MAILSLOT_NAME" in that line (i.e. refer to a non-existent mailslot) you will get the same error, so I suspect that is what happened.

Sorry, I should have quoted what I tried but the problem was something else ... I was getting a nice list of filenames and then a Session undefined error. I was running with wscript because I didn't know how to debug/echo from within *.mtq javascript. (I still don't).

Code: Select all
var attachments = msg.GetAttachmentList().split(',');

Does that work for you?


It sure does! :)

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: No registered users and 2 guests

cron