View Javadoc

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