procmail
[Top] [All Lists]

Rewriting mails

2000-03-17 13:01:58
Hi guys sorry if this is simple/frequently asked but I've read through the
man pages and what I can find on the net but can't find an easy answer,
maybe one of you guru's can help...

Here's what I'm trying to do....

I have two domains let's call them ABC and XYZ for ease...
ABC is the main domain and XYZ is a fake IP which uses the SMTP server on
the main domain.
*All* mail from both domains goes into one POP account on ABC
I want to forward all mails sent to XYZ.com to a different address, however
there is a complication which is out of my control...

The server has been set up (out of my control) so that all e-mails are
getting rewritten by the server so that they appear to have been addressed
to whatever(_at_)ABC(_dot_)com
Thus if I send an e-mail to test(_at_)XYZ(_dot_)com it arrives at my procmail 
recipies
with headers like....

Received: from MYLOCATION with SMTP id SAA15742 for <test(_at_)XYZ(_dot_)com>; 
Sun, 12
Mar 2000 18:30:03 -0800 (PST)
From: "Simon Daykin" <Simon(_at_)Byte-Sized(_dot_)com>
To: "test" <test(_at_)ABC(_dot_)com>
Subject: test

This means that the SMTP server (or something) is rewriting the To: header
to send it to the main domain.
I am trying to write a procmail recipie to rewrite the mail back to it's
original format (or remove the fact that it is a fake IP)
So far I have the following which works but isn't right as it sends using an
incorrect To: field

#----------.procmailrc----------
SHELL=/bin/sh
XSENT="NO"

:0
* ^Received:.*\<for\>.*XYZ\.com
| (formail -k -X"From:" -X"Subject:" -X"To:" \
  -i"To: test(_at_)XYZ(_dot_)com") | $SENDMAIL -t
#-------------------

This catches the mails ok and removes all the headers and creates a new
"To:" header correctly, what I really want it to do is to reconstruct the To
field correctly.

in Perl I should be able to do something like...

if ($LINE =~ /^To:(.*)@ABC/ ) {
    $LINE =~ s/ABC/XYZ/;
}

Presumably something like this is easy to do using either procmail or
formail but I can't seem to get the right combination, can anyone help
please?

Thanks
Simon
   ____        _            ____  _             _
  | __ ) _   _| |_ ___     / ___|(_)_______  __| |  ___ ___  _ __ ___
  |  _ \| | | | __/ _ \____\___ \| |_  / _ \/ _` | / __/ _ \| '_ ` _ \
  | |_) | |_| | ||  __/_____|__) | |/ /  __/ (_| || (_| (_) | | | | | |
  |____/ \__, |\__\___|    |____/|_/___\___|\__,_(_)___\___/|_| |_| |_|
         |___/
E-Mail : Simon(_at_)Byte-Sized(_dot_)com           Web : 
http://www.Byte-Sized.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~





<Prev in Thread] Current Thread [Next in Thread>
  • Rewriting mails, Simon Daykin <=