[Gllug] Procmail

tet at accucard.com tet at accucard.com
Mon Feb 25 10:45:23 UTC 2002


>I have all my mail from work forwarded to my internet mail address but
>because it goes through outlook it seems to strip some of the headers.

Unfortuantely, there's no way around this. Outlook (and/or Exchange)
sucks when it comes to doing the right thing with forwarded mail (or
indeed, with mail in general :-). Some versions of Outlook have a flag
to say "keep original mesasge intact" when forwarding. If yours does,
then use it. However, even with that flag set, it still screws up the
headers, preferring to place the original From and Subject lines as
quoted lines in the body, rather than in the header, and for mail from
people on the same Exchange server, it doesn't give you their email
address, only their name. When I had the misfortune to be in that
siutation in the past, I concocted the following procmail rules to
approximate doing the right thing. It assumes that mail from "Surname,
Firstname" can be delivered to firstname.surname at example.com, which is
usually a valid assumption with Exchange.

	:0
	* ^From:.*tethys at newsint
	{
		FROM_RE='^> From:[   ]*'
		SUBJ_RE='^> Subject:[   ]*'
		FROM=`egrep "$FROM_RE" | head -1 | sed -e "s/$FROM_RE//" \
			-f /h/tethys/etc/mungeaddr.sed`
		SUBJ=`egrep "$SUBJ_RE" | head -1 | sed "s/$SUBJ_RE//"`

		:0fW
		| formail -I "From: $FROM" -I "Subject: $SUBJ" \
			-A "X-MungedFrom: exchange"
	}

Forwarded mail arrives at my Unix box from an address matching
tethys at newsint. I then grep the body of the message to extract
the real from address and sender, and use formail to place them
in the header of the message. mungeaddr.sed is a file of sed
scripts that handle the broken From address from Exchange, with
a general regluar expression, plus a few special cases that the
general one didn't catch. I don't have the original any more,
but something like the following should work for you:

	s/^\([^,]*\), \([^ ]*\)/\1.\2 at colt-telecom.com/

>I receive the odd spam which automatically gets posted to my yahoo
>address and when I use fetchmail it comes down and procmail does not
>recognise it as such. I have tried to write it so that anything from
>paid4survey and a couple of others gets ditched but this string seems
>to get stripped from the headers when it comes via outlook.

Yep. If you use the above recipe, though, it should repopulate the header
with something you can later filter on.

Tet

-- 
Gllug mailing list  -  Gllug at linux.co.uk
http://list.ftech.net/mailman/listinfo/gllug




More information about the GLLUG mailing list