procmail
[Top] [All Lists]

Re: Verify Mail Has Valid 'From:' Field?

1997-12-19 23:03:05
On Thu, 18 Dec 1997 rsr(_at_)macromedia(_dot_)com wrote:
Has anyone figured out how to do a sanity check on mail to make
sure it's coming from a valid domain name? I'm thinking of
something that would
A) Take the 'From:' line;
B) Strip out everything but the TLD (rsr(_at_)host(_dot_)macromedia(_dot_)com 
->
macromedia.com)
C) Verify that the TLD is valid

Just did the exact thing you're talking about today:

a) and b): a little formail magic:

        FROMDOMAIN=`formail -rzxTo: | sed -e 's/.*@//'`

This needs some explaination. The formail is a little bit hokey, but it
works; essentially, we're generating a reply (-r) to the message in
question, which creates a "To:" line with -only- the email address in it
(no name, comments, etc). The '-x' asks for that new To: line to be
printed (minus the 'To:' part), and the '-z' strips the leading whitespace
in front of the address.

The sed part is child's play: essentially, yank off everything in front of
the '@' (as well as yanking the '@' too). The end result is that you have
only the domain left in FROMDOMAIN, which you can now beat away at. :-)

The solution to c) above required a bit of work. QMail has a program with
it called 'dnsmxip' which is perfectly suited to this task (it takes a
domain as an arguement, and returns either the A or MX record's IP
address, if one exists, or an error). You could probably use nslookup or
dig to do the same thing, though.

Hope this helps!

-- 
  ____ ______ _____
_/ __ \  ___//     \  Edward S. Marshall <emarshal(_at_)logic(_dot_)net>
\  ___/___ \|  | |  \ http://www.logic.net/~emarshal/
 \____\_____>__|_|__/ Information Systems Manager, Logical Solutions

[  Are you a spammer looking for a great opportunity to be blacklisted? Then  ]
[ have your automatic bots email spam(_at_)logic(_dot_)net and secure a spot on 
my list! ]

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