⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jasen.java

📁 spam source codejasen-0.9jASEN - java Anti Spam ENgine.zip 如标题所示
💻 JAVA
📖 第 1 页 / 共 3 页
字号:

            result.setTestResults(testResults);

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

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

            result.setProbability(finalProbability);
        }

        return result;
    }

    /**
     * Scans the given message.
	 *  <p>
	 * 		The threshold value indicates the value at which we know the message is spam without continuing
	 * 	</p>
     * If the engine computes this threshold prior to all plugins executing, tests are stopped and the result is
     * returned immediately
     * @param mm The MimeMessage to be scanned
     * @param threshold The marker above which scanning ceases
     * @param ignored A list of plugin names which will be ignored during the scan.  May be null
     * @return The results of the scan as a JasenScanResult
     * @throws JasenException
     */
    public JasenScanResult scan(MimeMessage mm, float threshold, String[] ignored) throws JasenException {
        JasenMessage message = null;

        // Parse the message
        try
        {
            message = mimeParser.parse(mm);
        }
        catch (JasenParseException e)
        {
            ErrorHandlerBroker.getInstance().getErrorHandler().handleException(e);

            if(e.getType() != null) {
                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)
                    {
                        throw new JasenException(e1);
                    }
                    catch (IllegalAccessException e1)
                    {
                        throw new JasenException(e1);
                    }
                }
                else
                {
                    throw e;
                }
            }
            else
            {
                throw e;
            }
        }

        return scan(mm, message, threshold, ignored);
    }


    private double calculate(double[] probabilities, int start, int end) throws JasenException {
        normalize(probabilities);
        return calculator.calculate(probabilities, start, end);
    }

    /**
     * If a probability boundary has been specified for the engine, this method
     * normalises the probabilities so they are within this boundary
     * @param probabilities
     */
    private boolean normalize(double[] probabilities) {

        boolean normed = false;

        if(boundary > 0.0f) {

            float low = boundary;
            float high = 1.0f - low;

            for (int i = 0; i < probabilities.length; i++)
            {
                // Check low/high
                if(probabilities[i] < low) {
                    probabilities[i] = low;
                    normed = true;
                }
                else if(probabilities[i] > high) {
                    probabilities[i] = high;
                    normed = true;
                }
            }
        }

        return normed;
    }

    /**
     * Gets the calculator used to calculate the combined probabilities of all the tests
     * @return The calculator in use
     * @see JasenConfiguration#getCalculator()
     */
    public ProbabilityCalculator getCalculator() {
        return calculator;
    }

    /**
     * Sets the calculator used to calculate the combined probabilities of all the tests
     * @param calculator
     * @see JasenConfiguration#setCalculator(String)
     */
    public void setCalculator(ProbabilityCalculator calculator) {
        this.calculator = calculator;
    }

    /**
     * Gets the mimeParser used to parse the "received" headers in the message
     * @return The Class object of the header parser in use
     * @see JasenConfiguration#getHeaderParser()
     */
    public Class getHeaderParserClass() {
        return headerParserClass;
    }

    /**
     * Sets the mimeParser used to parse the "received" headers in the message
     * @param headerParser
     * @see JasenConfiguration#setHeaderParser(String)
     */
    public void setHeaderParserClass(Class headerParser) {
        this.headerParserClass = headerParser;
    }

    /**
     * Gets the mimeParser used to parse the MimeMessage
     * @return The Mime parse in use
     * @see JasenConfiguration#getMimeParser()
     */
    public MimeMessageParser getMimeParser() {
        return mimeParser;
    }

    /**
     * Sets the mimeParser used to parse the MimeMessage
     * @param parser The mime parse to be used
     */
    public void setMimeParser(MimeMessageParser parser) {
        this.mimeParser = parser;
    }

    /**
     * Gets the list of plugins to be used when scanning a message
     * @return A list of PluginContainer objects
     * @see PluginContainer
     */
    public List getPlugins() {
        return plugins;
    }

    /**
     * Sets the list of plugins to be used when scanning a message
     * @param plugins A List of PluginContainer objects
     * @see PluginContainer
     */
    public void setPlugins(Vector plugins) {
        this.plugins = plugins;
    }


    /**
     * Gets the configuration object defined for the engine
     * @return The configuration object loaded from the XML config data
     */
    public JasenConfiguration getConfig() {
        return config;
    }

    /**
     * Gets the tokenizer used to extract meaningful text from the message
     * @return The message tokenizer in use
     * @see JasenConfiguration#getTokenizer()
     */
    public MimeMessageTokenizer getTokenizer() {
        return tokenizer;
    }

    /**
     * Sets the tokenizer used to extract meaningful text from the message
     * @param tokenizer The tokenizer to use
     * @see JasenConfiguration#setTokenizer(String)
     */
    public void setTokenizer(MimeMessageTokenizer tokenizer) {
        this.tokenizer = tokenizer;
    }

    /**
     * Gets the class used to hold the results of a scan
     * @return Returns the scanResultClass.
     * @see JasenConfiguration#getResult()
     */
    public Class getScanResultClass() {
        return scanResultClass;
    }

    /**
     * Sets the class used to hold the results of a scan 
     * @param resultClass
     * @see JasenConfiguration#setResult(String)
     */
    public void setScanResultClass(Class resultClass) {
        this.scanResultClass = resultClass;
    }

    /**
     * Gets the resolver used to resolve InetAddresses
     * @return The InetAddressResolver in use
     * @see JasenConfiguration#getInetResolver()
     */
    public InetAddressResolver getInetAddressResolver() {
        return inetAddressResolver;
    }

    /**
     * Sets the resolver used to resolve InetAddresses
     * @param inetAddressResolver
     * @see JasenConfiguration#setInetResolver(String)
     */
    public void setInetAddressResolver(InetAddressResolver inetAddressResolver) {
        this.inetAddressResolver = inetAddressResolver;
    }

    /**
     * Gets the resolver used to resolve DNS records
     * @return The DNS resolver in use
     * @see JasenConfiguration#getDnsResolver()
     */
    public DNSResolver getDnsResolver() {
        return dnsResolver;
    }

    /**
     *  Sets the resolver used to resolve DNS records
     * @param dnsResolver
     * @see JasenConfiguration#setDnsResolver(String)
     */
    public void setDnsResolver(DNSResolver dnsResolver) {
        this.dnsResolver = dnsResolver;
    }

    /**
     * Gets the error handler used by the scanner
     * @return The current error handler in use
     * @see JasenConfiguration#getErrorHandler()
     */
    public JasenErrorHandler getErrorHandler() {
        return errorHandler;
    }

    /**
     * Sets the error handler used by the scanner
     * @param errorHandler The error handler to beused
     * @see JasenConfiguration#setErrorHandler(String)
     */
    public void setErrorHandler(JasenErrorHandler errorHandler) {
        this.errorHandler = errorHandler;
    }
    
    
    /**
     * Gets the context classloader to use when loading plugins etc.
     * <P>
     * This should only EVERY be set by the auto update engine
     * </P>
     * @return The class loader registered by the auto update engine.  Or null if none has been set
     */
    public ClassLoader getContextClassLoader() {
        return contextClassLoader;
    }
    
    /**
     * Sets the class loader to use when loading plugins etc.
     * <P>
     * This should only EVERY be set by the auto update engine
     * </P> 
     * @param pluginClassLoader The class loader to use to load plugins for this session
     */
    public synchronized void  setContextClassLoader(ClassLoader pluginClassLoader) {
        this.contextClassLoader = pluginClassLoader;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -