01: /****************************************************************
02: * Licensed to the Apache Software Foundation (ASF) under one *
03: * or more contributor license agreements. See the NOTICE file *
04: * distributed with this work for additional information *
05: * regarding copyright ownership. The ASF licenses this file *
06: * to you under the Apache License, Version 2.0 (the *
07: * "License"); you may not use this file except in compliance *
08: * with the License. You may obtain a copy of the License at *
09: * *
10: * http://www.apache.org/licenses/LICENSE-2.0 *
11: * *
12: * Unless required by applicable law or agreed to in writing, *
13: * software distributed under the License is distributed on an *
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
15: * KIND, either express or implied. See the License for the *
16: * specific language governing permissions and limitations *
17: * under the License. *
18: ****************************************************************/package org.apache.james.transport.matchers;
19:
20: import org.apache.mailet.Mail;
21: import org.apache.mailet.MailetContext;
22: import org.apache.mailet.MailAddress;
23: import javax.mail.MessagingException;
24: import java.util.Locale;
25:
26: /**
27: * <P>Experimental: Checks whether a recipient has exceeded a maximum allowed quota for messages
28: * standing in his inbox. Such quota is <I>the same</I> for all users.</P>
29: * <P>Will check if the total size of all his messages in the inbox are greater
30: * than a certain number of bytes. You can use 'k' and 'm' as optional postfixes.
31: * In other words, "1m" is the same as writing "1024k", which is the same as
32: * "1048576".</P>
33: * <P>Here follows an example of a config.xml definition:</P>
34: * <PRE><CODE>
35: * <processor name="transport">
36: * .
37: * .
38: * .
39: * <mailet match=match="RecipientIsOverFixedQuota=40M" class="ToProcessor">
40: * <processor> error </processor>
41: * <notice>The recipient has exceeded maximum allowed size quota</notice>
42: * </mailet>
43: * .
44: * .
45: * .
46: * </processor>
47: * </CODE></PRE>
48: *
49: * <P>This matcher need to calculate the mailbox size everytime it is called. This can slow down things if there are many mails in
50: * the mailbox. Some users also report big problems with the matcher if a JDBC based mailrepository is used. </P>
51: * @version 1.0.0, 2003-05-11
52: */
53:
54: public class RecipientIsOverFixedQuota extends AbstractStorageQuota {
55: private long quota = 0;
56:
57: /**
58: * Standard matcher initialization.
59: * Does a <CODE>super.init()</CODE> and parses the common storage quota amount from
60: * <I>config.xml</I> for later use.
61: */
62: public void init() throws MessagingException {
63: super .init();
64: quota = parseQuota(getCondition().trim().toLowerCase(Locale.US));
65: }
66:
67: protected long getQuota(MailAddress recipient, Mail _)
68: throws MessagingException {
69: return quota;
70: }
71: }
|