diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-03-13 13:23:25 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-03-13 13:23:25 +0200 |
commit | 07ca8622ff6226c45b4ac321b38e5f6918f11603 (patch) | |
tree | 7041f2161e5503f5fe33e685b2e64a4895288e5c | |
parent | 31949407692d3176e88bdcb6b08f78b598f20b3c (diff) | |
download | mailfromd-07ca8622ff6226c45b4ac321b38e5f6918f11603.tar.gz mailfromd-07ca8622ff6226c45b4ac321b38e5f6918f11603.tar.bz2 |
New function header_rename_pattern
* NEWS: Update.
* mflib/header_rename.mf4: New function header_rename_pattern.
* doc/functions.texi: Document changes to message_header_count.
Document header_rename_pattern.
-rw-r--r-- | NEWS | 8 | ||||
-rw-r--r-- | doc/functions.texi | 33 | ||||
-rw-r--r-- | mflib/header_rename.mf4 | 21 |
3 files changed, 58 insertions, 4 deletions
@@ -53,6 +53,14 @@ actually an alias to the `portprobe' function. If your filter uses These functions have been moved to the `poll' module, which you should require prior to using any of them. +* message_header_count + +This function takes an additional optional string argument: + + number message_header_count (number NMSG [, string NAME}]) + +If NAME is supplied, only headers with this name are counted. + Version 7.0, 2010-08-07 diff --git a/doc/functions.texi b/doc/functions.texi index 90940eb0..8b0649eb 100644 --- a/doc/functions.texi +++ b/doc/functions.texi @@ -821,14 +821,36 @@ done @deftypefn {Library Function} void header_rename_all (string @var{name} @ [, string @var{prefix}]) @flindex header_rename.mf -Defined in the module @file{header_rename.mf}. +@*Defined in the module @file{header_rename.mf}. +@*Available only in the @samp{eom} handler. If @var{prefix} is given, rename all headers named @var{name} to @samp{@var{prefix}-@var{name}}. Otherwise, remove all such headers. - -@FIXME{example}. @end deftypefn +@deftypefn {Library Function} void header_rename_pattern (string @var{pattern} @ +@flindex header_rename.mf +@*Defined in the module @file{header_rename.mf}. +@*Available only in the @samp{eom} handler. + +If @var{prefix} is given, rename all headers whose names match +@var{pattern} (in the sense of @code{fnmatch}, @pxref{Special +comparisons, fnmatches}) to @samp{@var{prefix}-@var{name}}. +Otherwise, remove them. + +For example, to prefix all headers whose names begin with +@samp{X-Spamd-} with an additional @samp{X-}: + +@smallexample +require 'header_rename' + +prog eom +do + header_rename_pattern("X-Spamd-*", "X-") +done +@end smallexample +@end deftypefn + @node Body Modification Functions @section Body Modification Functions @@ -1291,8 +1313,11 @@ given @var{name}. If there are several headers with the same name, optional parameter @var{idx} may be used to select one of them. @end deftypefn -@deftypefn {Built-in Function} number message_header_count (number @var{nmsg}) +@deftypefn {Built-in Function} number message_header_count (number @var{nmsg}, + [string @var{name}]) Return number of headers in message @var{nmsg}. + +If @var{name} is supplied, count only headers with that name. @end deftypefn @deftypefn {Built-in Function} number message_header_lines (number @var{nmsg}) diff --git a/mflib/header_rename.mf4 b/mflib/header_rename.mf4 index 88144227..391631a8 100644 --- a/mflib/header_rename.mf4 +++ b/mflib/header_rename.mf4 @@ -45,3 +45,24 @@ do fi done done + +/* If PREFIX is specified, rename all headers matching PATTERN to + PREFIX-NAME. Otherwise, remove them. */ +func header_rename_pattern(string pattern; string prefix) +do + number msg current_message() + number count message_header_count(msg) + loop for number i 1, + while i <= count, + set i i + 1 + do + string name message_nth_header_name(msg, i) + if name fnmatches pattern + string value message_nth_header_value(msg, i) + header_delete(name, i) + if defined(prefix) + header_add(prefix."-".i."-".name, value) + fi + fi + done +done |