#!/usr/bin/perl
require 'prontolib.pl';
read_prefs();
$conn = &open_db_conn;
$sql = "select id from messages";
$query = $conn->prepare($sql);
$query->execute();
$count = 0;
while (($msgid) = $query->fetchrow_array()) {
$tmp = filename_to_tree("$prefs{'MailDir'}/$msgid");
open(TMP,"<$tmp");
while (<TMP>) {
if (/^References:\s*(.+)/i) { print ("message: $msgid has ref $1\n");
$sql = "update messages set ref = '$1' where id = '$msgid'";
$conn->do($sql);
$count++
  
  }

}

close(TMP);
}
print $count . "messages updated\n";
#$sql = "update messages set inreplyto = '' where inreplyto is NULL";
#$conn->do($sql);
