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 be...@apache.org on 2006/09/27 13:55:46 UTC

svn commit: r450409 - in /james/postage/trunk: ./ src/main/java/org/apache/james/postage/ src/main/java/org/apache/james/postage/classloading/ src/main/java/org/apache/james/postage/client/ src/main/java/org/apache/james/postage/mail/ src/main/java/org...

Author: berndf
Date: Wed Sep 27 04:55:44 2006
New Revision: 450409

URL: http://svn.apache.org/viewvc?view=rev&rev=450409
Log:
added fixcrlf to ant build file.
apart from that, no effective code changes, just format adjustments and copyright header

Modified:
    james/postage/trunk/build.xml
    james/postage/trunk/src/main/java/org/apache/james/postage/PostageRunner.java
    james/postage/trunk/src/main/java/org/apache/james/postage/PostageRuntimeException.java
    james/postage/trunk/src/main/java/org/apache/james/postage/classloading/CachedInstanceFactory.java
    james/postage/trunk/src/main/java/org/apache/james/postage/client/POP3Client.java
    james/postage/trunk/src/main/java/org/apache/james/postage/client/POP3MailAnalyzeStrategy.java
    james/postage/trunk/src/main/java/org/apache/james/postage/mail/AbstractMailFactory.java
    james/postage/trunk/src/main/java/org/apache/james/postage/mail/DefaultMailFactory.java
    james/postage/trunk/src/main/java/org/apache/james/postage/mail/DefaultMailValidator.java
    james/postage/trunk/src/main/java/org/apache/james/postage/mail/MailAnalyzeStrategy.java
    james/postage/trunk/src/main/java/org/apache/james/postage/mail/MailMatchingUtils.java
    james/postage/trunk/src/main/java/org/apache/james/postage/mail/MailValidator.java
    james/postage/trunk/src/main/java/org/apache/james/postage/result/MailProcessingRecord.java
    james/postage/trunk/src/main/java/org/apache/james/postage/result/PostageRunnerResultImpl.java
    james/postage/trunk/src/main/java/org/apache/james/postage/smtpserver/SMTPMailAnalyzeStrategy.java
    james/postage/trunk/src/main/java/org/apache/james/postage/smtpserver/SimpleMailServer.java

Modified: james/postage/trunk/build.xml
URL: http://svn.apache.org/viewvc/james/postage/trunk/build.xml?view=diff&rev=450409&r1=450408&r2=450409
==============================================================================
--- james/postage/trunk/build.xml (original)
+++ james/postage/trunk/build.xml Wed Sep 27 04:55:44 2006
@@ -86,6 +86,8 @@
     </target>
 
     <target name="init-compiler-sources">
+        <fixcrlf srcdir="${dir.source.classes}" includes="**/*.java" eol="lf" tab="remove" tablength="4" />
+        
         <copy todir="${dir.build.source}"  >
             <fileset dir="${dir.source.classes}" >
                 <include name="**/*.java" />

