aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2011-03-13 13:23:25 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2011-03-13 13:23:25 +0200
commit07ca8622ff6226c45b4ac321b38e5f6918f11603 (patch)
tree7041f2161e5503f5fe33e685b2e64a4895288e5c
parent31949407692d3176e88bdcb6b08f78b598f20b3c (diff)
downloadmailfromd-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--NEWS8
-rw-r--r--doc/functions.texi33
-rw-r--r--mflib/header_rename.mf421
3 files changed, 58 insertions, 4 deletions
diff --git a/NEWS b/NEWS
index 45848a16..eae1a68f 100644
--- a/NEWS
+++ b/NEWS
@@ -55,2 +55,10 @@ 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.
+
diff --git a/doc/functions.texi b/doc/functions.texi
index 90940eb0..8b0649eb 100644
--- a/doc/functions.texi
+++ b/doc/functions.texi
@@ -823,3 +823,4 @@ done
@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.
@@ -827,6 +828,27 @@ 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
+
@@ -1293,4 +1315,7 @@ optional parameter @var{idx} may be used to select one of them.
-@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
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
@@ -47 +47,22 @@ do
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

Return to:

Send suggestions and report system problems to the System administrator.