Author: norman Date: Thu Jul 27 08:42:42 2006 New Revision: 426107 URL: http://svn.apache.org/viewvc?rev=426107&view=rev Log: Add new util class which provides usefull static methods for mailets Code cleanup
Added: james/server/trunk/src/java/org/apache/james/util/mailet/ james/server/trunk/src/java/org/apache/james/util/mailet/MailetUtil.java Modified: james/server/trunk/src/java/org/apache/james/transport/mailets/CommandListservProcessor.java james/server/trunk/src/java/org/apache/james/transport/mailets/GenericListserv.java james/server/trunk/src/java/org/apache/james/transport/mailets/WhiteListManager.java Modified: james/server/trunk/src/java/org/apache/james/transport/mailets/CommandListservProcessor.java URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/transport/mailets/CommandListservProcessor.java?rev=426107&r1=426106&r2=426107&view=diff ============================================================================== --- james/server/trunk/src/java/org/apache/james/transport/mailets/CommandListservProcessor.java (original) +++ james/server/trunk/src/java/org/apache/james/transport/mailets/CommandListservProcessor.java Thu Jul 27 08:42:42 2006 @@ -28,6 +28,7 @@ import org.apache.james.services.UsersStore; import org.apache.mailet.RFC2822Headers; import org.apache.james.util.XMLResources; +import org.apache.james.util.mailet.MailetUtil; import org.apache.mailet.GenericMailet; import org.apache.mailet.Mail; import org.apache.mailet.MailAddress; @@ -262,7 +263,7 @@ if (subj == null) { subj = ""; } - subj = normalizeSubject(subj, prefix); + subj = MailetUtil.normalizeSubject(subj, prefix); AbstractRedirect.changeSubject(message, subj); } } @@ -421,79 +422,6 @@ usersRepository = usersStore.getRepository(repName); if (usersRepository == null) throw new Exception("Invalid user repository: " + repName); - } - - /** - * <p>This takes the subject string and reduces (normailzes) it. - * Multiple "Re:" entries are reduced to one, and capitalized. The - * prefix is always moved/placed at the beginning of the line, and - * extra blanks are reduced, so that the output is always of the - * form:</p> - * <code> - * <prefix> + <one-optional-"Re:"*gt; + <remaining subject> - * </code> - * <p>I have done extensive testing of this routine with a standalone - * driver, and am leaving the commented out debug messages so that - * when someone decides to enhance this method, it can be yanked it - * from this file, embedded it with a test driver, and the comments - * enabled.</p> - */ - static private String normalizeSubject(final String subj, final String prefix) { - // JDK IMPLEMENTATION NOTE! When we require JDK 1.4+, all - // occurrences of subject.toString.().indexOf(...) can be - // replaced by subject.indexOf(...). - - StringBuffer subject = new StringBuffer(subj); - int prefixLength = prefix.length(); - - // System.err.println("In: " + subject); - - // If the "prefix" is not at the beginning the subject line, remove it - int index = subject.toString().indexOf(prefix); - if (index != 0) { - // System.err.println("(p) index: " + index + ", subject: " + subject); - if (index > 0) { - subject.delete(index, index + prefixLength); - } - subject.insert(0, prefix); // insert prefix at the front - } - - // Replace Re: with RE: - String match = "Re:"; - index = subject.toString().indexOf(match, prefixLength); - - while(index > -1) { - // System.err.println("(a) index: " + index + ", subject: " + subject); - subject.replace(index, index + match.length(), "RE:"); - index = subject.toString().indexOf(match, prefixLength); - // System.err.println("(b) index: " + index + ", subject: " + subject); - } - - // Reduce them to one at the beginning - match ="RE:"; - int indexRE = subject.toString().indexOf(match, prefixLength) + match.length(); - index = subject.toString().indexOf(match, indexRE); - while(index > 0) { - // System.err.println("(c) index: " + index + ", subject: " + subject); - subject.delete(index, index + match.length()); - index = subject.toString().indexOf(match, indexRE); - // System.err.println("(d) index: " + index + ", subject: " + subject); - } - - // Reduce blanks - match = " "; - index = subject.toString().indexOf(match, prefixLength); - while(index > -1) { - // System.err.println("(e) index: " + index + ", subject: " + subject); - subject.replace(index, index + match.length(), " "); - index = subject.toString().indexOf(match, prefixLength); - // System.err.println("(f) index: " + index + ", subject: " + subject); - } - - - // System.err.println("Out: " + subject); - - return subject.toString(); } /** Modified: james/server/trunk/src/java/org/apache/james/transport/mailets/GenericListserv.java URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/transport/mailets/GenericListserv.java?rev=426107&r1=426106&r2=426107&view=diff ============================================================================== --- james/server/trunk/src/java/org/apache/james/transport/mailets/GenericListserv.java (original) +++ james/server/trunk/src/java/org/apache/james/transport/mailets/GenericListserv.java Thu Jul 27 08:42:42 2006 @@ -21,6 +21,7 @@ package org.apache.james.transport.mailets; +import org.apache.james.util.mailet.MailetUtil; import org.apache.mailet.RFC2822Headers; import org.apache.mailet.GenericMailet; import org.apache.mailet.Mail; @@ -86,78 +87,6 @@ return true; // preserve old behavior unless subclass overrides. } - /** - * <p>This takes the subject string and reduces (normailzes) it. - * Multiple "Re:" entries are reduced to one, and capitalized. The - * prefix is always moved/placed at the beginning of the line, and - * extra blanks are reduced, so that the output is always of the - * form:</p> - * <code> - * <prefix> + <one-optional-"Re:"*gt; + <remaining subject> - * </code> - * <p>I have done extensive testing of this routine with a standalone - * driver, and am leaving the commented out debug messages so that - * when someone decides to enhance this method, it can be yanked it - * from this file, embedded it with a test driver, and the comments - * enabled.</p> - */ - static private String normalizeSubject(final String subj, final String prefix) { - // JDK IMPLEMENTATION NOTE! When we require JDK 1.4+, all - // occurrences of subject.toString.().indexOf(...) can be - // replaced by subject.indexOf(...). - - StringBuffer subject = new StringBuffer(subj); - int prefixLength = prefix.length(); - - // System.err.println("In: " + subject); - - // If the "prefix" is not at the beginning the subject line, remove it - int index = subject.toString().indexOf(prefix); - if (index != 0) { - // System.err.println("(p) index: " + index + ", subject: " + subject); - if (index > 0) { - subject.delete(index, index + prefixLength); - } - subject.insert(0, prefix); // insert prefix at the front - } - - // Replace Re: with RE: - String match = "Re:"; - index = subject.toString().indexOf(match, prefixLength); - - while(index > -1) { - // System.err.println("(a) index: " + index + ", subject: " + subject); - subject.replace(index, index + match.length(), "RE:"); - index = subject.toString().indexOf(match, prefixLength); - // System.err.println("(b) index: " + index + ", subject: " + subject); - } - - // Reduce them to one at the beginning - match ="RE:"; - int indexRE = subject.toString().indexOf(match, prefixLength) + match.length(); - index = subject.toString().indexOf(match, indexRE); - while(index > 0) { - // System.err.println("(c) index: " + index + ", subject: " + subject); - subject.delete(index, index + match.length()); - index = subject.toString().indexOf(match, indexRE); - // System.err.println("(d) index: " + index + ", subject: " + subject); - } - - // Reduce blanks - match = " "; - index = subject.toString().indexOf(match, prefixLength); - while(index > -1) { - // System.err.println("(e) index: " + index + ", subject: " + subject); - subject.replace(index, index + match.length(), " "); - index = subject.toString().indexOf(match, prefixLength); - // System.err.println("(f) index: " + index + ", subject: " + subject); - } - - - // System.err.println("Out: " + subject); - - return subject.toString(); - } /** * Processes the message. Assumes it is the only recipient of this forked message. @@ -216,7 +145,7 @@ if (subj == null) { subj = ""; } - subj = normalizeSubject(subj, prefix); + subj = MailetUtil.normalizeSubject(subj, prefix); AbstractRedirect.changeSubject(message, subj); } Modified: james/server/trunk/src/java/org/apache/james/transport/mailets/WhiteListManager.java URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/transport/mailets/WhiteListManager.java?rev=426107&r1=426106&r2=426107&view=diff ============================================================================== --- james/server/trunk/src/java/org/apache/james/transport/mailets/WhiteListManager.java (original) +++ james/server/trunk/src/java/org/apache/james/transport/mailets/WhiteListManager.java Thu Jul 27 08:42:42 2006 @@ -750,7 +750,7 @@ * for finding the conf/sqlResources.xml file * @throws Exception If any error occurs */ - public void initSqlQueries(Connection conn, org.apache.mailet.MailetContext mailetContext) throws Exception { + private void initSqlQueries(Connection conn, org.apache.mailet.MailetContext mailetContext) throws Exception { try { if (conn.getAutoCommit()) { conn.setAutoCommit(false); Added: james/server/trunk/src/java/org/apache/james/util/mailet/MailetUtil.java URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/util/mailet/MailetUtil.java?rev=426107&view=auto ============================================================================== --- james/server/trunk/src/java/org/apache/james/util/mailet/MailetUtil.java (added) +++ james/server/trunk/src/java/org/apache/james/util/mailet/MailetUtil.java Thu Jul 27 08:42:42 2006 @@ -0,0 +1,87 @@ +/**************************************************************** + * 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.util.mailet; + + +/** + * The Util class provide some static methods which can be usefull in mailets + */ +public class MailetUtil { + + /** + * <p>This takes the subject string and reduces (normailzes) it. + * Multiple "Re:" entries are reduced to one, and capitalized. The + * prefix is always moved/placed at the beginning of the line, and + * extra blanks are reduced, so that the output is always of the + * form:</p> + * <code> + * <prefix> + <one-optional-"Re:"*gt; + <remaining subject> + * </code> + * <p>I have done extensive testing of this routine with a standalone + * driver, and am leaving the commented out debug messages so that + * when someone decides to enhance this method, it can be yanked it + * from this file, embedded it with a test driver, and the comments + * enabled.</p> + */ + public static String normalizeSubject(String subj, String prefix) { + StringBuffer subject = new StringBuffer(subj); + int prefixLength = prefix.length(); + + // If the "prefix" is not at the beginning the subject line, remove it + int index = subject.indexOf(prefix); + if (index != 0) { + + if (index > 0) { + subject.delete(index, index + prefixLength); + } + subject.insert(0, prefix); // insert prefix at the front + } + + // Replace Re: with RE: + String match = "Re:"; + index = subject.indexOf(match, prefixLength); + + while(index > -1) { + subject.replace(index, index + match.length(), "RE:"); + index = subject.indexOf(match, prefixLength); + } + + // Reduce them to one at the beginning + match ="RE:"; + int indexRE = subject.indexOf(match, prefixLength) + match.length(); + index = subject.indexOf(match, indexRE); + while(index > 0) { + subject.delete(index, index + match.length()); + index = subject.indexOf(match, indexRE); + } + + // Reduce blanks + match = " "; + index = subject.indexOf(match, prefixLength); + while(index > -1) { + subject.replace(index, index + match.length(), " "); + index = subject.indexOf(match, prefixLength); + } + return subject.toString(); + } + +} --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]