Author: norman
Date: Fri Apr 22 19:38:53 2011
New Revision: 1096002

URL: http://svn.apache.org/viewvc?rev=1096002&view=rev
Log:
Add a Mailet which will take care of make recipient lowercase before try to 
deliver the mail. As this is what most people expect it make sense to enable it 
by default. This is related to MAILBOX-58

Added:
    
james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/RecipientToLowerCase.java
Modified:
    
james/server/trunk/container-spring/src/main/config/james/mailetcontainer.xml

Modified: 
james/server/trunk/container-spring/src/main/config/james/mailetcontainer.xml
URL: 
http://svn.apache.org/viewvc/james/server/trunk/container-spring/src/main/config/james/mailetcontainer.xml?rev=1096002&r1=1096001&r2=1096002&view=diff
==============================================================================
--- 
james/server/trunk/container-spring/src/main/config/james/mailetcontainer.xml 
(original)
+++ 
james/server/trunk/container-spring/src/main/config/james/mailetcontainer.xml 
Fri Apr 22 19:38:53 2011
@@ -54,6 +54,9 @@
       <mailet match="All" class="RecipientRewriteTable">
         
<recipientrewritetable>DefaultRecipientRewriteTable</recipientrewritetable>
       </mailet>
+      <!-- Disable this if you want to have case-sensitive local-parts of the 
recipients -->
+      <mailet match="RecipientIsLocal" class="RecipientToLowerCase"/>
+      
       <mailet match="RecipientIsLocal" class="LocalDelivery"/>
       <mailet match="HostIsLocal" class="ToProcessor">
         <processor>local-address-error</processor>

Added: 
james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/RecipientToLowerCase.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/RecipientToLowerCase.java?rev=1096002&view=auto
==============================================================================
--- 
james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/RecipientToLowerCase.java
 (added)
+++ 
james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/RecipientToLowerCase.java
 Fri Apr 22 19:38:53 2011
@@ -0,0 +1,49 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you 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.mailets;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+
+import javax.mail.MessagingException;
+
+import org.apache.mailet.Mail;
+import org.apache.mailet.MailAddress;
+import org.apache.mailet.base.GenericMailet;
+
+/**
+ * {@link GenericMailet} which convert all Recipients to lowercase
+ * 
+ *
+ */
+public class RecipientToLowerCase extends GenericMailet{
+
+    @Override
+    public void service(Mail mail) throws MessagingException {
+        Iterator<MailAddress> rcpts = mail.getRecipients().iterator();
+        List<MailAddress> newRcpts = new ArrayList<MailAddress>();
+        while(rcpts.hasNext()) {
+            newRcpts.add(new 
MailAddress(rcpts.next().toString().toLowerCase(Locale.US)));
+        }
+        mail.setRecipients(newRcpts);
+    }
+
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to