1

I am new to procmail and struggling to understand the syntax.

What I want to do is to check the subject line to see if it begins with 3 upper case chars followed by a colon, and if it does, remove the colon from the end and perform and action i.e:

Subject: ABC: Other parts of the subject

:0
* $ ^Subject:/^[A-Z]{3}:$/
| /usr/bin/zarafa-dagent -C -P 'Support\\$1' vmail

Firstly I'm not sure if my regex is correct, and secondly, despite a lot of googling I can't figure out how to save my search into a variable to use elsewhere, I tried $1 for the first returned variable but that does not appear to work.

Any help would be much appreciated.

crankshaft
  • 2,607
  • 4
  • 45
  • 77

2 Answers2

2

You can post-process the value of $MATCH to trim the colon.

:0 D
* ^Subject:[^   ]*\/[A-Z][A-Z][A-Z]:
{
    :0
    * MATCH ?? ^^\/[A-Z][A-Z][A-Z]
    | /usr/bin/zarafa-dagent -C -P "Support\\$MATCH" vmail
}

The first condition captures the three uppercase characters and the colon into MATCH. The second matches this value against three uppercase characters, and captures just that part into the new value for MATCH.

As usual, the whitespace inside the brackets after Subject: consists of a space and a tab.

tripleee
  • 175,061
  • 34
  • 275
  • 318
-1

OK, solved this, procmail has it's own version of regex:

:0 D
* ^Subject:.*\/([A-Z]+[A-Z]+[A-Z]):
| /usr/bin/zarafa-dagent -C -P "Support\\$MATCH" vmail
EXITCODE=$?

It does not support the iterator brackets [A-Z]{3} and so you have to repeat the expression.

Also, it is case-insensitive, so you need to add the "D" flag.

Problem is I seem to be unable to remove the colon : from the end.

crankshaft
  • 2,607
  • 4
  • 45
  • 77
  • The `EXITCODE` assignment doesn't make any sense here; you are assigning it regardless of whether the condition triggered or not. You should probably add a `w` flag if you genuinely care about the exit code. Procmail will regard the delivery as failed if the action fails, anyway. – tripleee Apr 10 '14 at 08:01
  • 1
    Also, the `[A-Z]+` is wrong if you really just want to match one uppercase character -- lose the plus quantifier which means "one or more". – tripleee Apr 10 '14 at 08:01
  • Or if you just want to capture the exit code for your own internal use, don't use the built-in special variable `EXITCODE`. A good convention is to use lowercase for your own variable names. – tripleee Aug 09 '17 at 08:05