FileDocCategorySizeDatePackage
SizeGreaterThan.javaAPI DocApache James 2.3.12808Fri Jan 12 12:56:32 GMT 2007org.apache.james.transport.matchers

SizeGreaterThan

public class SizeGreaterThan extends org.apache.mailet.GenericMatcher
Checks whether the message (entire message, not just content) is greater than a certain number of bytes. You can use 'k' and 'm' as optional postfixes. In other words, "1m" is the same as writing "1024k", which is the same as "1048576".

Fields Summary
int
cutoff
Constructors Summary
Methods Summary
public voidinit()


       
        String amount = getCondition().trim().toLowerCase(Locale.US);
        if (amount.endsWith("k")) {
            amount = amount.substring(0, amount.length() - 1);
            cutoff = Integer.parseInt(amount) * 1024;
        } else if (amount.endsWith("m")) {
            amount = amount.substring(0, amount.length() - 1);
            cutoff = Integer.parseInt(amount) * 1024 * 1024;
        } else {
            cutoff = Integer.parseInt(amount);
        }
    
public java.util.Collectionmatch(org.apache.mailet.Mail mail)

        MimeMessage message = mail.getMessage();
        //Calculate the size
        int size = message.getSize();
        Enumeration e = message.getAllHeaders();
        while (e.hasMoreElements()) {
            size += ((Header)e.nextElement()).toString().length();
        }
        if (size > cutoff) {
            return mail.getRecipients();
        } else {
            return null;
        }