Re: How to extend ^TO_
Bart Schaefer <[email protected]> Sat, 25 Jan 2014 10:45:33 -0800
| Newsgroups | gmane.mail.procmail |
|---|---|
| Message-ID | <CABkvzcv3RiEiLSB8464_S9-TNKPFJRD6ai4O41JSz0ahkvGA4w@mail.gmail.com> |
On Fri, Jan 24, 2014 at 4:21 PM, Geoff Soper <[email protected]> wrote: > Hi, > in various places within my procmail recipes I have the following string: > (^TO_|Delivered-To:) > > How can I define this as a variable that I can use repeatedly in my recipes > and how do I include it in my recipes? I'm not sure LuKreme actually answered your question ... his example showed definitions of $NL and $WS for newline and whitespace but didn't show any uses of them. To define the pattern as a variable, you just use assignment syntax: Delivered_TO = '(^TO_|Delivered-To:(.*[^-a-zA-Z0-9_.])?)' (I've taken the liberty of fixing your pattern so that the scan of Delivered-To: will behave like the rest of the headers examined by ^TO_) Unlike the shell, procmail doesn't care about spaces around the "=", use them or omit them as you please. Capitalization in the variable name doesn't matter either, some people prefer all-caps to differentiate variables from other strings in the pattern more plainly. To use it in a recipe, you probably need to use braces around the variable name: :0 * ${Delivered_TO}geoff\.procmail2401 procmail-stuff You could instead put parens around the pattern that follows: :0 * $Delivered_TO(geoff\.procmail2401) procmail-stuff Either one will separate the "TO" from the "geoff", otherwise procmail would try to look up "Delivered_TOgeoff" as the variable name and find nothing. As a last note, because $name is expanded as a variable reference, you may sometimes have to use ($)name if you want to match a two-line string that has "name" at the start of the second line.