Modified: james/postage/trunk/src/main/java/org/apache/james/postage/PostageRunner.java
URL: http://svn.apache.org/viewvc/james/postage/trunk/src/main/java/org/apache/james/postage/PostageRunner.java?view=diff&rev=450409&r1=450408&r2=450409
==============================================================================
--- james/postage/trunk/src/main/java/org/apache/james/postage/PostageRunner.java (original)
+++ james/postage/trunk/src/main/java/org/apache/james/postage/PostageRunner.java Wed Sep 27 04:55:44 2006
@@ -81,7 +81,7 @@
     private static String m_messageIdPrefix = null;
 
     public static String getMessageIdPrefix() {
-    	return m_messageIdPrefix + "-";
+        return m_messageIdPrefix + "-";
     }
 
     /**
@@ -96,9 +96,9 @@
      * @param postageConfiguration
      */
     public PostageRunner(PostageConfiguration postageConfiguration) {
-    	m_messageIdPrefix = "" + System.currentTimeMillis();
+        m_messageIdPrefix = "" + System.currentTimeMillis();
 
-    	m_postageConfiguration = postageConfiguration;
+        m_postageConfiguration = postageConfiguration;
 
         int totalMailsPerMin = m_postageConfiguration.getTotalMailsPerMin();
         int durationMinutes = m_postageConfiguration.getDurationMinutes();

Modified: james/postage/trunk/src/main/java/org/apache/james/postage/PostageRuntimeException.java
URL: http://svn.apache.org/viewvc/james/postage/trunk/src/main/java/org/apache/james/postage/PostageRuntimeException.java?view=diff&rev=450409&r1=450408&r2=450409
==============================================================================
--- james/postage/trunk/src/main/java/org/apache/james/postage/PostageRuntimeException.java (original)
+++ james/postage/trunk/src/main/java/org/apache/james/postage/PostageRuntimeException.java Wed Sep 27 04:55:44 2006
@@ -1,40 +1,40 @@
-/****************************************************************
- * 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.postage;
-
-/**
- * base exception for Postage
- */
-public class PostageRuntimeException extends RuntimeException {
-    public PostageRuntimeException() {
-        super();
-    }
-
-    public PostageRuntimeException(String message) {
-        super(message);
-    }
-
-    public PostageRuntimeException(Throwable cause) {
-        super(cause);
-    }
-
-    public PostageRuntimeException(String message, Throwable cause) {
-        super(message, cause);
-    }
-}
+/****************************************************************
+ * 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.postage;
+
+/**
+ * base exception for Postage
+ */
+public class PostageRuntimeException extends RuntimeException {
+    public PostageRuntimeException() {
+        super();
+    }
+
+    public PostageRuntimeException(String message) {
+        super(message);
+    }
+
+    public PostageRuntimeException(Throwable cause) {
+        super(cause);
+    }
+
+    public PostageRuntimeException(String message, Throwable cause) {
+        super(message, cause);
+    }
+}

Modified: james/postage/trunk/src/main/java/org/apache/james/postage/classloading/CachedInstanceFactory.java
URL: http://svn.apache.org/viewvc/james/postage/trunk/src/main/java/org/apache/james/postage/classloading/CachedInstanceFactory.java?view=diff&rev=450409&r1=450408&r2=450409
==============================================================================
--- james/postage/trunk/src/main/java/org/apache/james/postage/classloading/CachedInstanceFactory.java (original)
+++ james/postage/trunk/src/main/java/org/apache/james/postage/classloading/CachedInstanceFactory.java Wed Sep 27 04:55:44 2006
@@ -1,58 +1,58 @@
-/****************************************************************
- * 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.postage.classloading;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-public class CachedInstanceFactory {
-
-    private static Log log = LogFactory.getLog(CachedInstanceFactory.class);
-
-    private final static Map m_classes = new HashMap();
-
-	public static Object createInstance(String classname) {
-        Object object = null;
-
-        Class clazz = null;
-        // class is configured, but not yet loaded
-        if (classname != null && m_classes.get(classname) == null) {
-            try {
-                clazz = Class.forName(classname);
-            } catch (ClassNotFoundException e) {
-                log.error("failed to load class " + classname, e);
-            }
-        }
-
-        // create instance, if custom class is given
-        if (clazz != null) {
-            try {
-                object = clazz.newInstance();
-            } catch (Exception e) {
-                log.error("failed to create instance of class " + classname, e);
-            }
-        }
-
-        return object;
-    }
-
-}
+/****************************************************************
+ * 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.postage.classloading;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class CachedInstanceFactory {
+
+    private static Log log = LogFactory.getLog(CachedInstanceFactory.class);
+
+    private final static Map m_classes = new HashMap();
+
+    public static Object createInstance(String classname) {
+        Object object = null;
+
+        Class clazz = null;
+        // class is configured, but not yet loaded
+        if (classname != null && m_classes.get(classname) == null) {
+            try {
+                clazz = Class.forName(classname);
+            } catch (ClassNotFoundException e) {
+                log.error("failed to load class " + classname, e);
+            }
+        }
+
+        // create instance, if custom class is given
+        if (clazz != null) {
+            try {
+                object = clazz.newInstance();
+            } catch (Exception e) {
+                log.error("failed to create instance of class " + classname, e);
+            }
+        }
+
+        return object;
+    }
+
+}

Modified: james/postage/trunk/src/main/java/org/apache/james/postage/client/POP3Client.java
URL: http://svn.apache.org/viewvc/james/postage/trunk/src/main/java/org/apache/james/postage/client/POP3Client.java?view=diff&rev=450409&r1=450408&r2=450409
==============================================================================
--- james/postage/trunk/src/main/java/org/apache/james/postage/client/POP3Client.java (original)
+++ james/postage/trunk/src/main/java/org/apache/james/postage/client/POP3Client.java Wed Sep 27 04:55:44 2006
@@ -121,10 +121,10 @@
                 POP3MessageInfo entry = entries[i];
 
                 try {
-					new POP3MailAnalyzeStrategy("pop3", m_results, pop3Client, entry.number, i).handle();
-				} catch (Exception exception) {
-					log.warn("error processing pop3 mail", exception);
-				}
+                    new POP3MailAnalyzeStrategy("pop3", m_results, pop3Client, entry.number, i).handle();
+                } catch (Exception exception) {
+                    log.warn("error processing pop3 mail", exception);
+                }
             }
 
             closeSession(pop3Client);

Modified: james/postage/trunk/src/main/java/org/apache/james/postage/client/POP3MailAnalyzeStrategy.java
URL: http://svn.apache.org/viewvc/james/postage/trunk/src/main/java/org/apache/james/postage/client/POP3MailAnalyzeStrategy.java?view=diff&rev=450409&r1=450408&r2=450409
==============================================================================
--- james/postage/trunk/src/main/java/org/apache/james/postage/client/POP3MailAnalyzeStrategy.java (original)
+++ james/postage/trunk/src/main/java/org/apache/james/postage/client/POP3MailAnalyzeStrategy.java Wed Sep 27 04:55:44 2006
@@ -1,99 +1,99 @@
-/****************************************************************
- * 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.postage.client;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.Reader;
-
-import javax.mail.MessagingException;
-import javax.mail.internet.MimeMessage;
-
-import org.apache.james.fetchmail.ReaderInputStream;
-import org.apache.james.postage.mail.MailAnalyzeStrategy;
-import org.apache.james.postage.result.PostageRunnerResult;
-
-public class POP3MailAnalyzeStrategy extends MailAnalyzeStrategy {
-
-	private int mailNumber;
-	private int mailIndex;
-	private org.apache.commons.net.pop3.POP3Client pop3Client;
-
-	public POP3MailAnalyzeStrategy(String receivingQueueName, PostageRunnerResult results, 
-								   org.apache.commons.net.pop3.POP3Client pop3Client, 
-								   int mailNumber, int mailIndex) {
-		super(receivingQueueName, results);
-		this.pop3Client = pop3Client;
-		this.mailNumber = mailNumber;
-		this.mailIndex = mailIndex;
-	}
-
-	protected MimeMessage loadMessage() throws Exception {
-		Reader reader = pop3Client.retrieveMessage(mailNumber);
-        BufferedReader mailReader = new BufferedReader(reader);
-		InputStream in = new ReaderInputStream(mailReader);
-		MimeMessage message;
-		try {
-			message = new MimeMessage(null, in);
-			in.close();
-		} catch (IOException e) {
-			log.info("failed to close POP3 mail reader.");
-			throw e;
-		} catch (MessagingException e) {
-			log.info("failed to process POP3 mail. remains on server");
-			throw e;
-		} finally {
-            if (in != null) {
-                try {
-                    in.close();
-                } catch (IOException e) {
-                    log.warn("error closing mail input stream");
-                }
-            }
-            if (mailReader != null) {
-                try {
-                	mailReader.close();
-                } catch (IOException e) {
-                    log.warn("error closing mail reader");
-                }
-            }
-            if (reader != null) {
-                try {
-                    reader.close();
-                } catch (IOException e) {
-                    log.warn("error closing (mail) reader");
-                }
-            }
-        }
-
-		return message;
-	}
-	
-	protected void dismissMessage() throws Exception {
-        try {
-            pop3Client.deleteMessage(mailIndex + 1); // don't retrieve again next time
-        } catch (Exception e) {
-            log.info("failed to delete POP3 mail.");
-            throw e;
-        }
-    }
-
-
-}
+/****************************************************************
+ * 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.postage.client;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+
+import javax.mail.MessagingException;
+import javax.mail.internet.MimeMessage;
+
+import org.apache.james.fetchmail.ReaderInputStream;
+import org.apache.james.postage.mail.MailAnalyzeStrategy;
+import org.apache.james.postage.result.PostageRunnerResult;
+
+public class POP3MailAnalyzeStrategy extends MailAnalyzeStrategy {
+
+    private int mailNumber;
+    private int mailIndex;
+    private org.apache.commons.net.pop3.POP3Client pop3Client;
+
+    public POP3MailAnalyzeStrategy(String receivingQueueName, PostageRunnerResult results, 
+                                   org.apache.commons.net.pop3.POP3Client pop3Client, 
+                                   int mailNumber, int mailIndex) {
+        super(receivingQueueName, results);
+        this.pop3Client = pop3Client;
+        this.mailNumber = mailNumber;
+        this.mailIndex = mailIndex;
+    }
+
+    protected MimeMessage loadMessage() throws Exception {
+        Reader reader = pop3Client.retrieveMessage(mailNumber);
+        BufferedReader mailReader = new BufferedReader(reader);
+        InputStream in = new ReaderInputStream(mailReader);
+        MimeMessage message;
+        try {
+            message = new MimeMessage(null, in);
+            in.close();
+        } catch (IOException e) {
+            log.info("failed to close POP3 mail reader.");
+            throw e;
+        } catch (MessagingException e) {
+            log.info("failed to process POP3 mail. remains on server");
+            throw e;
+        } finally {
+            if (in != null) {
+                try {
+                    in.close();
+                } catch (IOException e) {
+                    log.warn("error closing mail input stream");
+                }
+            }
+            if (mailReader != null) {
+                try {
+                    mailReader.close();
+                } catch (IOException e) {
+                    log.warn("error closing mail reader");
+                }
+            }
+            if (reader != null) {
+                try {
+                    reader.close();
+                } catch (IOException e) {
+                    log.warn("error closing (mail) reader");
+                }
+            }
+        }
+
+        return message;
+    }
+    
+    protected void dismissMessage() throws Exception {
+        try {
+            pop3Client.deleteMessage(mailIndex + 1); // don't retrieve again next time
+        } catch (Exception e) {
+            log.info("failed to delete POP3 mail.");
+            throw e;
+        }
+    }
+
+
+}

Modified: james/postage/trunk/src/main/java/org/apache/james/postage/mail/AbstractMailFactory.java
URL: http://svn.apache.org/viewvc/james/postage/trunk/src/main/java/org/apache/james/postage/mail/AbstractMailFactory.java?view=diff&rev=450409&r1=450408&r2=450409
==============================================================================
--- james/postage/trunk/src/main/java/org/apache/james/postage/mail/AbstractMailFactory.java (original)
+++ james/postage/trunk/src/main/java/org/apache/james/postage/mail/AbstractMailFactory.java Wed Sep 27 04:55:44 2006
@@ -1,92 +1,110 @@
-package org.apache.james.postage.mail;
-
-import javax.mail.Message;
-import javax.mail.MessagingException;
-import javax.mail.Session;
-import javax.mail.internet.MimeMessage;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.james.postage.configuration.MailSender;
-import org.apache.james.postage.result.MailProcessingRecord;
-
-public abstract class AbstractMailFactory {
-
-	private static Log log = LogFactory.getLog(DefaultMailFactory.class);
-
-	private static final char[] CHARSET = new char[]
-	                                {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
-	                                 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
-	                                 'u', 'v', 'w', 'x', 'y', 'z',
-	                                 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
-	                                 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
-	                                 'U', 'V', 'W', 'X', 'Y', 'Z'};
-
-	public static char getRandomChar() {
-	    return CHARSET[getRandomInt()];
-	}
-
-	private static int getRandomInt() {
-	    return (int)(Math.random() * (double)(CHARSET.length - 1));
-	}
-
-	public static byte getRandomByte() {
-	    return (byte)CHARSET[getRandomInt()];
-	}
-
-	public AbstractMailFactory() {
-		super();
-	}
-
-	/**
-	 * generates a mail containing data common to all test mails: postage headers, 
-	 */
-	public Message createMail(Session mailSession, MailSender mailSender, MailProcessingRecord mailProcessingRecord) {
-	    
-		MimeMessage message = new MimeMessage(mailSession);
-	
-	    try {
-	        message.addHeader(HeaderConstants.JAMES_POSTAGE_HEADER, "This is a test mail sent by James Postage");
-	        message.addHeader(HeaderConstants.JAMES_POSTAGE_VALIDATORCLASSNAME_HEADER, getValidatorClass().getName());
-	        message.setSubject(mailSender.getSubject());
-	        message.addHeader("Message-ID", "Postage-" + System.currentTimeMillis());
-	        mailProcessingRecord.setSubject(mailSender.getSubject());
-	
-	        if (mailProcessingRecord.getMailId() != null) {
-	            message.addHeader(HeaderConstants.MAIL_ID_HEADER, mailProcessingRecord.getMailId());
-	        } else {
-	        	log.warn("ID header is NULL!");
-	        	throw new RuntimeException("could not create mail with ID = NULL");
-	        }
-	
-	        populateMessage(message, mailSender, mailProcessingRecord);
-	
-	    } catch (MessagingException e) {
-	        mailProcessingRecord.setErrorTextSending(e.toString());
-	        log.error("mail could not be created", e);
-	        return null;
-	    }
-	    return message;
-	}
-
-	/**
-	 * here, the test case specific data must be added to the message.
-	 * @param message
-	 * @param mailSender
-	 * @param mailProcessingRecord
-	 * @throws MessagingException
-	 */
-	abstract protected void populateMessage(MimeMessage message, MailSender mailSender, MailProcessingRecord mailProcessingRecord) throws MessagingException;
-
-	/**
-	 * the class representing the validator 
-	 * 
-	 * @return validator class
-	 */
-	abstract protected Class getValidatorClass();
-	
-	protected int generateRandomPartSize(int sizeMin, int sizeMax) {
-	    return (int)(Math.random() * (double)(sizeMax - sizeMin)) + sizeMin;
-	}
-
-}
\ No newline at end of file
+/****************************************************************
+ * 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.postage.mail;
+
+import javax.mail.Message;
+import javax.mail.MessagingException;
+import javax.mail.Session;
+import javax.mail.internet.MimeMessage;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.james.postage.configuration.MailSender;
+import org.apache.james.postage.result.MailProcessingRecord;
+
+public abstract class AbstractMailFactory {
+
+    private static Log log = LogFactory.getLog(DefaultMailFactory.class);
+
+    private static final char[] CHARSET = new char[]
+                                    {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
+                                     'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
+                                     'u', 'v', 'w', 'x', 'y', 'z',
+                                     'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
+                                     'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
+                                     'U', 'V', 'W', 'X', 'Y', 'Z'};
+
+    public static char getRandomChar() {
+        return CHARSET[getRandomInt()];
+    }
+
+    private static int getRandomInt() {
+        return (int)(Math.random() * (double)(CHARSET.length - 1));
+    }
+
+    public static byte getRandomByte() {
+        return (byte)CHARSET[getRandomInt()];
+    }
+
+    public AbstractMailFactory() {
+        super();
+    }
+
+    /**
+     * generates a mail containing data common to all test mails: postage headers, 
+     */
+    public Message createMail(Session mailSession, MailSender mailSender, MailProcessingRecord mailProcessingRecord) {
+        
+        MimeMessage message = new MimeMessage(mailSession);
+    
+        try {
+            message.addHeader(HeaderConstants.JAMES_POSTAGE_HEADER, "This is a test mail sent by James Postage");
+            message.addHeader(HeaderConstants.JAMES_POSTAGE_VALIDATORCLASSNAME_HEADER, getValidatorClass().getName());
+            message.setSubject(mailSender.getSubject());
+            message.addHeader("Message-ID", "Postage-" + System.currentTimeMillis());
+            mailProcessingRecord.setSubject(mailSender.getSubject());
+    
+            if (mailProcessingRecord.getMailId() != null) {
+                message.addHeader(HeaderConstants.MAIL_ID_HEADER, mailProcessingRecord.getMailId());
+            } else {
+                log.warn("ID header is NULL!");
+                throw new RuntimeException("could not create mail with ID = NULL");
+            }
+    
+            populateMessage(message, mailSender, mailProcessingRecord);
+    
+        } catch (MessagingException e) {
+            mailProcessingRecord.setErrorTextSending(e.toString());
+            log.error("mail could not be created", e);
+            return null;
+        }
+        return message;
+    }
+
+    /**
+     * here, the test case specific data must be added to the message.
+     * @param message
+     * @param mailSender
+     * @param mailProcessingRecord
+     * @throws MessagingException
+     */
+    abstract protected void populateMessage(MimeMessage message, MailSender mailSender, MailProcessingRecord mailProcessingRecord) throws MessagingException;
+
+    /**
+     * the class representing the validator 
+     * 
+     * @return validator class
+     */
+    abstract protected Class getValidatorClass();
+    
+    protected int generateRandomPartSize(int sizeMin, int sizeMax) {
+        return (int)(Math.random() * (double)(sizeMax - sizeMin)) + sizeMin;
+    }
+
+}

