procmail
[Top] [All Lists]

removing suffixes without a shell

1998-06-16 12:36:23
Jari Aalto's new list recognition routine's documentation includes this:

|         `JA_LIST_USE_SHELL'
| 
|         This variable controls if shell is called to remove
|         "-request|-help|-owner" words from list name. Procmail can easily
|         reduce prefixes:
| 
|             owner-list-name --> list-name
| 
|         but it can't easily remove words to the right. This would
|         require calling shell and command `expr':
| 
|             list-name-owner --> list-name

Not true; suffixes can be removed without shells or outside programs.

:0
* LISTNAME ?? -(owner|request|help)^^
* LISTNAME ?? ^^\/.*-
* MATCH ?? ^^\/.*[^-]
{ LISTNAME = $MATCH }

That works even if there are embedded hyphens in the list's name; the only
problem would come from a trailing hyphen in the list's name.  (It would
reduce this-is-a-list-owner or this-is-a-list-request to this-is-a-list
but this-is-also-a-list--owner or this-is-also-a-list--request to just
this-is-also-a-list instead of this-is-also-a-list-.)

Earlier versions of procmail that are recent enough to grok extraction but in
which one cannot define MATCH twice in the same recipe can do it with code
like this:

:0
* LISTNAME ?? -(owner|request|help)^^
* LISTNAME ?? ^^\/.*-
{
 LISTNAME_HYPHEN = $MATCH

 :0
 * LISTNAME_HYPHEN ?? ^^\/.*[^-]
 { LISTNAME = $MATCH }
}

<Prev in Thread] Current Thread [Next in Thread>