#!/usr/bin/perl -i
#this is MHonArc Filter
#works on MHonArc generated outputs
#seraches for "keywords" and "description" variables
#and set both to the subject
#give me a list of input files...

BEGIN {
 $keywords = undef;
 $description = undef;
 $info = "Steffens Workspace - Technical Knowledgebase";
}

while($line = <>) {
    if ($line =~ m/<!--\s*X-Subject:\s*(.+)-->\s*$/i) {
        $description = $info . ": " . $1;
        #format to comma separated list:
        $key = $1;
        @keys=split(/[\s,]+/, $key);
        $key=join(", ", @keys, "SWS", $info);
        $keywords=$key;
    }
    if ((defined $keywords) || (defined $description)) {
        if ($line =~ s/(
            <!--\#set\s+var="keywords"\s+
                value=")
                [^"]*
                ("\s*-->)
                /$1$keywords$2/ix) {
                $keywords = undef;
        }
        if ($line =~ s/(
            <!--\#set\s+var="description"\s+
                value=")
                [^"]*
                ("\s*-->)
                /$1$description$2/ix) {
                $description = undef;
        }
    }
    print $line;
}    

