procmail
[Top] [All Lists]

Re: How to avoid s/\n/ /g when unfolding a header

2004-12-13 21:11:52
Toen wij Dallman Ross kietelden, kwam er dit uit:
Robert Allerstorfer:

OK, I think it is not possible to remove leading whitespace from each
line of a multiline string with pure procmail code. Therefore, I will

Well, it's possible, but you'd need a recursive rcfile.

  multiline_subj = `formail -zx Subject`
  INCLUDERC = do_me.inc

Inside "do_me.inc":

  :0
  * $ multiline_subj ?? $buildmeasubject$NL.*\/[^$WS]+
  {
     buildmeasubject = $buildmeasubject$MATCH
     SWITCHRC = $_
  }

  SWITCHRC  # this is our exit at the end


This is all completely untested, of course.



There is more to it than that.


For unwrapping, a Head-approach gets near:


  unwrap_Input = `formail -u Received -zx Received`

  unwrap_Head   # unset
  unwrap_Return # unset

  INCLUDERC = unwrap.inc
  LOG = "$NL$NL$unwrap_Return$NL"


  # unwrap.inc
  :0
  * $ unwrap_Input ?? $\unwrap_Head^\/.*
  {
    unwrap_Head = "$unwrap_Head$NL$MATCH"

    :0
    *$ MATCH ?? ()\/[^$WS].*
    {
      unwrap_Return = "$unwrap_Return $MATCH"
      SWITCHRC = $_
    }
  }



A line-skip-approach is far more reliable:


  unwrap_Input = `formail -u Received -zx Received`

  unwrap_Skip   # unset
  unwrap_Return # unset

  INCLUDERC = unwrap.inc
  LOG = "$NL$NL$unwrap_Return$NL"



  # unwrap.inc
  :0
  *$ unwrap_Input ?? ^^$unwrap_Skip\/[^$WS].*
  {
    unwrap_Return = "$unwrap_Return $MATCH"
    unwrap_Skip   = "$unwrap_Skip.*(^[$WS]*)+"
    SWITCHRC = $_
  }

but that still goes 'wrong' when a non-empty line
with only whitespace is included. (such lines are
not allowed, see rfc2822)

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