procmail
[Top] [All Lists]

Re: how to extract informations from the subject field ?

2005-07-22 23:57:08
Google Kreme schreef:
On 21 Jul 2005, at 13:54 , robert guru wrote:

I m receiving emails that have a special subject, the subject field
is composed by two elements sperated by the space character.
the first element is the string "DEPART" and the second element is
the department name
(example:   "DEPART computer_science"). So i want that procmail
extract the seconde element (department name), because the email
will be processed depending on this information.



   # Contains a space and a tab
   WS="    "

   :0h
   * $ ^Subject:$WS*\/[^$WS].*
   {
     SUBJECT=$MATCH

     :0
     * $SUBJECT ?? DEPART
     {
       :0h
       * $ ^Subject:$WS+DEPART \/.*
       { DEPART = $MATCH}
     }
   }

Should work.

I don't understand both h-flags. The "$WS+" was meant as "[$WS]+".


This single recipe does basically the same:

  :0
  * ^Subject: .* DEPART \/[^ ]+
  { DEPART = "$MATCH" }



But such "user-input" should always be treated as tainted, so check it
agains a list of acceptable values.

DEPS = '
computer_science
computer_magic
computer_fun
'

  DEPART   # unset
  :0
  * ^Subject: .* DEPART \/[^ ]+
  {
    DEPART = 'typo'
    :0
    *$ DEPS ?? ^$\MATCH^
    { DEPART = "$MATCH" }
  }

(untested)

-- 
Grtz, Ruud


____________________________________________________________
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

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