Modified: james/postage/trunk/src/main/java/org/apache/james/postage/mail/DefaultMailFactory.java
URL: http://svn.apache.org/viewvc/james/postage/trunk/src/main/java/org/apache/james/postage/mail/DefaultMailFactory.java?view=diff&rev=450409&r1=450408&r2=450409
==============================================================================
--- james/postage/trunk/src/main/java/org/apache/james/postage/mail/DefaultMailFactory.java (original)
+++ james/postage/trunk/src/main/java/org/apache/james/postage/mail/DefaultMailFactory.java Wed Sep 27 04:55:44 2006
@@ -33,49 +33,49 @@
 
 public class DefaultMailFactory extends AbstractMailFactory implements MailFactory {
 
-	protected void populateMessage(MimeMessage message, MailSender mailSender, MailProcessingRecord mailProcessingRecord) throws MessagingException {
+    protected void populateMessage(MimeMessage message, MailSender mailSender, MailProcessingRecord mailProcessingRecord) throws MessagingException {
         message.addHeader("Mime-Version", "1.0");
         message.addHeader("Content-Type", "multipart/mixed");
 
-		Multipart multipart = new MimeMultipart("mixed");
+        Multipart multipart = new MimeMultipart("mixed");
 
-		if (mailSender.sendTextPart()) {
-		    int sizeMinText = mailSender.getSizeMinText();
-		    int sizeMaxText = mailSender.getSizeMaxText();
-		    MimeBodyPart part = new MimeBodyPart();
+        if (mailSender.sendTextPart()) {
+            int sizeMinText = mailSender.getSizeMinText();
+            int sizeMaxText = mailSender.getSizeMaxText();
+            MimeBodyPart part = new MimeBodyPart();
 
-		    int mailSize = generateRandomPartSize(sizeMinText, sizeMaxText);
-		    mailProcessingRecord.setByteSendText(mailSize);
+            int mailSize = generateRandomPartSize(sizeMinText, sizeMaxText);
+            mailProcessingRecord.setByteSendText(mailSize);
 
-		    StringBuffer textBody = new StringBuffer(mailSize);
-		    for (int i = 0; i < mailSize; i++) textBody.append(getRandomChar());
+            StringBuffer textBody = new StringBuffer(mailSize);
+            for (int i = 0; i < mailSize; i++) textBody.append(getRandomChar());
 
-		    part.setText(textBody.toString());
+            part.setText(textBody.toString());
 
 //                part.setDataHandler(new DataHandler(textBody.toString(), "text/plain"));
-		    
-		    multipart.addBodyPart(part);
-		}
-
-		if (mailSender.sendBinaryPart()) {
-		    int sizeMinBinary = mailSender.getSizeMinBinary();
-		    int sizeMaxBinary = mailSender.getSizeMaxBinary();
-		    MimeBodyPart part = new MimeBodyPart();
-
-		    int mailSize = generateRandomPartSize(sizeMinBinary, sizeMaxBinary);
-		    mailProcessingRecord.setByteSendBinary(mailSize);
-
-		    byte[] bytes = new byte[mailSize];
-		    for (int i = 0; i < mailSize; i++) bytes[i] = getRandomByte();
-
-		    part.setDataHandler(new DataHandler(new ByteArrayDataSource(bytes, "application/octet-stream")));
-		    multipart.addBodyPart(part);
-		}
-		message.setContent(multipart);
-	}
-	
-	protected Class getValidatorClass() {
-		return DefaultMailValidator.class;
-	}
+            
+            multipart.addBodyPart(part);
+        }
+
+        if (mailSender.sendBinaryPart()) {
+            int sizeMinBinary = mailSender.getSizeMinBinary();
+            int sizeMaxBinary = mailSender.getSizeMaxBinary();
+            MimeBodyPart part = new MimeBodyPart();
+
+            int mailSize = generateRandomPartSize(sizeMinBinary, sizeMaxBinary);
+            mailProcessingRecord.setByteSendBinary(mailSize);
+
+            byte[] bytes = new byte[mailSize];
+            for (int i = 0; i < mailSize; i++) bytes[i] = getRandomByte();
+
+            part.setDataHandler(new DataHandler(new ByteArrayDataSource(bytes, "application/octet-stream")));
+            multipart.addBodyPart(part);
+        }
+        message.setContent(multipart);
+    }
+    
+    protected Class getValidatorClass() {
+        return DefaultMailValidator.class;
+    }
 
 }

