Mailfromd Manual (split by node):   Section:   Chapter:FastBack: Library   Up: Library   FastForward: Using MFL Mode   Contents: Table of ContentsIndex: Concept Index

5.7 Header Modification Functions

There are two ways to modify message headers in a MFL script. First is to use header actions, described in Actions, and the second way is to use message modification functions. Compared with the actions, the functions offer a series of advantages. For example, using functions you can construct the name of the header to operate upon (e.g. by concatenating several arguments), something which is impossible when using actions. Moreover, apart from three basic operations (add, modify and remove), as supported by header actions, header functions allow to insert a new header into a particular place.

Built-in Function: void header_add (string name, string value [, number idx])

Adds a header ‘name: value’ to the message. If idx is given, it specifies a 0-based index in the header list where to insert this header.

If idx is not supplied, the header is appended to the end of the header list.

In contrast to the add action, this function allows to construct the header name using arbitrary MFL expressions.

Built-in Function: void header_insert (string name, string value, number idx)

This function is equivalent to header_add with three arguments, i.e. it inserts a header ‘name: ‘value’ at idxth header position in the message.

Built-in Function: void header_delete (string name [, number index])

Delete header name from the envelope. If index is given, delete indexth instance of the header name.

Notice the differences between this function and the delete action:

  1. It allows to construct the header name, whereas delete requires it to be a literal string.
  2. Optional index argument allows to select a particular header instance to delete.
Built-in Function: void header_replace (string name, string value [, number index])

Replace the value of the header name with value. If index is given, replace indexth instance of header name.

Notice the differences between this function and the replace action:

  1. It allows to construct the header name, whereas replace requires it to be a literal string.
  2. Optional index argument allows to select a particular header instance to replace.
Built-in Function: void header_delete_nth (number n)

Deletes nth header. Headers are numbered from 1.

Built-in Function: void header_replace_nth (number n, string name, string value)

Replaces nth header with ‘name: value’.

Library Function: void header_rename (string name, string newname[, number idx])

Defined in the module header_rename.mf.
Available only in the ‘eom’ handler.

Renames the idxth instance of header name to newname. If idx is not given, assumes 1.

The example below renames ‘Subject’ header to ‘X-Old-Subject’:

require 'header_rename'

prog eom
do
  header_rename("Subject", "X-Old-Subject")
done
Library Function: void header_prefix_all (string name [, string prefix])

Defined in the module header_rename.mf.
Available only in the ‘eom’ handler.

If prefix is given, rename all headers named name to ‘prefix-name’. Otherwise, remove all such headers.

Library Function: void header_prefix_pattern (string pattern, string prefix)

Defined in the module header_rename.mf.
Available only in the ‘eom’ handler.

If prefix is given, rename all headers whose names match pattern (in the sense of fnmatch, see fnmatches) to ‘prefix-name’. Otherwise, remove them.

For example, to prefix all headers whose names begin with ‘X-Spamd-’ with an additional ‘X-’:

require 'header_rename'

prog eom
do
  header_prefix_pattern("X-Spamd-*", "X-")
done

Mailfromd Manual (split by node):   Section:   Chapter:FastBack: Library   Up: Library   FastForward: Using MFL Mode   Contents: Table of ContentsIndex: Concept Index