2

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'.

phillipadsmith
  • 364
  • 2
  • 13

3 Answers3

1

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.

tripleee
  • 175,061
  • 34
  • 275
  • 318
0

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.

Mörre
  • 5,699
  • 6
  • 38
  • 63
  • Doesn't seem to be the case, as folders with 'Listname' and 'listname' are being created. – phillipadsmith May 13 '11 at 20:08
  • Interesting, in this case I'll give your QUESTION an upvote... :) – Mörre May 13 '11 at 20:09
  • Okay, no news, but just to say that it seems that while the matching itself is (very likely) indeed case insensitive your problem lies AFTER matching. Try 7.21 at http://pm-doc.sourceforge.net/doc/#converting_value_to_lowercase – Mörre May 13 '11 at 21:32
  • Frustratingly, no luck. I have updated the recipe to this: https://gist.github.com/59887ed6dbd3103082fc ... and, yet, this is the log: https://gist.github.com/886ebbca32110f39b485 You'll notice that the list name -- Bricolage -- is still first-letter capped. :( – phillipadsmith May 14 '11 at 00:41
  • I think you've got the syntax a little wrong, judging from how they do it on the same page at http://pm-doc.sourceforge.net/doc/#saving_to_monthly_folders Your LISTID definitely has the right (lowercased) value! But it isn't used. There's ".Lists.$MATCH/" as the last line. – Mörre May 14 '11 at 05:35
  • @Mörre Yep, I wondered about that and updated the question accordinly. Wasn't clear to me that I could use the LISTID as a variable in the delivery rule. I'll give that a try. – phillipadsmith May 14 '11 at 18:05
  • 1
    Matching is indeed case insensitive but that fact is of no relevance here. The OS and the file system are case sensitive so they care about the case of the file names you are manipulating (except on the OSX default filesystem, apparently). `List` is different from `LIST` and `list` when used as a file name, regardless of Procmail. – tripleee Nov 17 '15 at 10:26
0
:0
 * ^((List-Id|X-(Mailing-)?List):(.*[<]\/[a-z]*))
Lists/`echo $MATCH | tr A-Z a-z`/