procmail
[Top] [All Lists]

Re: Fixing Original-(To|Cc) headers ?

1998-01-06 12:42:35
Vikas Agnihotri asked,

: How can I use procmail/formail to combine the information in these
: headers into their *CORRESPONDING* header MINUS the Original- ?

remarking that,

: Note that I can have multiple Original-Cc: headers and I want all the
: recipients combined into one Cc: header.

and

: I am not sure if multiple Original-To: headers are even allowed per RFCs
: but I am pretty sure I get emails with multiple Original-To: headers.

  ORIGINALTO ORIGINALCC # initialize as unset

# The -c option to formail takes care of headers continued onto indented
# lines; the pipe to tr takes care of multiple Original-To: headers by
# linking their contents with commas.

  :0h
  * ^Original-To:.*[^   ]
  ORIGINALTO=|formail -zcxOriginal-To: | tr \\12 ,

# Drop trailing comma from tr:

  :0A
  * ORIGINALTO ?? ,^^
  * ORIGINALTO ?? ^^\/.*[^,]
  { ORIGINALTO = $MATCH }

# Likewise for Original-Cc: lines:

  :0h
  * ^Original-Cc:.*[^   ]
  ORIGINALCC=|formail -zcxOriginal-Cc: | tr \\12 ,

  :0A
  * ORIGINALCC ?? ,^^
  * ORIGINALCC ?? ^^\/.*[^,]
  { ORIGINALCC = $MATCH }

# Now, let's install the changes if needed:

  :0
  * ORIGINALTO ?? ^^^^
  * ORIGINALCC ?? ^^^^
  { }
  :0Efwh
  | formail ${ORIGINALTO:+-A "To: $ORIGINALTO"} \
    ${ORIGINALCC:+-A "Cc: $ORIGINALCC"}

: Is this advisable? Does this clobber any useful information or make the
: message invalid in any way?

I can't comment on advisability, but with -A instead of -I or -i it should
not clobber existing To: or Cc: information.  (It *is* acceptable to have
multiple To: or Cc: lines.)  The only information lost is whether a listed
recipient was in a straight To: or Cc: header or in an Original- header.

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