procmail
[Top] [All Lists]

Re: how to strip any leading and trailing whitespaces?

2000-03-14 09:25:08
Vyacheslav Zakharov asked,

| How may I discard any leading and trailing whitespaces from Subject?

| The following recipe works fine for me:
| 
| :0
|  { SUBJECT=`formail -xSubject: |  sed -e 's/[;\`\\]/ /g' |\
|         expand | sed -e 's/^[ ]*//g' -e 's/[ ]*$//g'` }
| 
| but I read formail's calls were too expensive and slowed down the system.
| I wanna do it using procmail's MATCH variable.

However expensive formail is, one formail is less costly than a formail, two
seds, an expand, and a shell to pipe each to the next, and at that point you
still haven't filtered the message to have the stripped subject line.  As in
your own code, brackets enclose space and tab or caret, space, and tab:

  :0fwh # second asterisk and question mark are greedy
  * ^Subject:[  ]*\/[^  ](.*[^  ])?
  | formail -I "Subject: $MATCH"
  :0Efwh
  * ^Subject:
  | formail -I "Subject: (was blank)"
  :0Efwh
  | formail -I "Subject: (was missing)"

Of course, that will be fooled if an incoming subject really is "(was blank)"
or "(was missing)," but I think the risk is negligible.

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