org.apache.james.transport.matchers
Class AbstractQuotaMatcher

java.lang.Object
  extended byorg.apache.mailet.GenericMatcher
      extended byorg.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 03:51:21 -0500 (Tue, 03 Jan 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.
 Collection match(Mail mail)
          Standard matcher entrypoint.
protected  long parseQuota(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 Collection match(Mail mail)
                       throws 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:
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 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:
MessagingException

isRecipientChecked

protected boolean isRecipientChecked(MailAddress recipient)
                              throws 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:
MessagingException

getQuota

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

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

getUsed

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

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

parseQuota

protected long parseQuota(String amount)
                   throws 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:
MessagingException


"Copyright © 1999-2006 Apache Jakarta Project. All Rights Reserved."