org.apache.james.transport.matchers
Class AbstractQuotaMatcher

java.lang.Object
  extended by org.apache.mailet.GenericMatcher
      extended by org.apache.james.transport.matchers.AbstractQuotaMatcher
All Implemented Interfaces:
Matcher, MatcherConfig
Direct Known Subclasses:
AbstractStorageQuota

public abstract class AbstractQuotaMatcher
extends GenericMatcher

Abstract matcher checking whether a recipient has exceeded a maximum allowed quota.

"Quota" at this level is an abstraction whose specific interpretation will be done by subclasses.

Although extending GenericMatcher, its logic is recipient oriented.

Since:
2.2.0
Version:
CVS $Revision: 365582 $ $Date: 2006-01-03 08:51:21 +0000 (mar, 03 gen 2006) $

Constructor Summary
AbstractQuotaMatcher()
           
 
Method Summary
protected abstract  long getQuota(MailAddress address, Mail mail)
          Gets the quota to check against.
protected abstract  long getUsed(MailAddress address, Mail mail)
          Gets the used amount to check against the quota.
protected  boolean isOverQuota(MailAddress address, Mail mail)
          Does the quota check.
protected  boolean isRecipientChecked(MailAddress recipient)
          Checks the recipient.
protected  boolean isSenderChecked(MailAddress sender)
          Checks the sender.
 java.util.Collection match(Mail mail)
          Standard matcher entrypoint.
protected  long parseQuota(java.lang.String amount)
          Utility method that parses an amount string.
 
Methods inherited from class org.apache.mailet.GenericMatcher
destroy, getCondition, getMailetContext, getMatcherConfig, getMatcherInfo, getMatcherName, init, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractQuotaMatcher

public AbstractQuotaMatcher()
Method Detail

match

public final java.util.Collection match(Mail mail)
                                 throws javax.mail.MessagingException
Standard matcher entrypoint. First of all, checks the sender using isSenderChecked(org.apache.mailet.MailAddress). Then, for each recipient checks it using isRecipientChecked(org.apache.mailet.MailAddress) and isOverQuota(org.apache.mailet.MailAddress, org.apache.mailet.Mail).

Specified by:
match in interface Matcher
Specified by:
match in class GenericMatcher
Parameters:
mail - - the Mail object that contains the MimeMessage and routing information
Returns:
java.util.Collection - the recipients that the mailet container should have the mailet affect.
Throws:
javax.mail.MessagingException - if either isSenderChecked or isRecipientChecked throw an exception

isOverQuota

protected boolean isOverQuota(MailAddress address,
                              Mail mail)
Does the quota check. Checks if getQuota(org.apache.mailet.MailAddress, org.apache.mailet.Mail) < getUsed(org.apache.mailet.MailAddress, org.apache.mailet.Mail) for a recipient. Catches any throwable returning false, and so should any override do.

Parameters:
address - the recipient addresss to check
mail - the mail involved in the check
Returns:
true if over quota

isSenderChecked

protected boolean isSenderChecked(MailAddress sender)
                           throws javax.mail.MessagingException
Checks the sender. The default behaviour is to check that the sender is not null nor the local postmaster. If a subclass overrides this method it should "and" super.isSenderChecked to its check.

Parameters:
sender - the sender to check
Throws:
javax.mail.MessagingException

isRecipientChecked

protected boolean isRecipientChecked(MailAddress recipient)
                              throws javax.mail.MessagingException
Checks the recipient. The default behaviour is to check that the recipient is not the local postmaster. If a subclass overrides this method it should "and" super.isRecipientChecked to its check.

Parameters:
recipient - the recipient to check
Throws:
javax.mail.MessagingException

getQuota

protected abstract long getQuota(MailAddress address,
                                 Mail mail)
                          throws javax.mail.MessagingException
Gets the quota to check against.

Parameters:
address - the address holding the quota if applicable
mail - the mail involved if needed
Throws:
javax.mail.MessagingException

getUsed

protected abstract long getUsed(MailAddress address,
                                Mail mail)
                         throws javax.mail.MessagingException
Gets the used amount to check against the quota.

Parameters:
address - the address involved
mail - the mail involved if needed
Throws:
javax.mail.MessagingException

parseQuota

protected long parseQuota(java.lang.String amount)
                   throws javax.mail.MessagingException
Utility method that parses an amount string. You can use 'k' and 'm' as optional postfixes to the amount (both upper and lowercase). In other words, "1m" is the same as writing "1024k", which is the same as "1048576".

Parameters:
amount - the amount string to parse
Throws:
javax.mail.MessagingException


Copyright © 2002-2007 The Apache Software Foundation. All Rights Reserved.