Question

I'm using the following (classic) procmail recipe to catch mailing list e-mails and file them into a folder by list name:

:0
* ^((List-Id|X-(Mailing-)?List):(.*[<]\/[^>]*))
{
    LISTID=$MATCH
    :0
    * LISTID ?? ^\/[^@\.]* 
    Lists/$MATCH/
}

The problem is: if a list name changes from all lowercase to Firstlettercap, I end up with two folders, one for 'listname' and another for 'Listname'.

I'd like to lowercase the $MATCH variable before using it in the final delivery rule, but I'm not able to find a reference to a lc() function, or a regex/replacement that can be used to do this.

One comment below suggested this:

:0
 * ^((List-Id|X-(Mailing-)?List):(.*[<]\/[^>]*))
 {
    LISTID=`echo "$MATCH" | tr A-Z a-z`
    :0
    * LISTID ?? ^\/[^@\.]*
    .Lists.$MATCH/
 }

Which also doesn't appear to do what I'm after. Though, looking at it now, clearly the transliteration is only happening on the first occurrence of $MATCH and my guess is that it's not changing it at all for the use in the folder assignment line.

UPDATE #1: If I try to use LISTID in the folder assignment line, I get something like 'Bricolage.project.29601.lighthouseapp' instead of just 'Bricolage' or -- what I'm after -- just 'bricolage'.

Was it helpful?

Solution

Procmail itself has no functionality to replace text with other text. You can run the match through tr, or if avoiding external processes is really important, create a rule for each letter you need to map.

LISTID=`echo "$LISTID" | tr A-Z a-z`

# or alternatively
:0D
* LISTID ?? ^A\/.*
{ LISTID="a$MATCH" }
:0D
* LISTID ?? ^B\/.*
{ LISTID="b$MATCH" }
# ... etc

You could combine this with the final MATCH processing but I leave it at this for purposes of clarity.

OTHER TIPS

AFAIK procmail regular expressions are always case INsensitive anyway, so you already get what you want without doing anything special. At least I always used it that way, and all the sites with procmail documentation I checked (3+) said so too.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top