Package mireka.list

Source Code of mireka.list.SubjectRegexpValidator

package mireka.list;

import java.util.regex.Pattern;

import javax.mail.MessagingException;

import mireka.smtp.EnhancedStatus;
import mireka.smtp.RejectExceptionExt;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* SubjectRegexpValidator accepts a mail if its subject matches the specified
* regular expression pattern.
*/
public class SubjectRegexpValidator implements MailValidator {
    private final Logger logger = LoggerFactory
            .getLogger(SubjectRegexpValidator.class);
    private Pattern pattern;

    @Override
    public boolean shouldBeAccepted(ParsedMail mail) throws RejectExceptionExt {
        try {
            String subject = mail.getMimeMessage().getSubject();
            if (subject == null)
                subject = "";
            boolean result = pattern.matcher(subject).matches();
            if (result)
                logger.debug("Mail accepted, subject matches "
                        + pattern.toString());
            return result;
        } catch (MessagingException e) {
            throw new RejectExceptionExt(EnhancedStatus.BAD_MESSAGE_BODY);
        }
    }

    /**
     * @category GETSET
     */
    public String getPattern() {
        return pattern.toString();
    }

    /**
     * @category GETSET
     */
    public void setPattern(String pattern) {
        this.pattern = Pattern.compile(pattern);
    }

    /**
     * @category GETSET
     */
    public void setValue(String pattern) {
        setPattern(pattern);
    }
}
TOP

Related Classes of mireka.list.SubjectRegexpValidator

TOP
Copyright © 2018 www.massapi.com. 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.