procmail
[Top] [All Lists]

Re: Removing line-wrapped header

2004-09-10 11:23:42
Wrapping-up:

  NL    = "
" SPC   = " "
  TAB   = "     "
  b     = "[$SPC$TAB]"
  S     = "[^$SPC$TAB]"

# Example-1:
#  my_FIELD = "Re?c(ei|ie)?ve?d"
#  my_REGEX = "by virus[a-z0-9._-]+"

# Example-2:
  my_FIELD = "Mime-Version"
  my_REGEX = "1\.0"

# Example-3:
#  my_FIELD = "Return-Path"
#  my_REGEX = "<.*>"

# Example-4:
#  my_FIELD = "Received"
#  my_REGEX = "30874"

  :0
  *$ ^$my_FIELD:.*$my_REGEX
  {
    # alternative-1:
    #  :0h
    #  my_HEADERS=|cat

    # alternative-2:
    my_HEADERS = `formail -f -X ""`

    # alternative-3:
    #  my_HEADERS = `sed '/^$/q'`

    :0
    *$ my_HEADERS ?? ^^\/(.+$)*$my_FIELD:.*\
                         (^$b.*)*$my_REGEX
    *$ MATCH ?? ^^\/(.*^)*$S
    {
      my_HEAD # unset
      :0
      * MATCH ?? ^^\/(.*^)*..+$
      { my_HEAD = $MATCH }

      my_TAIL # unset
      :0
      *$ my_HEADERS ??
^$my_FIELD:.*(^$b.*)*$my_REGEX.*(^$b.*)*^\/$S.*(^.*)*
      { my_TAIL = "$MATCH$NL" }

      :0 h fw
      | echo "$my_HEAD$my_TAIL"
    }
  }

This goes wrong when 'my_REGEX' is not specific enough. There is a way
to solve even that, by translating 'my_HEAD' into a proper regex, by
changing each leading whitespace-character of every line from ' ' to
'( )' (or something equivalent), since leading whitespace-characters
are ignored. Because then you can use my_HEAD to deduct my_TAIL. With
my snr you can do that. *But you don't have to worry about all that if
you just ensure that 'my_REGEX' is specific enough.*

-- 
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>