From e04285eee2c93a0b5ba6659098260e42a0995d8c Mon Sep 17 00:00:00 2001 From: Giovanni Bechis Date: Fri, 31 May 2024 22:08:55 +0200 Subject: [PATCH] create an email message with a proper Message-ID (#236) --- lib/Mail/DMARC/Report/Send/SMTP.pm | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/Mail/DMARC/Report/Send/SMTP.pm b/lib/Mail/DMARC/Report/Send/SMTP.pm index 73636893..affab930 100644 --- a/lib/Mail/DMARC/Report/Send/SMTP.pm +++ b/lib/Mail/DMARC/Report/Send/SMTP.pm @@ -175,6 +175,7 @@ sub assemble_message_object { ], parts => [@parts], ) or croak "unable to assemble message\n"; + $email->header_str_set( 'Message-ID' => $self->get_message_id ); return $email; } @@ -196,6 +197,24 @@ sub get_helo_hostname { return Sys::Hostname::hostname; }; +sub get_message_id { + my $self = shift; + my $host = $self->get_helo_hostname; + + my ($ss, $mm, $hh, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(time); + + # Generate a "random" Message-ID + return sprintf("<%04d%02d%02d%02d%02d.%s\@%s>\n", + $year + 1900, + $mon + 1, + $mday, + $hh, + $mm, + rand(), + $host + ); +} + 1; __END__