home *** CD-ROM | disk | FTP | other *** search
/ Australian Personal Computer 2004 July / APC0407D1.iso / powerkit / spam / files / Outclass1.2.4.1r.exe / æ / outclassify.pl < prev    next >
Encoding:
Perl Script  |  2004-05-16  |  4.0 KB  |  164 lines

  1. #!/usr/bin/perl
  2. # ---------------------------------------------------------------------------------------------
  3. #
  4. # outclassify.pl --- A mail classification engine for Outclass to speak to POPFile 0.21.0
  5. #
  6. # Copyright (c) 2003 Ashit Gandhi
  7. # modified by Marc Brooks <lucis@fehq.org> for POPFile 0.21.0
  8. #
  9. # ---------------------------------------------------------------------------------------------
  10.  
  11. use strict;
  12. use Classifier::Bayes;
  13. use Classifier::WordMangle;
  14. use POPFile::Configuration;
  15. use POPFile::MQ;
  16. use POPFile::Logger;
  17.  
  18. my $engine;
  19. my $config;
  20. my $logger;
  21. my $mq;
  22. my $wm;
  23. my $session;
  24.  
  25. sub init
  26. {
  27.     $config = new POPFile::Configuration;
  28.     $mq = new POPFile::MQ;
  29.     $logger = new POPFile::Logger;
  30.     $engine = new Classifier::Bayes;
  31.     $wm = new Classifier::WordMangle;
  32.     $config->configuration( $config );
  33.     $config->mq( $mq );
  34.     $config->logger( $logger );
  35.     
  36.     $config->initialize();
  37.     
  38.     $logger->configuration( $config );
  39.     $logger->mq( $mq );
  40.     $logger->logger( $logger );
  41.     
  42.     $logger->initialize();
  43.     
  44.     $wm->configuration( $config );
  45.     $wm->mq( $mq );
  46.     $wm->logger( $logger );
  47.     $wm->start();   
  48.  
  49.     $mq->configuration( $config );
  50.     $mq->mq( $mq );
  51.     $mq->logger( $logger );
  52.     
  53.     $engine->configuration( $config );
  54.     $engine->mq( $mq );
  55.     $engine->logger( $logger );
  56.     
  57.     $engine->{parser__}->mangle( $wm );
  58.  
  59.     $engine->initialize();
  60.     
  61.     $config->load_configuration();
  62.     
  63.     $engine->start();
  64.     
  65.     $session = $engine->get_session_key('admin', '');
  66. }
  67.  
  68. # main
  69.  
  70. my $inp = "";
  71. my $cmd = "";
  72. my $arg1 = "";
  73. my $arg2 = "";
  74. my $messagetype = "";
  75.  
  76. select(STDOUT);
  77. $| = 1;
  78.  
  79. print "Outclass Engine Starting up...\n";
  80.  
  81. print "Initializing Bayes filter...\n";
  82. init();
  83.  
  84. print "Outclass Engine Ready.\n";
  85.  
  86. while(1)
  87. {
  88.     print "\n+OK\n";
  89.     $inp = <>;
  90.     chop($inp);
  91.     ($cmd, $arg1, $arg2) = split(/=/, $inp);
  92.  
  93. #    print "$cmd\n";
  94.  
  95.     if($cmd eq "classify" && length($arg1) > 0)
  96.     {
  97.                 $messagetype = $engine->classify($session, $arg1);
  98.                 $engine->classified($session, $messagetype);
  99.                 print  "$messagetype\n";
  100.     }
  101.     elsif($cmd eq "insert" && length($arg1) > 0 && length($arg2) > 0)
  102.     {
  103.         print("Classify $arg2 as $arg1\n");
  104.         $engine->create_bucket($session, $arg1);
  105.         $engine->add_message_to_bucket($session, $arg1, $arg2);
  106.                 $engine->classified($session, $arg1);
  107.  
  108.     }
  109.     elsif($cmd eq "save" && length($arg1) > 0)
  110.     {
  111.         # Not required to do anything for 19.0
  112.     }
  113.     elsif($cmd eq "htmlview" && length($arg1) > 0)
  114.     {
  115. #         $engine->{parser__}->{quickmagnets__} = {};
  116. #         print scalar(keys %{$engine->{parser__}->quickmagnets()}) . "<<<<\n";
  117. #         print $engine->{parser__}->quickmagnets() . " <---\n";
  118. #         my $classification = $engine->classify_file($arg1, $htmlui);
  119. #         my $score = $engine->scores();
  120. #         my $htmltext = $engine->get_html_colored_message($arg1);
  121. #         
  122. #         my $buckettext = "";
  123. #         foreach $b ($engine->get_buckets())
  124. #         {
  125. #             $buckettext .= "<tt><b><font";
  126. #             if($b eq $classification)
  127. #             {
  128. #                 $buckettext .= " size=+2";
  129. #             }
  130. #             $buckettext .= " color=" . $engine->get_bucket_color($b) . ">$b</font></b></tt><br>\n";
  131. #         }
  132.  
  133. #         # htmlview=C:\DOCUME~2\Vargon\LOCALS~1\Temp\1B440D4C-035A-4F60-BF4B-A80D0542CEE0.txt
  134. #         my $TEMPFILE = $ENV{"TEMP"} . "\OutclassViewfile.htm";
  135. #         open(MYOUTFILE, ">$TEMPFILE");
  136. #         print MYOUTFILE $buckettext;
  137. #         print MYOUTFILE "<hr>\n";
  138. #         print MYOUTFILE $score;
  139. #         print MYOUTFILE "<hr>\n";
  140. #         print MYOUTFILE $htmltext;
  141. #         close(MYOUTFILE);
  142.  
  143. #         system("start", "$TEMPFILE");
  144.     }
  145.     elsif($cmd eq "quit")
  146.     {
  147.                 $engine->release_session_key( $session );
  148.                 $engine->stop();
  149.                 $logger->stop();
  150.                 $mq->stop();
  151.                 $config->stop();
  152.                
  153.                 exit 0;
  154.     }
  155.     elsif(length($cmd) == 0)
  156.     {
  157.         #do nothing
  158.     }
  159.     else
  160.     {
  161.         print "ERROR: Unknown Command: '$cmd, $arg1, $arg2'\n";
  162.     }
  163. }
  164.