script/public-inbox.cgi
scripts/dc-dlvr
scripts/dc-dlvr.pre
+scripts/dupe-finder
scripts/edit-sa-prefs
scripts/import_maildir
scripts/import_slrnspool
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) = @_;
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;
}
}
}
-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 {
my $hdr = $mime->header_obj;
my $dig = content_digest($mime);
- $$mid0 = PublicInbox::Import::digest2mid($dig);
+ $$mid0 = PublicInbox::Import::digest2mid($dig, $hdr);
my $num = $self->{mm}->mid_insert($$mid0);
unless (defined $num) {
# it's hard to spoof the last Received: header
my @recvd = $hdr->header_raw('Received');
$dig->add("Received: $_") foreach (@recvd);
- $$mid0 = PublicInbox::Import::digest2mid($dig);
+ $$mid0 = PublicInbox::Import::digest2mid($dig, $hdr);
$num = $self->{mm}->mid_insert($$mid0);
# fall back to a random Message-ID and give up determinism:
until (defined($num)) {
$dig->add(rand);
- $$mid0 = PublicInbox::Import::digest2mid($dig);
+ $$mid0 = PublicInbox::Import::digest2mid($dig, $hdr);
warn "using random Message-ID <$$mid0> as fallback\n";
$num = $self->{mm}->mid_insert($$mid0);
}
--- /dev/null
+#!/usr/bin/perl -w
+# Copyright (C) 2018 all contributors <meta@public-inbox.org>
+# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
+#
+# ad-hoc tool for finding duplicates, unstable!
+use strict;
+use warnings;
+use PublicInbox::Inbox;
+use PublicInbox::Over;
+use PublicInbox::Search;
+use PublicInbox::Config;
+my $repo = shift;
+my $ibx;
+if (index($repo, '@') > 0) {
+ $ibx = PublicInbox::Config->new->lookup($repo);
+} elsif (-d $repo) {
+ $ibx = { mainrepo => $repo, address => 'unnamed@example.com' };
+ $ibx = PublicInbox::Inbox->new($ibx);
+} else {
+ $ibx = PublicInbox::Config->new->lookup_name($repo);
+}
+$ibx or die "No inbox";
+$ibx->search or die "search not available for inbox";
+my $dbh = $ibx->search->{over_ro}->connect;
+my $over = PublicInbox::Over->new($dbh->sqlite_db_filename);
+
+sub emit ($) {
+ my ($nums) = @_;
+ foreach my $n (@$nums) {
+ my $smsg = $over->get_art($n) or next;
+ print STDERR "$n $smsg->{blob} $smsg->{mid}\n";
+ my $msg = $ibx->msg_by_smsg($smsg) or next;
+ print "From $smsg->{blob}\@$n Thu Jan 1 00:00:00 1970\n";
+ $$msg =~ s/^(>*From )/>$1/gm;
+ print $$msg, "\n";
+ }
+}
+
+my $sth = $dbh->prepare(<<'');
+SELECT id,num FROM id2num WHERE num > 0 ORDER BY id
+
+$sth->execute;
+my $prev_id = -1;
+my ($id, $num, @nums);
+while (1) {
+ ($id, $num) = $sth->fetchrow_array;
+ defined $id or last;
+ if ($prev_id != $id) {
+ emit(\@nums) if scalar(@nums) > 1;
+ @nums = ();
+ }
+ $prev_id = $id;
+ push @nums, $num;
+}
[ $sec->header_obj->header_raw('Message-Id') ],
'no new Message-Id added');
- my $sane_mid = qr/\A<[\w\-]+\@localhost>\z/;
+ my $sane_mid = qr/\A<[\w\-\.]+\@\w+>\z/;
@warn = ();
$mime->header_set('Message-Id', '<a-mid@b>');
$mime->body_set('different');
@warn = ();
$mime->header_set('Message-Id', '<a-mid@b>');
$mime->body_set('this one needs a random mid');
- my $gen = PublicInbox::Import::digest2mid(content_digest($mime));
+ my $hdr = $mime->header_obj;
+ my $gen = PublicInbox::Import::digest2mid(content_digest($mime), $hdr);
unlike($gen, qr![\+/=]!, 'no URL-unfriendly chars in Message-Id');
my $fake = PublicInbox::MIME->new($mime->as_string);
$fake->header_set('Message-Id', "<$gen>");