[Mimedefang] Making an md5 key of the body

Chris Myers chris at by-design.net
Tue Mar 27 12:10:40 EDT 2007

----- Original Message ----- 
From: "Danny Kj æ rgaard" <danny at resennet.dk>
To: <mimedefang at lists.roaringpenguin.com>
Sent: Tuesday, March 27, 2007 7:45 AM
Subject: [Mimedefang] Making an md5 key of the body

> Hi,
> I would like to make an md5 key of all bodys that comes throu my
> mailscanner. I'm writing these to the log. I have the followering in my
> filter()

Here's a code snippet that will calculate the hash of the message headers 
and message body, and give you bytecounts for headers and body as well.

Note that calculating the digest ($ctx->b64digest) resets the calculation 
process, the code below DOES NOT calculate a combined hash of the headers 
and body.

    if ( -e "./INPUTMSG" ) {
        my $totalsize = -s "./INPUTMSG";
        my $headersize = 0;
        my $ctx = Digest::SHA1->new;
        open(FILE, "<./INPUTMSG") && do {
            while (<FILE>) {
                $headersize += length;
                last if ( /^$/ );
            $header_hash = $ctx->b64digest;
            $body_hash = $ctx->b64digest;
            $body_length = $totalsize - $headersize;

Chris Myers
Networks By Design 

More information about the MIMEDefang mailing list