about summary refs log tree commit homepage
diff options
context:
space:
mode:
-rw-r--r--lib/PublicInbox/Import.pm11
-rw-r--r--t/v2writable.t10
2 files changed, 16 insertions, 5 deletions
diff --git a/lib/PublicInbox/Import.pm b/lib/PublicInbox/Import.pm
index 4c007b61..77e74c13 100644
--- a/lib/PublicInbox/Import.pm
+++ b/lib/PublicInbox/Import.pm
@@ -401,7 +401,16 @@ sub atfork_child {
 
 sub digest2mid ($) {
         my ($dig) = @_;
-        $dig->clone->hexdigest . '@localhost';
+        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';
 }
 
 1;
diff --git a/t/v2writable.t b/t/v2writable.t
index c6bcefd4..bbe6d14b 100644
--- a/t/v2writable.t
+++ b/t/v2writable.t
@@ -68,6 +68,7 @@ if ('ensure git configs are correct') {
                 [ $mime->header_obj->header_raw('Message-Id') ],
                 'no new Message-Id added');
 
+        my $sane_mid = qr/\A<[\w\-]+\@localhost>\z/;
         @warn = ();
         $mime->header_set('Message-Id', '<a-mid@b>');
         $mime->body_set('different');
@@ -75,13 +76,14 @@ if ('ensure git configs are correct') {
         like(join(' ', @warn), qr/reused/, 'warned about reused MID');
         my @mids = $mime->header_obj->header_raw('Message-Id');
         is($mids[1], '<a-mid@b>', 'original mid not changed');
-        like($mids[0], qr/\A<\w+\@localhost>\z/, 'new MID added');
+        like($mids[0], $sane_mid, 'new MID added');
         is(scalar(@mids), 2, 'only one new MID added');
 
         @warn = ();
         $mime->header_set('Message-Id', '<a-mid@b>');
         $mime->body_set('this one needs a random mid');
-        my $gen = content_digest($mime)->hexdigest . '@localhost';
+        my $gen = PublicInbox::Import::digest2mid(content_digest($mime));
+        unlike($gen, qr![\+/=]!, 'no URL-unfriendly chars in Message-Id');
         my $fake = PublicInbox::MIME->new($mime->as_string);
         $fake->header_set('Message-Id', $gen);
         ok($im->add($fake), 'fake added easily');
@@ -90,14 +92,14 @@ if ('ensure git configs are correct') {
         like(join(' ', @warn), qr/using random/, 'warned about using random');
         @mids = $mime->header_obj->header_raw('Message-Id');
         is($mids[1], '<a-mid@b>', 'original mid not changed');
-        like($mids[0], qr/\A<\w+\@localhost>\z/, 'new MID added');
+        like($mids[0], $sane_mid, 'new MID added');
         is(scalar(@mids), 2, 'only one new MID added');
 
         @warn = ();
         $mime->header_set('Message-Id');
         ok($im->add($mime), 'random MID made for MID free message');
         @mids = $mime->header_obj->header_raw('Message-Id');
-        like($mids[0], qr/\A<\w+\@localhost>\z/, 'mid was generated');
+        like($mids[0], $sane_mid, 'mid was generated');
         is(scalar(@mids), 1, 'new generated');
 }