We have a header plugin that cleans up some invalid msgid headers (which
we've deemed more appropriate than passing them through only to have our
clients' exchange boxes remove them entirely), and adds a header based
on the date, pid, and increment since the connection started. It does a
bunch of other stuff and I don't have time to split it out and submit an
alternate patch now, but here are some snippets in case any of it seems
useful to you to integrate into your patch, or not:
use List::Util qw(first);
sub hook_data_post {
my ($self,$txn) = @_;
my $header = $txn->header;
# Replace all msgids with first non-empty, valid
# (or trivially fixed) msgid, if any
first { $header->add('Message-Id',"<$1>") if /(?:.*<)?([^<>\s]+)/ }
$header->delete('Message-Id');
...
my $cxn = $self->qp->connection;
$cxn->notes('msgid_count',($cxn->notes('msgid_count')||0) + 1);
my @time = gmtime;
$time[4]++; #month
$time[5] += 1900; #year
my $msgid = sprintf
#<yymmddhhmmss.pid.co...@hostname>
'<%d%02d%02d%02d%02d%02d.%d...@%s>',
reverse(@time[0..5]), # YYMMDDHHmmss
$$, # pid
$cxn->notes('msgid_count'), # count
$self->qp->config('me'); # hostname
Note that the first section of that code works in all the tests that
I've manufactured, but there have a couple of occasions where somehow a
header of 'Message-ID: <3[3' managed to get through and I don't know why
yet. Also note that one should be careful to fix up headers after
spamassassin and any other content-based scanner that care about headers
have scanned the message. Probably at some point it would be good for
content scanners to use, say, a Qpsmtpd::Transaction::original_message()
method that does $self->{_body_file}->seek(0,0) and then reads the whole
unmodified spooled message, so that you can muck around with headers in
any order without fear of screwing up your scans. I might be submitting
such a thing soonish.
-Jared
Robert Spier wrote:
This shouldn't be part of check_basicheaders. How about creating a
new plugin, add_messageid_if_missing (or something).
-R
David Nicol wrote:
Submitted for inclusion without restriction. These message IDs will
never duplicate nor repeat.
---------- Forwarded message ----------
From: <da...@hexaflexagon.nevermeta.com>
Date: Wed, Mar 18, 2009 at 5:21 PM
Subject: patch providing Message-Id creation feature for check_basicheaders
To: davidni...@gmail.com
--- /home/smtpd/plugins/check_basicheaders_original 2009-03-18
17:34:20.000000000 -0400
+++ /home/smtpd/plugins/check_basicheaders 2009-03-18
18:13:10.000000000 -0400
@@ -40,6 +40,8 @@
}
}
+my $SMTPIN = 'SMTPIN';
+
sub hook_data_post {
my ($self, $transaction) = @_;
@@ -66,5 +68,12 @@
return (DENY, "The Date in the header was too far in the future")
if $ts > time + ($self->{_days}*24*3600);
+ unless ($transaction->header->get('Message-Id')){
+ my $me = $self->qp->config('me');
+ my $newMID =
time()."-$me-$$".$SMTPIN++.rand(99999).'@'.($self->qp->connection->remote_ip);
+ $self->log(LOGINFO, "new Message-Id: $newMID");
+ $transaction->header->add('Message-Id', $newMID);
+ };
+
return (DECLINED);
}