X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FImport.pm;h=250a2db31e979054c94df5a0e1dd6ca2d8a5f883;hb=e350de7fdbe12dafc36e893e66ce8c93ec6dc3f2;hp=9e8900f3e6f86d2ce50576039654e75cad104120;hpb=dd80811bdaddc40520cb37abda23624674022e37;p=public-inbox.git diff --git a/lib/PublicInbox/Import.pm b/lib/PublicInbox/Import.pm index 9e8900f3..250a2db3 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) = @_; @@ -116,6 +117,9 @@ sub _cat_blob ($$$) { $n = read($r, my $lf, 1); defined($n) or die "read final byte of cat-blob failed: $!"; die "bad read on final byte: <$lf>" if $lf ne "\n"; + + # fixup some bugginess in old versions: + $buf =~ s/\A[\r\n]*From [^\r\n]*\r?\n//s; \$buf; } @@ -330,7 +334,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; } @@ -436,6 +440,8 @@ sub done { _update_git_info($self, 1) if delete $self->{nchg}; $self->lock_release; + + $self->{git}->cleanup; } sub atfork_child { @@ -445,18 +451,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 {