procmail
[Top] [All Lists]

Really preserving "From " when forwarding....

1997-06-11 00:46:00

It seems this has come up in the recent past, but it seems like folks are  
having trouble preserving the "From:" line, whereas I want to preserve the  
"From " line (the very first line).

I've come up with what I think is a pretty ingenious use of procmail (I've  
only been using it 2 years now, it's about time I came up with something!)

Anyway, I've got mail delivered at one machine where I want mail delivered  
(ie I don't want to bother telling people a whole new address), but I want  
that message to be forwarded to my host.

(Note: I have some other questions in the comments below)

So on my ISP's procmailrc I have:

MYHOST=myreal.hostname.ext

# note: if the host is up it will say "$MYHOST is alive"
# or else it will say "$MYHOST is dead" or "No response from $MYHOST"
#
# I'd like to do this recipe only if it says 'alive' and not do it otherwise
# right now I am just testing ping's exit code, but I am not sure if it exits
# with 0 if the host is down
#
# I was thinking of something like this:
#
# ALIVE=`/usr/etc/ping $MYHOST|awk '{print $NF}'`
#
# and then "if $ALIVE = "alive" then forward, otherwise... requeue?
#
# any help on this part is most appreciated

#
# Ok, now MYHOST should always be up, but let's test it
#
# Does anyone know what will happen if I try to forward and MYHOST is down?
#

# Blatantly assume that ping only exits with 0 if the host is alive
# this may not be true!!!

:0
* ? /usr/etc/ping $MYHOST
* !^X-Forwarded: yes
{
        :0c:
        backups-forwarded


        :0
        * ^From *\/[^ ].*
        | (formail -I "X-Forwarded: yes"  -I"X-Original-From: $MATCH") |\
          $SENDMAIL -oi luomat(_at_)$MYHOST

}

# right now if PING doesn't exit = 0 the message goes to $DEFAULT


NOW that will forward the message, but the 'From ' line will me  
"mylogin(_at_)myisp(_dot_)com" rather than the original 'From ' line


I was going to do this on MYHOST

:0wfh
*^From luomat
* !^From:.*luomat
| formail -I'From ' | formail

Thinking that it would check to see if the 'From ' line was from me, and if  
so and the 'From:' line was not from me, then regenerate the 'From ' line....  
but this did not work :-(


So now have this:

:0fhw
* ^X-Original-From: *\/[^ ].*
|/bin/sed "s/^From\ .*/From ${MATCH}/g"

And that works rather well..... Is there a way to make sure that it only  
matches the very first line of the email?  Is there a better way of  
preserving the original 'From ' line?

Thanks!

TjL



--
TjL <luomat(_at_)peak(_dot_)org>   / http://www.peak.org/~luomat/next/
"The best things in life are made into inferior
 versions and bundled with the latest Microsoft systems"
NeXT bookmarks: http://www.peak.org/~luomat/next/bookmarks.html

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