procmail
[Top] [All Lists]

Re: Wondering about error output

2000-01-10 23:32:53
S.Toms wrote,

|   I have a filter that checks the size of messages received and responds
| accordingly. Everything seems to work fine but the error has me wondering
| what I messed up and where. I'm hoping someone may beable to enlighten me.
| 
| <filter>
|    :0
|    * > 102400
|    * $!^From:.*(${ADDRESS}|${ALTADDRESS})
|    {
| 
|       :0c:
|       lrgleantag
| 
|       :0
|       { LOG = "Message size exceeds 100Kb" }
| 
|       :0c: lrgleantag.lock
|       | (formail -rt \
|          -I "From: MAILER-DAEMON(_at_)${HOST} (Mail Delivery Subsystem)" \
|          -A "X-Loop: ${LOGNAME}(_at_)${HOST}" ; \
|          cat ${PMDIR}/.limit ; \
|          echo " " ; \
|          echo " " ; \
|          echo " " ; \
|          cat lrgleantag ; \
|          rm -f lrgleantag) \
|          | /usr/sbin/sendmail -oi -t
|    }
| <end filter>

That's not a good way to do it.  You're giving up a lock after the save to
the temporary file and then expecting it to be guaranteed to have the same
contents when you try to get the same lock back.  Besides, you don't need
the temporary file at all.  Also, you should have a newline at the end of the
logged text so that you wouldn't get this:

| Message size exceeds 100Kbprocmail: Locking "lrgleantag.lock"

|   What I don't understand is the 'Error while writing to' part about a 1/3
| the way down in this error snip. As I said, it responds and replies
| correctly, but the error is irritating :/

| procmail: Error while writing to " (formail -rt \
|          -I "From: MAILER-DAEMON(_at_)${HOST} (Mail Delivery Subsystem)" \
|          -A "X-Loop: ${LOGNAME}(_at_)${HOST}" ; \
|          cat ${PMDIR}/.limit ; \
|          echo " " ; \
|          echo " " ; \
|          echo " " ; \
|          cat lrgleantag ; \
|          rm -f lrgleantag) \
|          | /usr/sbin/sendmail -oi -t"

That usually means that the command is not accepting the entire input,
and the recipe doesn't have an `i' flag to tell procmail that that's OK.
Without the -k option flag, formail -r will use only the head, and you
aren't using an `h' flag on that recipe, so you're telling procmail that
the command should read the entire message.  The message is over 100Kb,
a lot of which is likely to be in the body, so that's a lot of text
left unread when formail stops accepting input.

I'm a little surprised, as I didn't expect that to happen with formail -r
(or -x or -X); I thought it would happily read and lose the body.

Also, you want to respond to the sender, not necessarily to the reply
address, so you should not use -t with formail -r; -rt is for addressing
replies to content and -r is for reactions to receipt.

Instead of three echo commands after catting $PMDIR/.limit, add three trail-
ing blank lines (the spaces are unnecessarily) to the .limit file.  Then the
cat command will put the three blank lines there and you won't need three
echoes.

Here's a way to do it with no temporary file, and which gets around the
writing error problem (since formail -r will be called in a recipe that
reads only the head).

    # filter and return in a clone, let parent deliver original
    # X-Loop: header isn't of much value unless you test for it
    :0c
    * > 102400
    * $!^X-Loop: $LOGNAME(_at_)$\HOST
    * $!^From:.*($\ADDRESS|$\ALTADDRESS)
    {
       # Note trailing quote on following line to enclose newline in the text.
       LOG = "Message size exceeds 100Kb
"

       :0fh # double the head
       | sed -e H -e \$G

       # A duplicate of the head is now prepended to the body.

       # invert [first] head for return and insert .limit between it and
       # copy of original head (now part of the body)
       :0fh
       | formail -r \
          -I "From: MAILER-DAEMON(_at_)$HOST (Mail Delivery Subsystem)" \
          -A "X-Loop: $LOGNAME(_at_)$HOST" ; \
          cat $PMDIR/.limit # .limit file should end with three blank lines

       # The head of the cloned message has been inverted header for return.
       # The body of the cloned message comprises the .limit file with its
       #  blank lines, the old head, plus the original body.

       # Send out the clone.
       ! -t

       HOST # in case of fall-through
    }

    # parent procmail skips down here to deliver the original message

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