procmail
[Top] [All Lists]

Re: Controlling the procmail logfile ?

1997-08-26 13:33:28
I wrote,

| >   :0c
| >   backup/
| >
| >   :0
| >   * LASTFOLDER ?? ()\/[^/]+$
| >   { LOGFILE=logs/$BASENAME }

Ed Sabol caught me,

| $BASENAME? Do you mean $MATCH?

Oops, yes.  I partially edited some code that included assigning
BASENAME=$MATCH at first.  Thanks for catching that.

| If so, then remember that, as of 3.11pre5,
| $MATCH would include the newline since you have a "$" in the regexp you are
| MATCHing.

I believe that the newline will be stripped by the assignment operator and
will not survive into the logfile's name, however.  Still, if it does,
it's easy to cure:

 :0
 * LASTFOLDER ?? ()\/[^/]+$
 * MATCH ?? ^^\/.+
 { LOGFILE=Logs/$MATCH }

| Unfortunately, "[^/]+" will also match the newline.

No, it will not include the newline (a bracketed range can never match a
newline), but without the right anchor, it will match the *first* run of
one or more non-slash characters: in this case, the word "backup".

| "[^/].+" would not, but
| that won't work in the context of what you are trying to do.

In fact, it will match the entirety of $LASTFOLDER except any opening slash.

|    :0
|    * LASTFOLDER ?? backup/\/.+
|    { LOGFILE=logs/$MATCH }

Fine, as long as that the backup directory is named "backup" or something
ending in "backup".

| Or, more generically:
| 
|    :0
|    * LASTFOLDER ?? ()\/[^/]+

Nope, that needs the right anchor or it will match the name of the backup
directory instead of that of the file.  Add the "$" and then the rest of
the code will work:

|    {
|        BASENAME=$MATCH
| 
|        :0
|        * BASENAME ?? ^^\/.+
|        { LOGFILE=logs/$MATCH }
|    }

| But that seems a little unnecessarily cumbersome to me. The former would only
| fail in circumstances where $MAILDIR included the string "backup/" which is
| probably highly unlikely.

LASTFOLDER should not include "$MAILDIR" if $MAILDIR is not named in the
recipe, so the former would fail only in cases where the name of the backup
directory does not end in "backup".

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