procmail
[Top] [All Lists]

Re: remove text from body and change subject and author

2005-01-12 17:35:37
On Tue, Jan 11, 2005 at 05:53:33PM +0100, Fabian Braennstroem wrote:

Fabian, would you please just post the header lines verbatim
that you want to work with and repeat what your goal is with them?
People would be glad to help with actual syntax rather than
generalized statements, if you'd only help them help you.

Here is a small example with the first couple lines of the
body:

[header deleted except for Subject]

       Subject: OpenFOAM: Installation: OpenFoam for MS windows
       
       ------------------------------------------------------------
       OpenFOAM Message Board: OpenFoam: Installation: OpenFoam for
       MS windows
       ------------------------------------------------------------
       
       By Madhav Gentela (Gentela) on Wednesday, December 29, 2004
       - 07:56 pm:

With my procmail-recipe without the header 'h':

      :0
      * ^Subject.*(OpenFoam: Installation)
      {
       :0w
       FROM=|formail -I "" | sed -n -e '/By\ /p' |  sed -e  
's/^\(.\{0\}\).\{3\}\(.*\)/\1\2/'|  sed -e  
's/^\(.\{10\}\).\{30\}\(.*\)/\1\2/'

       :0 fw
       | formail -i "From:$FROM"

       :0
       CFD/OpenFoam_Installation
      }


I want to look for the line with 'By Madhav Gentela...' and erase the
word 'By ' and some more appending stuff like the day and date.

Okay.  Saying you want to erase "some more ... stuff" is not very
precise when one is trying to build a regex parser.  *What* more
appending stuff?  All of it?


Aeh, now it works; at least there are some mixed up names and not the
default From-Header. Copying the recipe I saw that I tested it on the
new Subject, so the recipe never started for these mails.

Your sed does not work, even left as-is in its highly inefficient state
of running three sed pipes serially.  It fails on the second operation:

 bash-2.05b$ echo 'By Madhav Gentela ( Gentela ) on Wednesday, December 29, 
2004' | \
              sed -n -e '/By\ /p' | sed -e 's/^\(.\{0\}\).\{3\}\(.*\)/\1\2/'

 sed: 1: "s/^\(.\{0\}\).\{3\}\(.* ...": RE error: empty (sub)expression 

(And the first sed expression's only purpose is to limit the editing space to
the line I echoed.)

As for the procmail code, again, the "w" flag does nothing useful on an
action line that ends with a sed statement; sed does not offer return
codes that show whether there was string parsing or not.  (The error
codes only show whether sed could execute, period.  But if it couldn't,
waiting for it (with a "w") does no good if there's no Plan "B" for what
to do if the code errors out.  So just leave off the "w" from the sed
one.  Here's proof:

  [217.228.128.33 -> panix5] {dman} [1.61]
   8:54pm [~/Mail] 577[0]> echo foo | sed 's/bar//'; echo $?
  foo
  0
  
  [217.228.128.33 -> panix5] {dman} [1.46]
   8:55pm [~/Mail] 578[0]> echo foo | sed 's/foo//'; echo $?
  
  0
  

Exit code of zero regardless of whether "foo" was altered by the sed statement.

Anyway, back to your problem:

  :0 fw h   # filter the head only, but using a match from the body
  * ^Subject:.*OpenFOAM: Installation:
  * B     ?? ^By \/[^(]*
  * MATCH ?? ^^\/.*[^ ]
  | formail -i "From: $MATCH"

That will put "From: Madhav Gentela" in the From: header.  Is that what you
want?  (What is Madhav's email address, and whence do we get it?)

-- 
dman

____________________________________________________________
procmail mailing list   Procmail homepage: http://www.procmail.org/
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail