Welcome to Islandnet.com  
Locally owned and operated since 1993  
Live Help
LOG IN:  Username:    Password:    

PEP Documentation

Return to the help index

Pages: QuickstartActionsHeadersTestsCommandsAttachment HandlingReply FilesMailing ListsChild AccountsDNS BlocklistsSpamAssassinChallengesM-ScriptGlossarySpam FAQSMTP TutorialPEP Quick SetupPEP WizardPEP Editor

Launching M-Script Programs (Advanced)

This page provides more detailed information about using PEP's "exec" feature. It is assumed that you know the basics about creating a mailrule file and constructing rules. It is also expected that you're familiar with creating and using M-Script programs.

This page does not attempt to teach you how to write M-Script programs. For that, please visit http://www.islandnet.com/mscript/.

What is an "M-Script Program"?

M-Script is a programming language that was originally designed for writing CGI applications for web pages, but now it can also be used to write programs that run from within PEP. M-Script is an easy programming language to learn: it's similar to BASIC or dBase programming.

Why?

There are many examples of why you might want to launch a program upon reception of an e-mail message. You could create a program that generates a web archive of certain mailing list messages for example. Or you might use this to process e-mail based product orders.

How does it work?

To launch an M-Script program from within PEP you must do two things. First you need to write your M-Script program, then you need to add a rule that causes it to run.

The rule is the easy part. Here's a sample PEP rule that launches (executes) an M-Script program called "archiver.ms2":

exec if subject contains "[Llamas]" "archiver"

The program itself must have a ".ms2" extension and must be located in your "ms2" directory, as per the M-Script documentation.

In the example above, we launch the M-Script program without passing the message itself to the program. The program will run, but it has no way of accessing the headers or the body of the message. Depending on what the program does, this may or may not be what you want.

If you want your program to have access to the message, you need to specify an additional parameter in your rule. This is the name of a file to which a copy of the message will be saved prior to launching your program:

exec if subject contains "[Llamas]" "archiver" "temp/message.txt"

If your program exits with a value of zero, PEP halts without delivering your message. This makes it effectively the same a s DELETE rule. If the program exits with a non-zero value, PEP continues processing the rest of your mailrule file.

NOTE:

  • It is not a good idea to use a fixed filename because if two messages come in simultaneously one will clobber the other. Use the PEP_ID value to form part of the filename: temp/{PEP_ID}.txt

  • The saved message will not be deleted after your program halts, so it's up to you to do this insude your program.

  • Your program should always exit with an explicit return value of either zero or one. If it doesn't the value is undefined and you may get unexpected results.

Environment Variables

Prior to launching your M-Script program, PEP defines the following environment variables which you can read from within your program with the getenv() function:

PEP_ID
This is a string that is guaranteed to be unique for each message PEP processes. It is usually used as the filename for passing that message to the program.

PEP_IP
This is the IP address of the machine that passed the message to our mail server/

PEP_RULE
This is a copy of the rule that caused the program to launch.

PEP_LINES
This a number that indicates how many lines long the message is.

PEP_BYTES
This is a number that indicates how large the message is in bytes.

PEP_TOCOUNT
This is a number that indicates how many addresses there are in the To: header of the message.

PEP_CCCOUNT
This is a number that indicates how many addresses there are in the Cc: header of the message.

An Example

For this example we simply want to count messages from our Visual Basic mailing list that happend to include the string "[VBS]" in every subject header. The count will be stored in the file "vbs.count" in our root directory:

We start with a rule like the following:

exec if subject contains "[VBS]" "counter"

Since we're simply counting occurances of such messages, we don't need to pass the actual messages to the program.

Next we create the file "counter.ms2" in our "ms2" directory. It would look something like this:

if exists( "vbs.count" )
   in = open( "vbs.count", "r+" )
else
   in = open( "vbs.count, "w" )
endif
if in
   while !lockf( in )
   endif
   count = read( in ) + 1
   rewind( in )
   write( in, count, "\n" )
   close( in )
endif
return 1

And that's it. Every time we get a message with "[VBS]" in the subject, the program runs and adds 1 to the value in the "vbs.count" file.

Note the last line which returns a value of one to PEP. This will cause PEP to continue testing the message against your mailrule file. Unless a subsequent rule deletes it, it will be delivered to your mailbox.



Page generation time: 0.11 seconds