procmail
[Top] [All Lists]

Re: Procmail -Sed/ex/ed question.

1999-06-10 16:59:29
Tapas Banerjee asked,

| On our project, publisher of mail keep "mailing list name" on message body,
| and send attachment with mail text. While formatting the message using
| procmail and formail, we delete the name of mailing list. But the PROBLEM
| is, this deletion in tern moves  the PDF attachment by a deleted number of
| character on message body. I realized that - the systems takes into account
| of count of character. If we delete them, it shifts PDF by that count.
| 
|  Following is the recipe, and I would like to change ---> line.
| ----------------------------------------------------------------------------
| ----------------------------
| :0
| * ? fgrep -xis "$SENDER" /home/ess/.procmail/sender_list
| * !^Subject:.*\<RE:
| * B ?? ^\/.*_list
| {
|      # Remove line containing subject(<name>_list), from body
|      :0 fbw
|      | sed -e "s/$MATCH/ /g"   ------>  |sed -e s/$MATCH/COUNT OF
| CHARACTER($MATCH) ./g"              ......
| ----------------------------------------------------------------------------
| -------------------------------
| i.e.  say MATCH=davinci_list
|        it will be replaced by wc -c $MATCH, i.e. 12 character of space or
| '.', to place attachment  at correct position.
| 
|  Do you know how to do this in sh/sed/ex/ed? I can to do it easily by a perl
| script, but for efficiency reason, it would be nice if do using simple shell
| command in procmail rc file, not calling another external program.

Hmm.  Settle for a recursive includerc arrangement?

  :0
  * 1^1 MATCH ?? .
  {
   OLDSTRING = $MATCH
   SEDCATCHER = $\OLDSTRING # the string probably includes brackets
   NEWSTRING = $OLDSTRING
   INCLUDERC = /path/to/.space_outrc # or relative path from $MAILDIR

   :0 # sed won't grok the leading empty parentheses
   * SEDCATCHER ?? ^^..\/.+
   { SEDCATCHER = $MATCH }
  }
  :0Afwb
  | sed -e "1,/$SEDCATCHER/s/$SEDCATCHER/$NEWSTRING/"

and in .space_outrc,

  :0
  * NEWSTRING ?? ^^\/( )*
  { DONEPART = "$MATCH" }

  :0
  * $ NEWSTRING ?? ^^()$DONEPART().\/.*
  {
   NEWSTRING = "$DONEPART $MATCH"

   :0
   * MATCH ?? .
   { INCLUDERC = $_ }
  }

Now, that said, I am not enamored of the approach.  Tapas, where is the
offset -- the number that says how many characters into the body the
attachment starts -- provided?  I think it would be better to extract that
number into $MATCH, reduce it by the size of the deleted text, and correct
it in the message.  For example (this assumes that there is at least one
character [besides the repeated listname] before the attachment),

 :0
 * ^X-Offset: *\/[1-9][0-9]*
 * $ $MATCH^0
 * -1^1 OLDSTRING ?? .
 | formail -i "X-Offset: $="

OK, so it's another fork, but it's so much cleaner than a recursive includerc.

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