mvmf: mvmda/mfl hdrctls script example

mvmf: mvmda/mfl hdrctls script examples

If you want to do a lot of tests on header elements, it can be useful to describe the tests in a data file rather than in a script. Changing a data file is easier than modifying a script-- not to mention that it can be easier automated.

You can, of course, write your own MFL script to accomplish this. But here's an example. This data file format allows you to specify a number of different sorts of things to test in the email header, and a variety of actions to take when the test succeeds. Simple actions include keeping the message, discarding it, and filing into a folder; you can also include MFL fragments in the data file for more more complex actions.

We'll start out with the data file format and the MFL script that processes it, but also see the delivery script snippet below that makes use of these. Here are:

A sample hdrctls.txt file containing specifications of header elements and actions, and

A sample hdrctls.mfl file containing the mfl script code to process a hdrctls.cdb database created from the text file.

Using the above, your primary delivery script might include pieces like this:

@include <system-wide-stuff.mfl>
@include "hdrctls.mfl"		// pick up the hdrctls functions

// don't forget to require any capabilities used, e.g.:
sieve {
    require [ "fileinto", "copy", "reject" ];
    require [ "editheader", "vnd.mvmf.dnsbl" ];
    require [ "regex", "relational", "comparator-i;ascii-numeric" ];
    require "vacation";
}


    ...

sieve {
    // You may have some script elements like this first:
    if false {			// so that I can use elsif after this
	keep;
    }

    // Some random test of a subject string
    elsif header :contains "subject" "discard me" {
	discard;  stop;
    }

    // Check the hdrctls file and stop if something was processed.
    //  The hdrctls() function is defined in hdrctls.mfl included
    //  above.  Note the use of a "C" mode escape to call the function.
    elsif C { hdrctls(); } {
	stop;			// hdrctls() adds a "X-HDRCTLS-KEY" header.
    }

    // Nothing in the hdrctls data, continue on...
    elsif not exists "To" {
	addheader "X-Spam-Reason" "No TO line";
	fileinto "Spam/maybe";
    }

    // "implicit keep" will file anything not handled above.
}