#!/usr/bin/perl -w

##############################################################################
#
#	decodesubj.pl	-	This program gets all the subjects and processes
#				them through MIME::Words
#
#	Author		-	Steve Kordik <countzero@cyberdeck.org>
#
#
##############################################################################

BEGIN {
	$libpath = $0;
	$libpath =~ s!/[^/]+$!!;
	$libpath =~ s!/bin$!/lib/cscmail!;
	if (! -e $libpath) { die "Can't find required files in $libpath"; };
}

use lib "$libpath";
use lib "$libpath/modules/lib/perl5/site_perl/5.005";
use DBI;

require 'csclib.pl';
&read_prefs;

my $dbh=&open_db_conn;

$sql2= "update messages set subject = ? where id
= ?";
$query2=$dbh->prepare($sql2);

$sql = "select subject, id from messages";
$query = $dbh->prepare($sql);
$query->execute();
while (@row=$query->fetchrow_array()) {
	$row[0] = MIME::Words::decode_mimewords($row[0]);
	$query2->execute($row[0], $row[1]);
}
