You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by vi...@apache.org on 2004/02/26 14:26:38 UTC

cvs commit: james-server/src/java/org/apache/james/transport/matchers AbstractStorageQuota.java

vincenzo    2004/02/26 05:26:38

  Modified:    src/java/org/apache/james/transport/matchers Tag:
                        branch_2_1_fcs AbstractStorageQuota.java
  Log:
  The AbstractStorageQuota matcher subclasses are unable to retrieve the amount of storage currently used in the recipient's inbox if the message's recipient name is an alias instead of being the primary name, and hence never match.
  Fixed getUsed(MailAddress recipient, Mail _) adding a call to a new getPrimaryName(String originalUsername) method that hanles aliases.
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.1.2.3   +58 -59    james-server/src/java/org/apache/james/transport/matchers/Attic/AbstractStorageQuota.java
  
  Index: AbstractStorageQuota.java
  ===================================================================
  RCS file: /home/cvs/james-server/src/java/org/apache/james/transport/matchers/Attic/AbstractStorageQuota.java,v
  retrieving revision 1.1.2.2
  retrieving revision 1.1.2.3
  diff -u -r1.1.2.2 -r1.1.2.3
  --- AbstractStorageQuota.java	28 Aug 2003 16:22:37 -0000	1.1.2.2
  +++ AbstractStorageQuota.java	26 Feb 2004 13:26:37 -0000	1.1.2.3
  @@ -1,60 +1,19 @@
  -/* ====================================================================
  - * The Apache Software License, Version 1.1
  - *
  - * Copyright (c) 2000-2003 The Apache Software Foundation.  All rights
  - * reserved.
  - *
  - * Redistribution and use in source and binary forms, with or without
  - * modification, are permitted provided that the following conditions
  - * are met:
  - *
  - * 1. Redistributions of source code must retain the above copyright
  - *    notice, this list of conditions and the following disclaimer.
  - *
  - * 2. Redistributions in binary form must reproduce the above copyright
  - *    notice, this list of conditions and the following disclaimer in
  - *    the documentation and/or other materials provided with the
  - *    distribution.
  - *
  - * 3. The end-user documentation included with the redistribution,
  - *    if any, must include the following acknowledgment:
  - *       "This product includes software developed by the
  - *        Apache Software Foundation (http://www.apache.org/)."
  - *    Alternately, this acknowledgment may appear in the software itself,
  - *    if and wherever such third-party acknowledgments normally appear.
  - *
  - * 4. The names "Apache", "Jakarta", "JAMES" and "Apache Software Foundation"
  - *    must not be used to endorse or promote products derived from this
  - *    software without prior written permission. For written
  - *    permission, please contact apache@apache.org.
  - *
  - * 5. Products derived from this software may not be called "Apache",
  - *    nor may "Apache" appear in their name, without prior written
  - *    permission of the Apache Software Foundation.
  - *
  - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  - * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  - * SUCH DAMAGE.
  - * ====================================================================
  - *
  - * This software consists of voluntary contributions made by many
  - * individuals on behalf of the Apache Software Foundation.  For more
  - * information on the Apache Software Foundation, please see
  - * <http://www.apache.org/>.
  - *
  - * Portions of this software are based upon public domain software
  - * originally written at the National Center for Supercomputing Applications,
  - * University of Illinois, Urbana-Champaign.
  - */
  +/***********************************************************************
  + * Copyright (c) 2000-2004 The Apache Software Foundation.             *
  + * All rights reserved.                                                *
  + * ------------------------------------------------------------------- *
  + * Licensed under the Apache License, Version 2.0 (the "License"); you *
  + * may not use this file except in compliance with the License. You    *
  + * may obtain a copy of the License at:                                *
  + *                                                                     *
  + *     http://www.apache.org/licenses/LICENSE-2.0                      *
  + *                                                                     *
  + * Unless required by applicable law or agreed to in writing, software *
  + * distributed under the License is distributed on an "AS IS" BASIS,   *
  + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or     *
  + * implied.  See the License for the specific language governing       *
  + * permissions and limitations under the License.                      *
  + ***********************************************************************/
   
   package org.apache.james.transport.matchers;
   
  @@ -66,6 +25,9 @@
   import org.apache.james.core.MailImpl;
   import org.apache.james.services.MailServer;
   import org.apache.james.services.MailRepository;
  +import org.apache.james.services.UsersStore;
  +import org.apache.james.services.UsersRepository;
  +import org.apache.james.services.JamesUser;
   
   import org.apache.mailet.Mail;
   import org.apache.mailet.MailAddress;
  @@ -79,12 +41,21 @@
    * <P>"Storage quota" at this level is still an abstraction whose specific interpretation
    * will be done by subclasses (e.g. could be specific for each user or common to all of them).</P> 
    *
  - * @version 1.0.0, 2003-05-11
  + * @version CVS $Revision$ $Date$
  + * @since 2.2.0
    */
   abstract public class AbstractStorageQuota extends AbstractQuotaMatcher { 
   
       private MailServer mailServer;
   
  +    /** The store containing the local user repository. */
  +    private UsersStore usersStore;
  +
  +    /** The user repository for this mail server.  Contains all the users with inboxes
  +     * on this server.
  +     */
  +    private UsersRepository localusers;
  +
       /**
        * Standard matcher initialization.
        * Overriding classes must do a <CODE>super.init()</CODE>.
  @@ -97,6 +68,12 @@
           } catch (ComponentException e) {
               log("Exception in getting the MailServer: " + e.getMessage() + e.getRole());
           }        
  +        try {
  +            usersStore = (UsersStore)compMgr.lookup(UsersStore.ROLE);
  +        } catch (ComponentException e) {
  +            log("Exception in getting the UsersStore: " + e.getMessage() + e.getRole());
  +        }        
  +        localusers = (UsersRepository)usersStore.getRepository("LocalUsers");
       }
   
       /** 
  @@ -120,7 +97,7 @@
        */    
       protected long getUsed(MailAddress recipient, Mail _) throws MessagingException {
           long size = 0;
  -        MailRepository userInbox = mailServer.getUserInbox(recipient.getUser());
  +        MailRepository userInbox = mailServer.getUserInbox(getPrimaryName(recipient.getUser()));
           for (Iterator it = userInbox.list(); it.hasNext(); ) {
               String key = (String) it.next();
               MailImpl mc = userInbox.retrieve(key);
  @@ -135,4 +112,26 @@
           }
           return size;
       }
  +
  +    /**
  +     * Gets the main name of a local customer, handling aliases.
  +     *
  +     * @param originalUsername the user name to look for; it can be already the primary name or an alias
  +     * @return the primary name, or originalUsername unchanged if not found
  +     */
  +    protected String getPrimaryName(String originalUsername) {
  +        String username;
  +        try {
  +            username = localusers.getRealName(originalUsername);
  +            JamesUser user = (JamesUser) localusers.getUserByName(username);
  +            if (user.getAliasing()) {
  +                username = user.getAlias();
  +            }
  +        }
  +        catch (Exception e) {
  +            username = originalUsername;
  +        }
  +        return username;
  +    }
  +    
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org