1 /************************************************************************
2 * Copyright (c) 2000-2006 The Apache Software Foundation. *
3 * All rights reserved. *
4 * ------------------------------------------------------------------- *
5 * Licensed under the Apache License, Version 2.0 (the "License"); you *
6 * may not use this file except in compliance with the License. You *
7 * may obtain a copy of the License at: *
8 * *
9 * http://www.apache.org/licenses/LICENSE-2.0 *
10 * *
11 * Unless required by applicable law or agreed to in writing, software *
12 * distributed under the License is distributed on an "AS IS" BASIS, *
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or *
14 * implied. See the License for the specific language governing *
15 * permissions and limitations under the License. *
16 ***********************************************************************/
17
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>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 * @version 1.0.0, 2003-05-11
50 */
51
52 public class RecipientIsOverFixedQuota extends AbstractStorageQuota {
53 private long quota = 0;
54
55 /***
56 * Standard matcher initialization.
57 * Does a <CODE>super.init()</CODE> and parses the common storage quota amount from
58 * <I>config.xml</I> for later use.
59 */
60 public void init() throws MessagingException {
61 super.init();
62 quota = parseQuota(getCondition().trim().toLowerCase(Locale.US));
63 }
64
65 protected long getQuota(MailAddress recipient, Mail _) throws MessagingException {
66 return quota;
67 }
68 }