Methods Summary |
---|
protected abstract long | getQuota(org.apache.mailet.MailAddress address, org.apache.mailet.Mail mail)Gets the quota to check against.
|
protected abstract long | getUsed(org.apache.mailet.MailAddress address, org.apache.mailet.Mail mail)Gets the used amount to check against the quota.
|
protected boolean | isOverQuota(org.apache.mailet.MailAddress address, org.apache.mailet.Mail mail)Does the quota check.
Checks if {@link #getQuota} < {@link #getUsed} for a recipient.
Catches any throwable returning false, and so should any override do.
String user = address.getUser();
try {
boolean over = getQuota(address, mail) < getUsed(address, mail);
if (over) log(address + " is over quota.");
return over;
} catch (Throwable e) {
log("Exception checking quota for: " + address, e);
return false;
}
|
protected boolean | isRecipientChecked(org.apache.mailet.MailAddress recipient)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.
return !(getMailetContext().getPostmaster().equals(recipient));
|
protected boolean | isSenderChecked(org.apache.mailet.MailAddress sender)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.
return !(sender == null || getMailetContext().getPostmaster().equals(sender));
|
public final java.util.Collection | match(org.apache.mailet.Mail mail)Standard matcher entrypoint.
First of all, checks the sender using {@link #isSenderChecked}.
Then, for each recipient checks it using {@link #isRecipientChecked} and
{@link #isOverQuota}.
Collection matching = null;
if (isSenderChecked(mail.getSender())) {
matching = new ArrayList();
for (Iterator i = mail.getRecipients().iterator(); i.hasNext(); ) {
MailAddress recipient = (MailAddress) i.next();
if (isRecipientChecked(recipient) && isOverQuota(recipient, mail)) {
matching.add(recipient);
}
}
}
return matching;
|
protected long | parseQuota(java.lang.String amount)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".
long quota;
try {
if (amount.endsWith("k")) {
amount = amount.substring(0, amount.length() - 1);
quota = Long.parseLong(amount) * 1024;
} else if (amount.endsWith("m")) {
amount = amount.substring(0, amount.length() - 1);
quota = Long.parseLong(amount) * 1024 * 1024;
} else {
quota = Long.parseLong(amount);
}
return quota;
}
catch (Exception e) {
throw new MessagingException("Exception parsing quota", e);
}
|