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