Modified: james/postage/trunk/src/main/java/org/apache/james/postage/mail/DefaultMailValidator.java
URL: http://svn.apache.org/viewvc/james/postage/trunk/src/main/java/org/apache/james/postage/mail/DefaultMailValidator.java?view=diff&rev=450409&r1=450408&r2=450409
==============================================================================
--- james/postage/trunk/src/main/java/org/apache/james/postage/mail/DefaultMailValidator.java (original)
+++ james/postage/trunk/src/main/java/org/apache/james/postage/mail/DefaultMailValidator.java Wed Sep 27 04:55:44 2006
@@ -1,54 +1,54 @@
-/****************************************************************
- * 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.postage.mail;
-
-import javax.mail.Message;
-import javax.mail.MessagingException;
-import javax.mail.internet.MimeMultipart;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.james.postage.result.MailProcessingRecord;
-
-public class DefaultMailValidator implements MailValidator {
-
-    private static Log log = LogFactory.getLog(DefaultMailValidator.class);
-
-	public boolean validate(Message message, MailProcessingRecord record) {
-
-		MimeMultipart mimeMultipart;
-		try {
-			mimeMultipart = new MimeMultipart(message.getDataHandler().getDataSource());
-		} catch (MessagingException e) {
-			return false;
-		}
-
-		// figuring out the parts created by DefaultMailFactory
-        int textPartSize = MailMatchingUtils.getMimePartSize(mimeMultipart, "text/plain");
-        record.setByteReceivedText(textPartSize);
-        int binaryPartSize = MailMatchingUtils.getMimePartSize(mimeMultipart, "application/octet-stream");
-		record.setByteReceivedBinary(binaryPartSize);
-        
-        boolean textPartValid = textPartSize == record.getByteSendText();
-		boolean binaryPartValid = binaryPartSize == record.getByteSendBinary();
-		boolean valid = textPartValid && binaryPartValid;
-		return valid;
-	}
-
-}
+/****************************************************************
+ * 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.postage.mail;
+
+import javax.mail.Message;
+import javax.mail.MessagingException;
+import javax.mail.internet.MimeMultipart;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.james.postage.result.MailProcessingRecord;
+
+public class DefaultMailValidator implements MailValidator {
+
+    private static Log log = LogFactory.getLog(DefaultMailValidator.class);
+
+    public boolean validate(Message message, MailProcessingRecord record) {
+
+        MimeMultipart mimeMultipart;
+        try {
+            mimeMultipart = new MimeMultipart(message.getDataHandler().getDataSource());
+        } catch (MessagingException e) {
+            return false;
+        }
+
+        // figuring out the parts created by DefaultMailFactory
+        int textPartSize = MailMatchingUtils.getMimePartSize(mimeMultipart, "text/plain");
+        record.setByteReceivedText(textPartSize);
+        int binaryPartSize = MailMatchingUtils.getMimePartSize(mimeMultipart, "application/octet-stream");
+        record.setByteReceivedBinary(binaryPartSize);
+        
+        boolean textPartValid = textPartSize == record.getByteSendText();
+        boolean binaryPartValid = binaryPartSize == record.getByteSendBinary();
+        boolean valid = textPartValid && binaryPartValid;
+        return valid;
+    }
+
+}

Modified: james/postage/trunk/src/main/java/org/apache/james/postage/mail/MailAnalyzeStrategy.java
URL: http://svn.apache.org/viewvc/james/postage/trunk/src/main/java/org/apache/james/postage/mail/MailAnalyzeStrategy.java?view=diff&rev=450409&r1=450408&r2=450409
==============================================================================
--- james/postage/trunk/src/main/java/org/apache/james/postage/mail/MailAnalyzeStrategy.java (original)
+++ james/postage/trunk/src/main/java/org/apache/james/postage/mail/MailAnalyzeStrategy.java Wed Sep 27 04:55:44 2006
@@ -1,94 +1,94 @@
-/****************************************************************
- * 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.postage.mail;
-
-import javax.mail.MessagingException;
-import javax.mail.internet.MimeMessage;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.james.postage.result.MailProcessingRecord;
-import org.apache.james.postage.result.PostageRunnerResult;
-
-/**
- * handles the process of retrieving, analyzing and finally (optionally) dismissing the 
- */
-public abstract class MailAnalyzeStrategy {
-
-    protected static Log log = LogFactory.getLog(MailAnalyzeStrategy.class);
-
-    private String queue = null;
-    private PostageRunnerResult results = null;
-
-    public MailAnalyzeStrategy(String receivingQueueName, PostageRunnerResult results) {
-    	this.queue = receivingQueueName;
-    	this.results = results;
-	}
-    
-    public void handle() throws Exception { 
-    	MailProcessingRecord mailProcessingRecord = prepareRecord();
-
-    	MimeMessage message = loadMessage();
-    	
-    	// do we _really_ have to handle this?
-    	if (!MailMatchingUtils.isMatchCandidate(message)) return;
-
-	    String id = MailMatchingUtils.getMailIdHeader(message);
-	    try {
-	        mailProcessingRecord.setByteReceivedTotal(message.getSize());
-	
-	        mailProcessingRecord.setMailId(id);
-	        mailProcessingRecord.setSubject(message.getSubject());
-	
-	        mailProcessingRecord.setTimeFetchEnd(System.currentTimeMillis());
-	
-	    } catch (MessagingException e) {
-	        log.info(queue + ": failed to process mail. remains on server");
-	        return;
-	    } finally {
-	    	MailProcessingRecord matchedAndMergedRecord = results.matchMailRecord(mailProcessingRecord);
-	        if (matchedAndMergedRecord != null) {
-	        	MailMatchingUtils.validateMail(message, matchedAndMergedRecord);
-	        	results.recordValidatedMatch(matchedAndMergedRecord);
-	        }
-	    }
-    
-	    dismissMessage();
-    }
-
-    /** 
-     * mandatory override to make the message available
-     */
-	protected MimeMessage loadMessage() throws Exception {
-		return null;
-	}
-
-	/**
-	 * optional override to delete the message.
-	 */
-	protected void dismissMessage() throws Exception {
-		; // empty body
-	}
-	
-	private MailProcessingRecord prepareRecord() {
-		MailProcessingRecord mailProcessingRecord = new MailProcessingRecord();
-		mailProcessingRecord.setReceivingQueue(queue);
-		mailProcessingRecord.setTimeFetchStart(System.currentTimeMillis());
-		return mailProcessingRecord;
-	}
-}
+/****************************************************************
+ * 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.postage.mail;
+
+import javax.mail.MessagingException;
+import javax.mail.internet.MimeMessage;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.james.postage.result.MailProcessingRecord;
+import org.apache.james.postage.result.PostageRunnerResult;
+
+/**
+ * handles the process of retrieving, analyzing and finally (optionally) dismissing the 
+ */
+public abstract class MailAnalyzeStrategy {
+
+    protected static Log log = LogFactory.getLog(MailAnalyzeStrategy.class);
+
+    private String queue = null;
+    private PostageRunnerResult results = null;
+
+    public MailAnalyzeStrategy(String receivingQueueName, PostageRunnerResult results) {
+        this.queue = receivingQueueName;
+        this.results = results;
+    }
+    
+    public void handle() throws Exception { 
+        MailProcessingRecord mailProcessingRecord = prepareRecord();
+
+        MimeMessage message = loadMessage();
+        
+        // do we _really_ have to handle this?
+        if (!MailMatchingUtils.isMatchCandidate(message)) return;
+
+        String id = MailMatchingUtils.getMailIdHeader(message);
+        try {
+            mailProcessingRecord.setByteReceivedTotal(message.getSize());
+    
+            mailProcessingRecord.setMailId(id);
+            mailProcessingRecord.setSubject(message.getSubject());
+    
+            mailProcessingRecord.setTimeFetchEnd(System.currentTimeMillis());
+    
+        } catch (MessagingException e) {
+            log.info(queue + ": failed to process mail. remains on server");
+            return;
+        } finally {
+            MailProcessingRecord matchedAndMergedRecord = results.matchMailRecord(mailProcessingRecord);
+            if (matchedAndMergedRecord != null) {
+                MailMatchingUtils.validateMail(message, matchedAndMergedRecord);
+                results.recordValidatedMatch(matchedAndMergedRecord);
+            }
+        }
+    
+        dismissMessage();
+    }
+
+    /** 
+     * mandatory override to make the message available
+     */
+    protected MimeMessage loadMessage() throws Exception {
+        return null;
+    }
+
+    /**
+     * optional override to delete the message.
+     */
+    protected void dismissMessage() throws Exception {
+        ; // empty body
+    }
+    
+    private MailProcessingRecord prepareRecord() {
+        MailProcessingRecord mailProcessingRecord = new MailProcessingRecord();
+        mailProcessingRecord.setReceivingQueue(queue);
+        mailProcessingRecord.setTimeFetchStart(System.currentTimeMillis());
+        return mailProcessingRecord;
+    }
+}

