about summary refs log tree commit homepage
path: root/lib/PublicInbox/Import.pm
diff options
context:
space:
mode:
authorEric Wong (Contractor, The Linux Foundation) <e@80x24.org>2018-04-18 09:13:10 +0000
committerEric Wong (Contractor, The Linux Foundation) <e@80x24.org>2018-04-18 09:14:14 +0000
commit69329215485cf2ab9d8cd1fa7faf65d8ec42dc0b (patch)
treedcf2a469711f8e61ce428f521d5e57d13a2e97c7 /lib/PublicInbox/Import.pm
parent2a49233ab00a366251974824658a20bf68e519da (diff)
downloadpublic-inbox-69329215485cf2ab9d8cd1fa7faf65d8ec42dc0b.tar.gz
While hunting duplicates, I noticed a leading '-' in some
Message-IDs as a result of RFC4648 encoding.  While '-' seems
allowed by RFC5322 and URL-friendly (RFC4648), they are uncommon
and make using Message-IDs as arguments for command-line tools
more difficult.  So prefix them with a datestamp to at least
give readers some sense of the age.  And shorten the "localhost"
hostname to "z" to save space.
Diffstat (limited to 'lib/PublicInbox/Import.pm')
-rw-r--r--lib/PublicInbox/Import.pm18
1 files changed, 10 insertions, 8 deletions
diff --git a/lib/PublicInbox/Import.pm b/lib/PublicInbox/Import.pm
index 9e8900f3..c7a96e1e 100644
--- a/lib/PublicInbox/Import.pm
+++ b/lib/PublicInbox/Import.pm
@@ -14,6 +14,7 @@ use PublicInbox::Address;
 use PublicInbox::MsgTime qw(msg_timestamp msg_datestamp);
 use PublicInbox::ContentId qw(content_digest);
 use PublicInbox::MDA;
+use POSIX qw(strftime);
 
 sub new {
         my ($class, $git, $name, $email, $ibx) = @_;
@@ -330,7 +331,7 @@ sub v1_mid0 ($) {
         my $mids = mids($hdr);
 
         if (!scalar(@$mids)) { # spam often has no Message-Id
-                my $mid0 = digest2mid(content_digest($mime));
+                my $mid0 = digest2mid(content_digest($mime), $hdr);
                 append_mid($hdr, $mid0);
                 return $mid0;
         }
@@ -445,18 +446,19 @@ sub atfork_child {
         }
 }
 
-sub digest2mid ($) {
-        my ($dig) = @_;
+sub digest2mid ($$) {
+        my ($dig, $hdr) = @_;
         my $b64 = $dig->clone->b64digest;
         # Make our own URLs nicer:
         # See "Base 64 Encoding with URL and Filename Safe Alphabet" in RFC4648
         $b64 =~ tr!+/=!-_!d;
 
-        # We can make this more meaningful with a date prefix or other things,
-        # but this is only needed for crap that fails to generate a Message-ID
-        # or reuses one.  In other words, it's usually spammers who hit this
-        # so they don't deserve nice Message-IDs :P
-        $b64 . '@localhost';
+        # Add a date prefix to prevent a leading '-' in case that trips
+        # up some tools (e.g. if a Message-ID were a expected as a
+        # command-line arg)
+        my $dt = msg_datestamp($hdr);
+        $dt = POSIX::strftime('%Y%m%d%H%M%S', gmtime($dt));
+        "$dt.$b64" . '@z';
 }
 
 sub clean_purge_buffer {