From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id B8A5C1F42D for ; Mon, 19 Mar 2018 08:15:02 +0000 (UTC) From: "Eric Wong (Contractor, The Linux Foundation)" To: meta@public-inbox.org Subject: [PATCH 13/27] watchmaildir: use content_digest to generate Message-Id Date: Mon, 19 Mar 2018 08:14:45 +0000 Message-Id: <20180319081459.10645-14-e@80x24.org> In-Reply-To: <20180319081459.10645-1-e@80x24.org> References: <20180319081459.10645-1-e@80x24.org> List-Id: This can probably be moved to Import for code reuse. --- lib/PublicInbox/WatchMaildir.pm | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/lib/PublicInbox/WatchMaildir.pm b/lib/PublicInbox/WatchMaildir.pm index c72d939..f2d3db9 100644 --- a/lib/PublicInbox/WatchMaildir.pm +++ b/lib/PublicInbox/WatchMaildir.pm @@ -12,6 +12,8 @@ use PublicInbox::Import; use PublicInbox::MDA; use PublicInbox::Spawn qw(spawn); use File::Temp qw//; +use PublicInbox::MID qw(mids); +use PublicInbox::ContentId qw(content_digest); sub new { my ($class, $config) = @_; @@ -144,25 +146,14 @@ sub _remove_spam { }) } -# used to hash the relevant portions of a message when there are conflicts -sub _hash_mime2 { - my ($mime) = @_; - require Digest::SHA; - my $dig = Digest::SHA->new('SHA-1'); - $dig->add($mime->header_obj->header_raw('Subject')); - $dig->add($mime->body_raw); - $dig->hexdigest; -} - sub _force_mid { my ($mime) = @_; - # probably a bad idea, but we inject a Message-Id if - # one is missing, here.. - my $mid = $mime->header_obj->header_raw('Message-Id'); - if (!defined $mid || $mid =~ /\A\s*\z/) { - $mid = '<' . _hash_mime2($mime) . '@generated>'; - $mime->header_set('Message-Id', $mid); - } + my $hdr = $mime->header_obj; + my $mids = mids($hdr); + return if @$mids; + my $dig = content_digest($mime); + my $mid = $dig->clone->hexdigest . '@localhost'; + $hdr->header_set('Message-Id', $mid); } sub _try_path { -- EW