Modified: james/postage/trunk/src/main/java/org/apache/james/postage/mail/MailMatchingUtils.java
URL: http://svn.apache.org/viewvc/james/postage/trunk/src/main/java/org/apache/james/postage/mail/MailMatchingUtils.java?view=diff&rev=450409&r1=450408&r2=450409
==============================================================================
--- james/postage/trunk/src/main/java/org/apache/james/postage/mail/MailMatchingUtils.java (original)
+++ james/postage/trunk/src/main/java/org/apache/james/postage/mail/MailMatchingUtils.java Wed Sep 27 04:55:44 2006
@@ -1,150 +1,150 @@
-/****************************************************************
- * 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.postage.mail;
-
-import org.apache.james.postage.PostageRunner;
-import org.apache.james.postage.PostageRuntimeException;
-import org.apache.james.postage.classloading.CachedInstanceFactory;
-import org.apache.james.postage.result.MailProcessingRecord;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import javax.mail.BodyPart;
-import javax.mail.MessagingException;
-import javax.mail.internet.MimeMessage;
-import javax.mail.internet.MimeMultipart;
-
-import java.util.regex.Pattern;
-
-/**
- * helps matching, analysing and validating result mails and sent test mails
- */
-public class MailMatchingUtils {
-
-    private static Log log = LogFactory.getLog(MailMatchingUtils.class);
-
-    /**
-     * if this mail was created by postage, whatever run - but by startup check
-     */
-    public static boolean isPostageStartupCheckMail(MimeMessage message) {
-        String headerValue = getMailIdHeader(message);
-        return HeaderConstants.JAMES_POSTAGE_STARTUPCHECK_HEADER_ID.equals(headerValue);
-    }
-
-    /**
-     * if this mail was created by postage, whatever run - but not by startup check
-     */
-    public static boolean isPostageTestMail(MimeMessage message) {
-        return isPostageMail(message) && !isPostageStartupCheckMail(message);
-    }
-
-    /**
-     * if this mail was created by postage, whatever run - if startup check or live test
-     */
-    public static boolean isPostageMail(MimeMessage message) {
-        return null != getUniqueHeader(message, HeaderConstants.JAMES_POSTAGE_HEADER);
-    }
-
-    public static boolean isPostageIdHeaderPresent(MimeMessage message) {
-        return null != getMailIdHeader(message);
-    }
-
-    public static String getMailIdHeader(MimeMessage message) {
-        return getUniqueHeader(message, HeaderConstants.MAIL_ID_HEADER);
-    }
-
-    /**
-     * if this mail was created by the currently running postage scenario - not by
-     * any of those before.
-     */
-    public static boolean isCurrentRunnerMail(MimeMessage message) {
-        String headerValue = getMailIdHeader(message);
-        return headerValue != null && headerValue.startsWith(PostageRunner.getMessageIdPrefix());
-    }
-
-    public static boolean matchHeader(MimeMessage message, String header, String valueRegex) {
-        return Pattern.matches(valueRegex, getUniqueHeader(message, header));
-    }
-
-    public static String getUniqueHeader(MimeMessage message, String header) {
-        String[] idHeaders;
-        try {
-            idHeaders = message.getHeader(header);
-        } catch (MessagingException e) {
-            throw new PostageRuntimeException(e);
-        }
-        if (idHeaders != null && idHeaders.length > 0) {
-            return idHeaders[0]; // there should be exactly one.
-        }
-        return null;
-    }
-
-    public static boolean isMatchCandidate(MimeMessage message) {
-        try {
-            if (!isPostageIdHeaderPresent(message)) {
-                if (isPostageMail(message)) {
-                    log.warn(HeaderConstants.MAIL_ID_HEADER + " header is missing from James test mail");
-                }
-                else log.info("skipping non-postage mail. remains on server. subject was: " + message.getSubject());
-                return false;
-            }
-        } catch (MessagingException e) {
-            log.info("failed to get mail subject for logging. remains on server. mails might be corrupt.");
-            return false;
-        }
-        if (MailMatchingUtils.isPostageStartupCheckMail(message)) return false;
-        return true;
-    }
-    
-    public static boolean validateMail(MimeMessage message, MailProcessingRecord mailProcessingRecord) {
-    	String classname = getUniqueHeader(message, HeaderConstants.JAMES_POSTAGE_VALIDATORCLASSNAME_HEADER);
-    	MailValidator validator = (MailValidator)CachedInstanceFactory.createInstance(classname);
-    	if (validator == null) return false;
-    	
-    	boolean isValid = validator.validate(message, mailProcessingRecord);
-    	if (isValid) mailProcessingRecord.setValid();
-		else log.warn("failed to validate mail");
-    	
-		return isValid;
-    }
-    
-    public static MimeMultipart convertToMimeMultipart(MimeMessage message) {
-        try {
-			return new MimeMultipart(message.getDataHandler().getDataSource());
-		} catch (MessagingException e) {
-			throw new RuntimeException("could not convert MimeMessage to MimeMultipart", e);
-		}
-    }
-    
-    public static int getMimePartSize(MimeMultipart parts, String mimeType) {
-        if (parts != null) {
-            try {
-                for (int i = 0; i < parts.getCount(); i++) {
-                    BodyPart bodyPart = parts.getBodyPart(i);
-                    if (bodyPart.getContentType().startsWith(mimeType)) {
-                        return bodyPart.getSize();
-                    }
-                }
-            } catch (MessagingException e) {
-                log.info("failed to process body parts.", e);
-            }
-        }
-        return 0;
-    }
-}
+/****************************************************************
+ * 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.postage.mail;
+
+import org.apache.james.postage.PostageRunner;
+import org.apache.james.postage.PostageRuntimeException;
+import org.apache.james.postage.classloading.CachedInstanceFactory;
+import org.apache.james.postage.result.MailProcessingRecord;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.mail.BodyPart;
+import javax.mail.MessagingException;
+import javax.mail.internet.MimeMessage;
+import javax.mail.internet.MimeMultipart;
+
+import java.util.regex.Pattern;
+
+/**
+ * helps matching, analysing and validating result mails and sent test mails
+ */
+public class MailMatchingUtils {
+
+    private static Log log = LogFactory.getLog(MailMatchingUtils.class);
+
+    /**
+     * if this mail was created by postage, whatever run - but by startup check
+     */
+    public static boolean isPostageStartupCheckMail(MimeMessage message) {
+        String headerValue = getMailIdHeader(message);
+        return HeaderConstants.JAMES_POSTAGE_STARTUPCHECK_HEADER_ID.equals(headerValue);
+    }
+
+    /**
+     * if this mail was created by postage, whatever run - but not by startup check
+     */
+    public static boolean isPostageTestMail(MimeMessage message) {
+        return isPostageMail(message) && !isPostageStartupCheckMail(message);
+    }
+
+    /**
+     * if this mail was created by postage, whatever run - if startup check or live test
+     */
+    public static boolean isPostageMail(MimeMessage message) {
+        return null != getUniqueHeader(message, HeaderConstants.JAMES_POSTAGE_HEADER);
+    }
+
+    public static boolean isPostageIdHeaderPresent(MimeMessage message) {
+        return null != getMailIdHeader(message);
+    }
+
+    public static String getMailIdHeader(MimeMessage message) {
+        return getUniqueHeader(message, HeaderConstants.MAIL_ID_HEADER);
+    }
+
+    /**
+     * if this mail was created by the currently running postage scenario - not by
+     * any of those before.
+     */
+    public static boolean isCurrentRunnerMail(MimeMessage message) {
+        String headerValue = getMailIdHeader(message);
+        return headerValue != null && headerValue.startsWith(PostageRunner.getMessageIdPrefix());
+    }
+
+    public static boolean matchHeader(MimeMessage message, String header, String valueRegex) {
+        return Pattern.matches(valueRegex, getUniqueHeader(message, header));
+    }
+
+    public static String getUniqueHeader(MimeMessage message, String header) {
+        String[] idHeaders;
+        try {
+            idHeaders = message.getHeader(header);
+        } catch (MessagingException e) {
+            throw new PostageRuntimeException(e);
+        }
+        if (idHeaders != null && idHeaders.length > 0) {
+            return idHeaders[0]; // there should be exactly one.
+        }
+        return null;
+    }
+
+    public static boolean isMatchCandidate(MimeMessage message) {
+        try {
+            if (!isPostageIdHeaderPresent(message)) {
+                if (isPostageMail(message)) {
+                    log.warn(HeaderConstants.MAIL_ID_HEADER + " header is missing from James test mail");
+                }
+                else log.info("skipping non-postage mail. remains on server. subject was: " + message.getSubject());
+                return false;
+            }
+        } catch (MessagingException e) {
+            log.info("failed to get mail subject for logging. remains on server. mails might be corrupt.");
+            return false;
+        }
+        if (MailMatchingUtils.isPostageStartupCheckMail(message)) return false;
+        return true;
+    }
+    
+    public static boolean validateMail(MimeMessage message, MailProcessingRecord mailProcessingRecord) {
+        String classname = getUniqueHeader(message, HeaderConstants.JAMES_POSTAGE_VALIDATORCLASSNAME_HEADER);
+        MailValidator validator = (MailValidator)CachedInstanceFactory.createInstance(classname);
+        if (validator == null) return false;
+        
+        boolean isValid = validator.validate(message, mailProcessingRecord);
+        if (isValid) mailProcessingRecord.setValid();
+        else log.warn("failed to validate mail");
+        
+        return isValid;
+    }
+    
+    public static MimeMultipart convertToMimeMultipart(MimeMessage message) {
+        try {
+            return new MimeMultipart(message.getDataHandler().getDataSource());
+        } catch (MessagingException e) {
+            throw new RuntimeException("could not convert MimeMessage to MimeMultipart", e);
+        }
+    }
+    
+    public static int getMimePartSize(MimeMultipart parts, String mimeType) {
+        if (parts != null) {
+            try {
+                for (int i = 0; i < parts.getCount(); i++) {
+                    BodyPart bodyPart = parts.getBodyPart(i);
+                    if (bodyPart.getContentType().startsWith(mimeType)) {
+                        return bodyPart.getSize();
+                    }
+                }
+            } catch (MessagingException e) {
+                log.info("failed to process body parts.", e);
+            }
+        }
+        return 0;
+    }
+}

