Change Message-ID in sendmail

emailsendmail

We have determined that a piece of external software generates emails with the same Message-ID field. This software uses sendmail to perform the actual sending.

Since it is not very easy for us to change that external software to fix the bug, I would like to know if it is possible to make sendmail ignore the given Message-ID and generate a new one?

EXTRA-INFO:

I have found some documentation confirming my fears:

Header flags only control header insertion . If a header is received in the input, it is passed to the output, regardless of the flag settings.

See http://docstore.mik.ua/orelly/networking/tcpip/ch10_05.htm, section 10.5.7 Defining Mail Headers

Best Answer

if you're open to using a different MTA or at least an intermediate MTA, have a look at qpsmtpd. i currently use qpsmtpd to convert incoming uuencoded emails from some legacy apps we use to MIME.

here's what i use, which is a modified version of the tnef2mime plugin (so please ignore any extra cruft and references to tnef2mime). this could be easily modified to remove the existing message-id header and add a new one.

#!/usr/bin/perl -wT

use MIME::Parser;
use MIME::Entity;
use MIME::Head;
use File::MMagic;
use Convert::TNEF;

my $parser;
my $ent;
my $tmpdir='/var/spool/qpsmtpd';
my $count=0;
my $foundtnef=0;
my (@attachments, @blocked, @tnefs);

sub register {
  my ($self, $qp, %arg) = @_;
  $self->register_hook("data_post", "tnef2mime");
}

sub tnef2mime ( $$ )
        {
        my ($self, $transaction) = @_;
        # new Parser Object
        $parser = new MIME::Parser;
        # temp output directory
        $parser->output_under( $tmpdir );
        $parser->extract_uuencode(1);

        # read message body
        open BFN, $transaction->body_filename();
        $ent = $parser->parse(\*BFN);
        close BFN;

        my $founduu = $ent->parts && !$transaction->header->get('MIME-Version');

        if( $founduu )
                {
                $transaction->header->add('MIME-Version', "1.0" );
                my $xac = "UUENCODE -> MIME";
                $self->log(LOGDEBUG, "uuencoded attachment converted to MIME" );
                $transaction->header->add('X-TNEF2MIME-Plugin', $xac );

                # fix content-type header
                $transaction->header->delete('Content-Type');
                $transaction->header->add('Content-Type', $ent->head->get('Content-Type'));

                # write converted message body
                open BFN, ">" . $transaction->body_filename();
                $ent->print(\*BFN);
                close BFN;

                }


        my $output_dir = $parser->output_dir;

        opendir( DIR, $output_dir ) or die "Could not open temporary output dir $output_dir: $!\n";
        while( defined( my $file = readdir( DIR ) ) )
                {
                next if $file =~ /^\.\.?$/;
                $file =~ s/(^.*$)//;
                $file = $1;
                unlink( "$output_dir/$file" );
                }
        closedir( DIR );
        rmdir( $output_dir );

        return DECLINED;
        }
Related Topic