Package org.jasen.core

Examples of org.jasen.core.StandardScanResult


     * @return The results of the scan as a JasenScanResult
     * @throws JasenException
     */
    public JasenScanResult scan(MimeMessage mm, JasenMessage message, float threshold, String[] ignored) throws JasenException {

        StandardScanResult result = null;
        ReceivedHeaderParser parser = null;

        try
        {
            // Create a result instance
            result = (StandardScanResult) scanResultClass.newInstance();

            // and a mimeParser
            parser = (ReceivedHeaderParser) headerParserClass.newInstance();

        }
        catch (InstantiationException e)
        {
            throw new JasenException(e);
        }
        catch (IllegalAccessException e)
        {
            throw new JasenException(e);
        }

        //  Wrap the message so we can capture mimeParser data and store tokenized text
        JasenMessageWrapper wrapper = new JasenMessageWrapper(message);

        wrapper.setEngine(this);

        // Parse the HTML part and extract the tokens
        SpamHTMLParser htmlParser = new SpamHTMLParser();

        // Now, tokenize the html and text parts of the message
        ParserData parserData = htmlParser.parse(mm, wrapper, tokenizer);

        // Now, loop through the plugins in order and test...
        if(plugins != null) {

            PluginContainer container = null;
            JasenTestResult pluginResult = null;

            double[] probabilities = new double[plugins.size()];
            double[] pointProbabilities = null;
            int points = 0;
            float min = 0.0f;
            float max = 0.0f;
            int pointThreshold = 1;
            float prob = 0.5f;
            double finalProbability = 0.5d;
            boolean thresholdReached = false;

            String[][] testResults = new String[plugins.size()][4];

            long time;
           
            // Ensure the ignore list is sorted for the binary search
            if(ignored != null) {
                Arrays.sort(ignored);
            }

            for (int i = 0; i < plugins.size(); i++)
            {
                time = System.currentTimeMillis();

                container = (PluginContainer)plugins.get(i);
               
                // Determine if we should ignore this plugin
                if(ignored != null && ignored.length > 0 && Arrays.binarySearch(ignored, container.getName()) > -1) {
                    probabilities[i] =  JasenEngineConfiguration.getInstance().getGuess();
                   
                    testResults[i][RESULT_INDEX_PROBABILITY] = String.valueOf(probabilities[i])
                    testResults[i][RESULT_INDEX_TIME] = "0";
                    testResults[i][RESULT_INDEX_NAME] = container.getName();
                    testResults[i][RESULT_INDEX_PROBABILITY] = container.getDisplayName();
                }
                else
                {
                    try
                    {
                        pluginResult = container.getPlugin().test(this, mm, wrapper, parserData, parser);
                    }
                    catch (JasenException e)
                    {
                        // We couldn't execute this plugin... record the error and continue
                        ErrorHandlerBroker.getInstance().getErrorHandler().handleException(e);

                        probabilities[i] = JasenEngineConfiguration.getInstance().getGuess();
                    }

                    testResults[i][RESULT_INDEX_NAME] = container.getName();
                    testResults[i][RESULT_INDEX_DISPLAY] = container.getDisplayName();

                    if(pluginResult != null) {
                        if(pluginResult.isAbsolute()) {
                            // We know it's definately spam
                            result.setProbability(1.0d);

                            testResults[i][RESULT_INDEX_PROBABILITY] = "1.0";

                            // Stop processing here
                            return result;
                        }
                        else
                        {
                            probabilities[i] = pluginResult.calculateProbability();
                            testResults[i][RESULT_INDEX_PROBABILITY] = String.valueOf(probabilities[i]);
                        }
                    }
                    else
                    {
                        throw new JasenException("JasenTestResult cannot be null");
                    }

                    // If we have a threshold, compute now
                    if(threshold != NO_THRESHOLD) {
                        finalProbability = calculate(probabilities, 0, i+1);

                        if(finalProbability >= threshold) {
                            thresholdReached = true;
                            break;
                        }
                    }                     
                }

                testResults[i][RESULT_INDEX_TIME] = String.valueOf(System.currentTimeMillis() - time);
            }

            result.setTestResults(testResults);

            // Now  the final probability
            if(!thresholdReached) {

                finalProbability = calculate(probabilities, 0, probabilities.length);
            }

            result.setProbability(finalProbability);
        }

        return result;
    }
View Full Code Here


                if(e.getType().equals(ParseErrorType.MALFORMED_MIME) ||
                        e.getType().equals(ParseErrorType.UNSUPPORTED_ENCODING) ||
                        e.getType().equals(ParseErrorType.PARSE_ERROR)) {

                    // These can be used to indicate spam..
                    StandardScanResult result = null;

                    try
                    {
                        result = (StandardScanResult) scanResultClass.newInstance();
                        result.setProbability(JasenEngineConfiguration.getInstance().getGuess());
                        result.setParseError(true);
                        String[][] explain = new String[1][4];
                       
                        explain[0][RESULT_INDEX_PROBABILITY]= "0.0";
                        explain[0][RESULT_INDEX_TIME]= "0.0";
                        explain[0][RESULT_INDEX_NAME]= "Parse Error";
                        explain[0][RESULT_INDEX_DISPLAY]= e.getMessage();

                        result.setTestResults(explain);

                        return result;
                    }
                    catch (InstantiationException e1)
                    {
View Full Code Here

TOP

Related Classes of org.jasen.core.StandardScanResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.