home *** CD-ROM | disk | FTP | other *** search
- #!/usr/bin/perl
- # ---------------------------------------------------------------------------------------------
- #
- # outclassify.pl --- A mail classification engine for Outclass to speak to POPFile 0.21.0
- #
- # Copyright (c) 2003 Ashit Gandhi
- # modified by Marc Brooks <lucis@fehq.org> for POPFile 0.21.0
- #
- # ---------------------------------------------------------------------------------------------
-
- use strict;
- use Classifier::Bayes;
- use Classifier::WordMangle;
- use POPFile::Configuration;
- use POPFile::MQ;
- use POPFile::Logger;
-
- my $engine;
- my $config;
- my $logger;
- my $mq;
- my $wm;
- my $session;
-
- sub init
- {
- $config = new POPFile::Configuration;
- $mq = new POPFile::MQ;
- $logger = new POPFile::Logger;
- $engine = new Classifier::Bayes;
- $wm = new Classifier::WordMangle;
- $config->configuration( $config );
- $config->mq( $mq );
- $config->logger( $logger );
-
- $config->initialize();
-
- $logger->configuration( $config );
- $logger->mq( $mq );
- $logger->logger( $logger );
-
- $logger->initialize();
-
- $wm->configuration( $config );
- $wm->mq( $mq );
- $wm->logger( $logger );
- $wm->start();
-
- $mq->configuration( $config );
- $mq->mq( $mq );
- $mq->logger( $logger );
-
- $engine->configuration( $config );
- $engine->mq( $mq );
- $engine->logger( $logger );
-
- $engine->{parser__}->mangle( $wm );
-
- $engine->initialize();
-
- $config->load_configuration();
-
- $engine->start();
-
- $session = $engine->get_session_key('admin', '');
- }
-
- # main
-
- my $inp = "";
- my $cmd = "";
- my $arg1 = "";
- my $arg2 = "";
- my $messagetype = "";
-
- select(STDOUT);
- $| = 1;
-
- print "Outclass Engine Starting up...\n";
-
- print "Initializing Bayes filter...\n";
- init();
-
- print "Outclass Engine Ready.\n";
-
- while(1)
- {
- print "\n+OK\n";
- $inp = <>;
- chop($inp);
- ($cmd, $arg1, $arg2) = split(/=/, $inp);
-
- # print "$cmd\n";
-
- if($cmd eq "classify" && length($arg1) > 0)
- {
- $messagetype = $engine->classify($session, $arg1);
- $engine->classified($session, $messagetype);
- print "$messagetype\n";
- }
- elsif($cmd eq "insert" && length($arg1) > 0 && length($arg2) > 0)
- {
- print("Classify $arg2 as $arg1\n");
- $engine->create_bucket($session, $arg1);
- $engine->add_message_to_bucket($session, $arg1, $arg2);
- $engine->classified($session, $arg1);
-
- }
- elsif($cmd eq "save" && length($arg1) > 0)
- {
- # Not required to do anything for 19.0
- }
- elsif($cmd eq "htmlview" && length($arg1) > 0)
- {
- # $engine->{parser__}->{quickmagnets__} = {};
- # print scalar(keys %{$engine->{parser__}->quickmagnets()}) . "<<<<\n";
- # print $engine->{parser__}->quickmagnets() . " <---\n";
- # my $classification = $engine->classify_file($arg1, $htmlui);
- # my $score = $engine->scores();
- # my $htmltext = $engine->get_html_colored_message($arg1);
- #
- # my $buckettext = "";
- # foreach $b ($engine->get_buckets())
- # {
- # $buckettext .= "<tt><b><font";
- # if($b eq $classification)
- # {
- # $buckettext .= " size=+2";
- # }
- # $buckettext .= " color=" . $engine->get_bucket_color($b) . ">$b</font></b></tt><br>\n";
- # }
-
- # # htmlview=C:\DOCUME~2\Vargon\LOCALS~1\Temp\1B440D4C-035A-4F60-BF4B-A80D0542CEE0.txt
- # my $TEMPFILE = $ENV{"TEMP"} . "\OutclassViewfile.htm";
- # open(MYOUTFILE, ">$TEMPFILE");
- # print MYOUTFILE $buckettext;
- # print MYOUTFILE "<hr>\n";
- # print MYOUTFILE $score;
- # print MYOUTFILE "<hr>\n";
- # print MYOUTFILE $htmltext;
- # close(MYOUTFILE);
-
- # system("start", "$TEMPFILE");
- }
- elsif($cmd eq "quit")
- {
- $engine->release_session_key( $session );
- $engine->stop();
- $logger->stop();
- $mq->stop();
- $config->stop();
-
- exit 0;
- }
- elsif(length($cmd) == 0)
- {
- #do nothing
- }
- else
- {
- print "ERROR: Unknown Command: '$cmd, $arg1, $arg2'\n";
- }
- }
-