Modified: james/postage/trunk/src/main/java/org/apache/james/postage/mail/MailValidator.java
URL: http://svn.apache.org/viewvc/james/postage/trunk/src/main/java/org/apache/james/postage/mail/MailValidator.java?view=diff&rev=450409&r1=450408&r2=450409
==============================================================================
--- james/postage/trunk/src/main/java/org/apache/james/postage/mail/MailValidator.java (original)
+++ james/postage/trunk/src/main/java/org/apache/james/postage/mail/MailValidator.java Wed Sep 27 04:55:44 2006
@@ -1,32 +1,32 @@
-/****************************************************************
- * 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.postage.mail;
-
-import javax.mail.Message;
-
-import org.apache.james.postage.result.MailProcessingRecord;
-
-/**
- * implementations validate matched and received messages by checking for the expected properties.
- * for example, they could check for spam-marking headers or mime parts.
- * most commonly, each MailValidator implementation matches one corresponding MailFactory.
- */
-public interface MailValidator {
-	public boolean validate(Message message, MailProcessingRecord record);
-}
+/****************************************************************
+ * 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.postage.mail;
+
+import javax.mail.Message;
+
+import org.apache.james.postage.result.MailProcessingRecord;
+
+/**
+ * implementations validate matched and received messages by checking for the expected properties.
+ * for example, they could check for spam-marking headers or mime parts.
+ * most commonly, each MailValidator implementation matches one corresponding MailFactory.
+ */
+public interface MailValidator {
+    public boolean validate(Message message, MailProcessingRecord record);
+}

