From 8eaa877179910dce156179e9025d1e0df34089d8 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 21 Sep 2021 07:41:50 +0000 Subject: lei_mail_sync: account for non-unique cases NNTP servers, IMAP servers, and various MUAs may recycle "unique" identifiers due to software bugs or careless BOFHs. Warn about them, but always be prepared to account for them. --- lib/PublicInbox/LeiImportKw.pm | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'lib/PublicInbox/LeiImportKw.pm') diff --git a/lib/PublicInbox/LeiImportKw.pm b/lib/PublicInbox/LeiImportKw.pm index 379101c2..21c93515 100644 --- a/lib/PublicInbox/LeiImportKw.pm +++ b/lib/PublicInbox/LeiImportKw.pm @@ -34,11 +34,15 @@ sub ipc_atfork_child { sub ck_update_kw { # via wq_io_do my ($self, $url, $uid, $kw) = @_; - my $oidbin = $self->{-lms_ro}->imap_oidbin($url, $uid) // return; - my @docids = $self->{over}->oidbin_exists($oidbin) or return; + my @oidbin = $self->{-lms_ro}->num_oidbin($url, $uid); + my $uid_url = "$url/;UID=$uid"; + @oidbin > 1 and $self->{lei}->err("W: $uid_url not unique:\n", + map { "\t".unpack('H*', $_)."\n" } @oidbin); + my %seen; + my @docids = sort { $a <=> $b } grep { !$seen{$_}++ } + map { $self->{over}->oidbin_exists($_) } @oidbin; $self->{lse}->kw_changed(undef, $kw, \@docids) or return; - $self->{verbose} and - $self->{lei}->qerr('# '.unpack('H*', $oidbin)." => @$kw\n"); + $self->{verbose} and $self->{lei}->qerr("# $uid_url => @$kw\n"); $self->{sto}->wq_do('set_eml_vmd', undef, { kw => $kw }, \@docids); } -- cgit v1.2.3-24-ge0c7