procmail
[Top] [All Lists]

Re: Multi-Directory Fileserver

1998-10-01 11:39:43
Adam Bailey, you wrote that your logfile says,

    procmail: No match on "-\/[0-9]+"

Here is your code, as suggested by our newlywed pal in Finland, Era Eriksson:

| : :0 c
| : # * ^Subject: SEND ISSUE [0-9a-z]
| : * ^Subject:\<*send\<*issue\<*\/[0-9]+-[0-9]+
| : * !^X-Loop: odn(_at_)main-net(_dot_)com

The situation may never come up, but the period should be escaped.

| : * !^Subject:.*Re:

The first condition eliminates subjects begining with Re:.  If the sender
wants to stick Re: to the right of the filename, it's no problem.

| : * !^FROM_DAEMON
| : # * !^Subject: SEND ISSUE .*[/.]\.

As Holger Wahlen explained, perhaps you didn't test the cases where that
condition is needed.  However, as long as only [0-9]+-[0-9]+ is extracted,
let them type anything else they please farther along the line, including
/. or .., and it won't get into the name of the file anyway.  So, given that
the earlier condition restricts the filename safely, yes, we can do without
that one.  It is needed, though, for the generic case of letting the sender
specify any filename, to prevent going up the tree or fetching dotfiles or
entering dot-named subdirectories.

| : {
| :     MAILDIR=$HOME/webpgs/issues
| :     :0 fhw
| :     * ^Subject: SEND ISSUE \/[^ ]*

As Emil Isberg has posted, that condition is redundant; the line is already
matched and $MATCH is already extracted.

| :     | formail -I "From: odn(_at_)main-net(_dot_)com" -rA "X-Loop: 
odn(_at_)main-net(_dot_)com"
| :
| :     FILE="$MATCH"
| :
| :         :0
| :         * STRING ?? -\/[0-9]+

Well, there's your problem.  $STRING has not yet been defined, so it is
unset.  Therefore it will not contain a hyphen followed by at least one
digit.

| :         { ISSUE=$MATCH

That brace's partner is in a different column, so it is hard for the eye to
scan, but I'm rearranging the braces anyway.

| :         STRING=$MATCH
| :         :0
| :         * STRING ?? ^^\/[0-9]+
| :         { VOL=$MATCH }
| :
| :         FILE=volume_$VOL/issue_$ISSUE.txt
| :
| :  }
| :
| :     :0 ah
| :     | cat - ./$FILE 2>&1 | $SENDMAIL -oi -t
| : }
| :
| : :0 a:
| : $HOME/requests.log

`a' looks odd there, as it tests the previous action on that level, which
was "{", which cannot fail.  Therefore `A' makes more sense.  In fact,
better to place it inside the preceding braces altogether and lose the
clone.

| but it ends up just printing the results in the requests.log file.

Yes, because the command to save to requests.log is not dependent on that
condition.  Methinks Era understandably had other things on his mind and made
an incomplete edit when he changed his mind about something; I do that a lot
myself, and I don't have newlywed status as a justification.  Let's try again:

    :0
    * ^Subject:\<*send\<*issue\<*\/[0-9]+-[0-9]+
    * !^X-Loop: odn(_at_)main-net\(_dot_)com
    * !^Subject:.*Re:
    * !^FROM_DAEMON
    {
     STRING="$MATCH"
     MAILDIR=$HOME/webpgs/issues

     :0c:
     $HOME/requests.log

     :0 fhw
     | formail -I "From: odn(_at_)main-net(_dot_)com" -rA "X-Loop: 
odn(_at_)main-net(_dot_)com"


     :0
     * STRING ?? -\/[0-9]+
     { ISSUE=$MATCH }

     :0
     * STRING ?? ^^\/[0-9]+
     { VOL=$MATCH }
   
     FILE=volume_$VOL/issue_$ISSUE.txt

     :0w
     | cat - ./$FILE 2>&1 | $SENDMAIL $SENDMAILFLAGS -t

     :0: # catch `e' situation
     $HOME/requests.failed
    }

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