Modified: james/postage/trunk/src/main/java/org/apache/james/postage/result/MailProcessingRecord.java
URL: http://svn.apache.org/viewvc/james/postage/trunk/src/main/java/org/apache/james/postage/result/MailProcessingRecord.java?view=diff&rev=450409&r1=450408&r2=450409
==============================================================================
--- james/postage/trunk/src/main/java/org/apache/james/postage/result/MailProcessingRecord.java (original)
+++ james/postage/trunk/src/main/java/org/apache/james/postage/result/MailProcessingRecord.java Wed Sep 27 04:55:44 2006
@@ -65,11 +65,11 @@
     }
     
     public void setValid() {
-    	isReceivedValid = true;
+        isReceivedValid = true;
     }
     
     public boolean isReceivedValid() {
-    	return isReceivedValid;
+        return isReceivedValid;
     }
 
     public long getTimeConnectStart() {

Modified: james/postage/trunk/src/main/java/org/apache/james/postage/result/PostageRunnerResultImpl.java
URL: http://svn.apache.org/viewvc/james/postage/trunk/src/main/java/org/apache/james/postage/result/PostageRunnerResultImpl.java?view=diff&rev=450409&r1=450408&r2=450409
==============================================================================
--- james/postage/trunk/src/main/java/org/apache/james/postage/result/PostageRunnerResultImpl.java (original)
+++ james/postage/trunk/src/main/java/org/apache/james/postage/result/PostageRunnerResultImpl.java Wed Sep 27 04:55:44 2006
@@ -93,13 +93,13 @@
     }
     
     public void recordValidatedMatch(MailProcessingRecord matchedAndMergedRecord) {
-    	if (!m_matchedMailResults.values().contains(matchedAndMergedRecord)) {
-    		log.error("cannot record validation result for (already written?) result having id " 
-    				   + matchedAndMergedRecord.getMailId());
-    		return;
-    	}
-    	
-    	if (matchedAndMergedRecord.isReceivedValid()) m_validMailCounter++;
+        if (!m_matchedMailResults.values().contains(matchedAndMergedRecord)) {
+            log.error("cannot record validation result for (already written?) result having id " 
+                       + matchedAndMergedRecord.getMailId());
+            return;
+        }
+        
+        if (matchedAndMergedRecord.isReceivedValid()) m_validMailCounter++;
     }
 
     public void addJVMResult(JVMResourcesRecord jvmResourcesRecord) {

Modified: james/postage/trunk/src/main/java/org/apache/james/postage/smtpserver/SMTPMailAnalyzeStrategy.java
URL: http://svn.apache.org/viewvc/james/postage/trunk/src/main/java/org/apache/james/postage/smtpserver/SMTPMailAnalyzeStrategy.java?view=diff&rev=450409&r1=450408&r2=450409
==============================================================================
--- james/postage/trunk/src/main/java/org/apache/james/postage/smtpserver/SMTPMailAnalyzeStrategy.java (original)
+++ james/postage/trunk/src/main/java/org/apache/james/postage/smtpserver/SMTPMailAnalyzeStrategy.java Wed Sep 27 04:55:44 2006
@@ -1,39 +1,39 @@
-/****************************************************************
- * 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.postage.smtpserver;
-
-import javax.mail.internet.MimeMessage;
-
-import org.apache.james.postage.mail.MailAnalyzeStrategy;
-import org.apache.james.postage.result.PostageRunnerResult;
-
-public class SMTPMailAnalyzeStrategy extends MailAnalyzeStrategy {
-
-	private MimeMessage message = null;
-	
-	public SMTPMailAnalyzeStrategy(String receivingQueueName, PostageRunnerResult results, MimeMessage message) {
-		super(receivingQueueName, results);
-		this.message = message;
-	}
-	
-    protected MimeMessage loadMessage() throws Exception {
-    	return message;
-    }
-
-}
+/****************************************************************
+ * 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.postage.smtpserver;
+
+import javax.mail.internet.MimeMessage;
+
+import org.apache.james.postage.mail.MailAnalyzeStrategy;
+import org.apache.james.postage.result.PostageRunnerResult;
+
+public class SMTPMailAnalyzeStrategy extends MailAnalyzeStrategy {
+
+    private MimeMessage message = null;
+    
+    public SMTPMailAnalyzeStrategy(String receivingQueueName, PostageRunnerResult results, MimeMessage message) {
+        super(receivingQueueName, results);
+        this.message = message;
+    }
+    
+    protected MimeMessage loadMessage() throws Exception {
+        return message;
+    }
+
+}

Modified: james/postage/trunk/src/main/java/org/apache/james/postage/smtpserver/SimpleMailServer.java
URL: http://svn.apache.org/viewvc/james/postage/trunk/src/main/java/org/apache/james/postage/smtpserver/SimpleMailServer.java?view=diff&rev=450409&r1=450408&r2=450409
==============================================================================
--- james/postage/trunk/src/main/java/org/apache/james/postage/smtpserver/SimpleMailServer.java (original)
+++ james/postage/trunk/src/main/java/org/apache/james/postage/smtpserver/SimpleMailServer.java Wed Sep 27 04:55:44 2006
@@ -55,11 +55,11 @@
     private PostageRunnerResult m_results;
 
     public void sendMail(MailAddress sender, Collection recipients, MimeMessage message) throws MessagingException {
-    	try {
+        try {
             new SMTPMailAnalyzeStrategy("smtpOutbound", m_results, message).handle();
-		} catch (Exception e) {
-			throw new MessagingException("error handling message", e);
-		}
+        } catch (Exception e) {
+            throw new MessagingException("error handling message", e);
+        }
     }
 
     public void sendMail(MailAddress sender, Collection recipients, InputStream msg) throws MessagingException {



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