GNU Mailutils Manual (split by node):   Section:   Chapter:FastBack: Programs   Up: MDA Scripting   FastForward: Libraries   Contents: Table of ContentsIndex: Function Index Python MDA Filters

The file name of the Python mail filter is specified using ‘script’ configuration statement. For example, the following configuration statement:

script {
  pattern "~/";

instructs mda to use the file in the recipient home directory as a Python filter.

A simple example of a mail filter written in Python:

from mailutils import *
import maidag
import re

msg = message.Message (maidag.message)
hdr = msg.header

    if 'List-Post' in hdr and 'Received' in hdr \
       and hdr['Received'].find ('') != -1:

        # check envelope's sender address
        m = (r'([\w\-]+)-bounces\+([\w]+)=.*',
                       msg.envelope.get_sender ())
        if m:
            lbox = (1)
            user = (2)
            # open destination mailbox and append message
            dst = mailbox.MailboxDefault ('~/Mail/%s' % lbox)
            dst.append_message (msg)
            dst.close ()
            # set deleted flag so maidag will not deliver msg elsewhere
            msg.attribute.set_deleted ()
except Exception: