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 no...@apache.org on 2010/11/04 21:59:38 UTC
svn commit: r1031241 - in /james/server/trunk:
container-spring/src/main/config/james/smtpserver.xml
smtpserver/src/main/java/org/apache/james/smtpserver/MailPriorityHandler.java
Author: norman
Date: Thu Nov 4 20:59:37 2010
New Revision: 1031241
URL: http://svn.apache.org/viewvc?rev=1031241&view=rev
Log:
Add MailPriorityHandler which allows to set mail priority per recipient domain (JAMES-1114)
Added:
james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/MailPriorityHandler.java
Modified:
james/server/trunk/container-spring/src/main/config/james/smtpserver.xml
Modified: james/server/trunk/container-spring/src/main/config/james/smtpserver.xml
URL: http://svn.apache.org/viewvc/james/server/trunk/container-spring/src/main/config/james/smtpserver.xml?rev=1031241&r1=1031240&r2=1031241&view=diff
==============================================================================
--- james/server/trunk/container-spring/src/main/config/james/smtpserver.xml (original)
+++ james/server/trunk/container-spring/src/main/config/james/smtpserver.xml Thu Nov 4 20:59:37 2010
@@ -257,6 +257,24 @@
<!-- Load the core command handlers -->
<handler class="org.apache.james.smtpserver.CoreCmdHandlerLoader"/>
+ <!-- This handler can add a hint to the mail which tells the MailQueue which email should get processed first -->
+ <!-- Normally the MailQueue will just handles Mails in FIFO manner -->
+ <!-- Valid priority values are 1,5,9 where 9 is the highest-->
+ <!--
+ <handler class="org.apache.james.smtpserver.MailPriortyHandler">
+ <priorityEntries>
+ <priorityEntry>
+ <domain> yourdomain1 </domain>
+ <priority> 1 </priority>
+ </priorityEntry>
+ <priorityEntry>
+ <domain> yourdomain2 </domain>
+ <priority> 9 </priority>
+ </priorityEntry>
+ <priorityEntries>
+ </handler>
+ -->
+
<!-- This MessageHandler could be used to check message against spamd before -->
<!-- accept the email. So its possible to reject a message on smtplevel if a -->
<!-- configured hits amount is reached. -->
Added: james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/MailPriorityHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/MailPriorityHandler.java?rev=1031241&view=auto
==============================================================================
--- james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/MailPriorityHandler.java (added)
+++ james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/MailPriorityHandler.java Thu Nov 4 20:59:37 2010
@@ -0,0 +1,98 @@
+/****************************************************************
+ * 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.smtpserver;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.HierarchicalConfiguration;
+import org.apache.james.lifecycle.Configurable;
+import org.apache.james.protocols.smtp.SMTPSession;
+import org.apache.james.protocols.smtp.hook.HookResult;
+import org.apache.james.protocols.smtp.hook.HookReturnCode;
+import org.apache.james.queue.api.MailPrioritySupport;
+import org.apache.mailet.Mail;
+import org.apache.mailet.MailAddress;
+
+/**
+ * Handler which set a configured {@link Mail} priority for the mail.
+ *
+ * if the {@link Mail} has more then one recipient, then the highest priority (which was found) is set
+ *
+ */
+public class MailPriorityHandler implements JamesMessageHook, Configurable{
+
+ private Map<String, Integer> prioMap = new HashMap<String, Integer>();
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.james.smtpserver.JamesMessageHook#onMessage(org.apache.james.protocols.smtp.SMTPSession, org.apache.mailet.Mail)
+ */
+ @SuppressWarnings("unchecked")
+ public HookResult onMessage(SMTPSession session, Mail mail) {
+ Iterator<MailAddress> rcpts = mail.getRecipients().iterator();
+
+ Integer p = null;
+
+ while(rcpts.hasNext()) {
+ String domain = rcpts.next().getDomain();
+ Integer prio = null;
+ if (domain != null) {
+ prio = prioMap.get(domain);
+ if (prio != null) {
+ if (p == null || prio > p) {
+ p = prio;
+ }
+
+ // already the highest priority
+ if (p == MailPrioritySupport.HIGH_PRIORITY) break;
+ }
+ }
+ }
+
+
+ // set the priority if one was found
+ if (p != null) mail.setAttribute(MailPrioritySupport.MAIL_PRIORITY, p);
+ return new HookResult(HookReturnCode.DECLINED);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.james.lifecycle.Configurable#configure(org.apache.commons.configuration.HierarchicalConfiguration)
+ */
+ @SuppressWarnings("unchecked")
+ public void configure(HierarchicalConfiguration config) throws ConfigurationException {
+ List<HierarchicalConfiguration> entries = config.configurationsAt("priorityEntries.priorityEntry");
+ for (int i = 0; i < entries.size(); i++) {
+ HierarchicalConfiguration prioConf = entries.get(i);
+ String domain = prioConf.getString("domain");
+ int prio = prioConf.getInt("priority", MailPrioritySupport.NORMAL_PRIORITY);
+ if (prio > MailPrioritySupport.HIGH_PRIORITY || prio < MailPrioritySupport.LOW_PRIORITY) {
+ throw new ConfigurationException("configured priority must be >= " + MailPrioritySupport.LOW_PRIORITY + " and <= " + MailPrioritySupport.HIGH_PRIORITY);
+ }
+ prioMap.put(domain, prio);
+ }
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org