public Collection match()

in mailet/standard/src/main/java/org/apache/james/transport/matchers/CompareNumericHeaderValue.java [122:170]


    public Collection<MailAddress> match(Mail mail) throws MessagingException {
        if (headerName == null) {
            // should never get here
            throw new IllegalStateException("Null headerName");
        }
        
        MimeMessage message = mail.getMessage();
        
        String [] headerArray = message.getHeader(headerName);
        if (headerArray != null && headerArray.length > 0) {
            try {
                int comparison = Double.valueOf(headerArray[0].trim()).compareTo(headerValue);
                switch (comparisonOperator) {
                    case LT:
                        if (comparison < 0) {
                            return mail.getRecipients();
                        }
                        break;
                    case LE:
                        if (comparison <= 0) {
                            return mail.getRecipients();
                        }
                        break;
                    case EQ:
                        if (comparison == 0) {
                            return mail.getRecipients();
                        }
                        break;
                    case GE:
                        if (comparison >= 0) {
                            return mail.getRecipients();
                        }
                        break;
                    case GT:
                        if (comparison > 0) {
                            return mail.getRecipients();
                        }
                        break;
                    default:
                        // should never get here
                        throw new IllegalStateException("Unknown comparisonOperator" + comparisonOperator);
                }
            } catch (NumberFormatException nfe) {
                throw new MessagingException("Bad header value found in message: \"" + headerArray[0] + "\"", nfe);
            }
        }
        
        return null;
    }