From: epg Date: Thu, 17 Apr 2014 04:46:55 +0000 (-0700) Subject: quick hack to update a db mapping message-id to message file names X-Git-Url: https://diplodocus.org/git/minc/commitdiff_plain/53237e78cea6b9432f4f0fdc5c640dbeacd0ce16 quick hack to update a db mapping message-id to message file names --- diff --git a/msgiddb b/msgiddb new file mode 100644 index 0000000..a5ff9bf --- /dev/null +++ b/msgiddb @@ -0,0 +1,73 @@ +#!/usr/local/bin/perl + +=head1 NAME + +B - update database mapping Message-ID to message file names + +=head1 SYNOPSIS + +B I I + +=head1 DESCRIPTION + +For each I, read its Message-ID and use as key in I. +Check for its presence in the JSON-serialized list stored as the value; +if absent, append and update the db. + +For messages with multiple Message-ID fields, concatenate all the values and use +that as the key. + +I names are used exactly; no path components are stripped. + +=cut + +use strict; +use warnings; +use v5.14; + +use DB_File; +use JSON::PP; +use List::Util 'first'; + +use FindBin; +use lib $FindBin::Bin; + +require 'minc'; + +sub push_dblist { + my $db = shift; + my $key = shift; + my $value = shift; + my $current_value = $db->{$key}; + my $values; + if ($current_value) { + $values = decode_json($current_value); + if ( first { defined($_) } @$values ) { + return; + } + } + else { + my @tmp; + $values = \@tmp; + } + push( @$values, $value ); + $db->{$key} = encode_json($values); +} + +if ( !caller() ) { + my $dbfn = shift; + tie( my %db, 'DB_File', $dbfn ) or die("tie(DB_File, $dbfn): $!"); + + my $errors = 0; + for my $fn (@ARGV) { + my $msgids = get_headers($fn)->{'message-id'}; + if ( !( defined($msgids) && @$msgids ) ) { + say STDERR "$fn has no message-id"; + $errors++; + next; + } + my $msgid = join( '', @$msgids ); + push_dblist( \%db, $msgid, $fn ); + } + exit($errors); +}