[Mimedefang] Header extraction question

Joseph Brennan brennan at columbia.edu
Sat Oct 10 22:07:56 EDT 2009



--On Friday, October 9, 2009 3:29 PM -0700 NFN Smith 
<worldoff9908 at mail.com> wrote:

> Is there a way of extracting headers of a message in mimedefang?
>
> What's up is that for messages submitted by my local users (authenticated
> connections), I'd like to get to the contents of User-Agent and X-Mailer
> headers.
>
> Initially I want to just do logging for some statistical analysis, but in
> the longer run, if it's possible, I'd like to be able to force rejections
> of exchanges coming from users that have unapproved mailers (e.g., old
> versions that are no longer supported by the developer).
>
> Is there a way of doing this?
>


We do this to get stats on what clients people are using.  And as long
as you're capturing header data at all, it's not too expensive to check
other interesting patterns in headers.

Joseph Brennan
Columbia University Information Technology



    %Header = '';


    # In the HEADERS file, any multiline headers have been rewritten to
    # be one line.  Received: is a typical example.  So here we do not
    # need to worry about continuation lines.
    #
    # Where there are multiple headers with the same name, what we do
    # here will overwrite and end up with the data for the last one.
    # If we want to collect them all we make a list like @Received.

    if (open(IN,"<./HEADERS")) {
        while(<IN>) {
            chomp;
            if (/^(\S+): (.*)/) {
                my $label = $1;
                my $data  = $2;
                $label = lc($label);
                $Header{$label} = $data;
                if ($label eq 'received') {
                    push(@Received,$data);
                }
            }
        }
    }
    close(IN);


    # We only test this once, so, ignoring autovivification...

    $Client = 'unknown';
    $Client = $Header{'x-mailer'} if $Header{'x-mailer'};
    $Client = $Header{'user-agent'} if $Header{'user-agent'};








More information about the MIMEDefang mailing list