From 53237e78cea6b9432f4f0fdc5c640dbeacd0ce16 Mon Sep 17 00:00:00 2001 From: epg Date: Wed, 16 Apr 2014 21:46:55 -0700 Subject: [PATCH] quick hack to update a db mapping message-id to message file names --- msgiddb | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 msgiddb 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); +} -- 2.56.0