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/13 09:01:37 UTC

svn commit: r442876 - in /james/postage/trunk/src/main/java/org/apache/james/postage: ./ client/ mail/ result/ smtpserver/

Author: berndf
Date: Wed Sep 13 00:01:36 2006
New Revision: 442876

URL: http://svn.apache.org/viewvc?view=rev&rev=442876
Log:
- fixed reading the text parts size
- startup-test mails have no longer postage id == NULL, now postage id is "PROFORMA"
- handle the startup-test mails correctly: ignore them, not try to match them
- unifying the mail reception workflow, handling creation of result record, matching and validation in MailAnalyzeStrategy and its derivations
- integrate validator concept (POSTAGE-5) with current DefaultMailFactory, moving validation code into DefaultMailValidator

Added:
    james/postage/trunk/src/main/java/org/apache/james/postage/client/POP3MailAnalyzeStrategy.java
    james/postage/trunk/src/main/java/org/apache/james/postage/mail/MailAnalyzeStrategy.java
    james/postage/trunk/src/main/java/org/apache/james/postage/smtpserver/SMTPMailAnalyzeStrategy.java
Modified:
    james/postage/trunk/src/main/java/org/apache/james/postage/PostageRunner.java
    james/postage/trunk/src/main/java/org/apache/james/postage/client/POP3Client.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/MailMatchingUtils.java
    james/postage/trunk/src/main/java/org/apache/james/postage/result/PostageRunnerResult.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/SimpleMailServer.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=442876&r1=442875&r2=442876
==============================================================================
--- 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 13 00:01:36 2006
@@ -261,6 +261,7 @@
     private void logElapsedData() {
         log.info("unmatched messages: " + m_results.getUnmatchedMails());
         log.info("matched messages:   " + m_results.getMatchedMails());
+        log.info("valid matches:      " + m_results.getValidMails());
         log.info("recorded errors:    " + m_results.getErrorCount());
     }
 

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=442876&r1=442875&r2=442876
==============================================================================
--- 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 13 00:01:36 2006
@@ -20,29 +20,19 @@
 
 package org.apache.james.postage.client;
 
+import java.io.IOException;
+import java.util.Iterator;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.commons.net.pop3.POP3MessageInfo;
-import org.apache.james.fetchmail.ReaderInputStream;
 import org.apache.james.postage.PostageException;
 import org.apache.james.postage.SamplingException;
 import org.apache.james.postage.StartupException;
 import org.apache.james.postage.execution.Sampler;
-import org.apache.james.postage.mail.MailMatchingUtils;
-import org.apache.james.postage.result.MailProcessingRecord;
 import org.apache.james.postage.result.PostageRunnerResult;
 import org.apache.james.postage.user.UserList;
 
-import javax.mail.BodyPart;
-import javax.mail.MessagingException;
-import javax.mail.internet.MimeMessage;
-import javax.mail.internet.MimeMultipart;
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.Reader;
-import java.util.Iterator;
-
 public class POP3Client implements Sampler {
 
     private static Log log = LogFactory.getLog(POP3Client.class);
@@ -128,121 +118,19 @@
             }
 
             for (int i = 0; entries != null && i < entries.length; i++) {
-// TODO do we need to check the state?                assertEquals(1, pop3Client.getState());
                 POP3MessageInfo entry = entries[i];
-                int size = entry.size;
 
-                MailProcessingRecord mailProcessingRecord = new MailProcessingRecord();
-                mailProcessingRecord.setReceivingQueue("pop3");
-                mailProcessingRecord.setTimeFetchStart(System.currentTimeMillis());
-
-                String mailText;
-                BufferedReader mailReader = null;
-                Reader reader = null;
                 try {
-                    reader = pop3Client.retrieveMessage(entry.number);
-                    mailReader = new BufferedReader(reader);
-
-                    analyzeAndMatch(mailReader, mailProcessingRecord, pop3Client, i);
-                } catch (Exception e) {
-                    log.info("failed to read pop3 mail #" + i + " for " + username);
-                    continue; // mail processing record is discarded
-                } finally {
-                    if (reader != null) {
-                        try {
-                            reader.close();
-                        } catch (IOException e) {
-                            log.warn("error closing mail reader");
-                        }
-                    }
-                }
-
-                continue;
+					new POP3MailAnalyzeStrategy("pop3", m_results, pop3Client, entry.number, i).handle();
+				} catch (Exception exception) {
+					log.warn("error processing pop3 mail", exception);
+				}
             }
 
             closeSession(pop3Client);
         } catch (PostageException e) {
             throw new SamplingException("sample failed", e);
         }
-    }
-
-    private void analyzeAndMatch(Reader mailReader, MailProcessingRecord mailProcessingRecord, org.apache.commons.net.pop3.POP3Client pop3Client, int i) {
-
-        InputStream in = new ReaderInputStream(mailReader);
-        MimeMessage message;
-        try {
-            message = new MimeMessage(null, in);
-            in.close();
-        } catch (IOException e) {
-            log.info("failed to close mail reader.");
-            return;
-        } catch (MessagingException e) {
-            log.info("failed to process mail. remains on server");
-            return;
-        }
-
-
-        if (!MailMatchingUtils.isMatchCandidate(message)) return;
-
-        String id = MailMatchingUtils.getMailIdHeader(message);
-        try {
-            mailProcessingRecord.setByteReceivedTotal(message.getSize());
-
-            mailProcessingRecord.setMailId(id);
-            mailProcessingRecord.setSubject(message.getSubject());
-
-            MimeMultipart mimeMultipart = new MimeMultipart(message.getDataHandler().getDataSource());
-
-            // this assumes, there is zero or one part each, either of type plaintext or binary
-            mailProcessingRecord.setByteReceivedText(getPartSize(mimeMultipart, "text/plain"));
-            mailProcessingRecord.setByteReceivedBinary(getPartSize(mimeMultipart, "application/octet-stream"));
-
-            mailProcessingRecord.setTimeFetchEnd(System.currentTimeMillis());
-
-            try {
-                pop3Client.deleteMessage(i + 1); // don't retrieve again next time
-            } catch (Exception e) {
-                log.info("failed to delete mail.");
-                return;
-            }
-        } catch (MessagingException e) {
-            log.info("failed to process mail. remains on server");
-            return;
-        } finally {
-        	MailProcessingRecord matchedAndMergedRecord = matchMails(mailProcessingRecord);
-            if (matchedAndMergedRecord != null) {
-            	MailMatchingUtils.validateMail(message, matchedAndMergedRecord);
-            }
-        }
-    }
-
-    private MailProcessingRecord matchMails(MailProcessingRecord mailProcessingRecord) {
-        MailProcessingRecord matchedAndMergedRecord = m_results.matchMailRecord(mailProcessingRecord);
-        if (matchedAndMergedRecord == null) {
-        	// (but only do this if sure this is a Postage test mail for this runner)
-            String oldMailId = mailProcessingRecord.getMailId();
-            String newMailId = MailProcessingRecord.getNextId();
-            mailProcessingRecord.setMailId(newMailId);
-            log.info("changed mail id from " + oldMailId + " to " + newMailId);
-            m_results.addNewMailRecord(mailProcessingRecord);
-        }
-        return matchedAndMergedRecord;
-    }
-
-    private int getPartSize(MimeMultipart parts, String mimeType) {
-        if (parts != null) {
-            try {
-                for (int i = 0; i < parts.getCount(); i++) {
-                    BodyPart bodyPart = parts.getBodyPart(i);
-                    if (mimeType.equals(bodyPart.getContentType())) {
-                        return bodyPart.getSize();
-                    }
-                }
-            } catch (MessagingException e) {
-                log.info("failed to process body parts.", e);
-            }
-        }
-        return 0;
     }
 }
 

Added: 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=auto&rev=442876
==============================================================================
--- james/postage/trunk/src/main/java/org/apache/james/postage/client/POP3MailAnalyzeStrategy.java (added)
+++ james/postage/trunk/src/main/java/org/apache/james/postage/client/POP3MailAnalyzeStrategy.java Wed Sep 13 00:01:36 2006
@@ -0,0 +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;
+        }
+    }
+
+
+}

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=442876&r1=442875&r2=442876
==============================================================================
--- 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 13 00:01:36 2006
@@ -82,6 +82,9 @@
                 for (int i = 0; i < mailSize; i++) textBody.append(getRandomChar());
 
                 part.setText(textBody.toString());
+
+//                part.setDataHandler(new DataHandler(textBody.toString(), "text/plain"));
+                
                 multipart.addBodyPart(part);
             }
 

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=442876&r1=442875&r2=442876
==============================================================================
--- 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 13 00:01:36 2006
@@ -19,13 +19,36 @@
 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) {
-		return true;
+
+		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;
 	}
 
 }

Added: 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=auto&rev=442876
==============================================================================
--- james/postage/trunk/src/main/java/org/apache/james/postage/mail/MailAnalyzeStrategy.java (added)
+++ james/postage/trunk/src/main/java/org/apache/james/postage/mail/MailAnalyzeStrategy.java Wed Sep 13 00:01:36 2006
@@ -0,0 +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;
+	}
+}

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=442876&r1=442875&r2=442876
==============================================================================
--- 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 13 00:01:36 2006
@@ -25,12 +25,15 @@
 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 result mails to sent test mails
+ * helps matching, analysing and validating result mails and sent test mails
  */
 public class MailMatchingUtils {
 
@@ -119,5 +122,29 @@
 		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/result/PostageRunnerResult.java
URL: http://svn.apache.org/viewvc/james/postage/trunk/src/main/java/org/apache/james/postage/result/PostageRunnerResult.java?view=diff&rev=442876&r1=442875&r2=442876
==============================================================================
--- james/postage/trunk/src/main/java/org/apache/james/postage/result/PostageRunnerResult.java (original)
+++ james/postage/trunk/src/main/java/org/apache/james/postage/result/PostageRunnerResult.java Wed Sep 13 00:01:36 2006
@@ -26,20 +26,32 @@
 
     void setEnvironmentDescription(Map descriptionItems);
 
+    /**
+     * add a record to be matched later on
+     * @param mailProcessingRecord
+     */
     void addNewMailRecord(MailProcessingRecord mailProcessingRecord);
 
     /**
-     * 
+     * retrieve the matching record, if existing
      * @param mailProcessingRecord record for whom a match is searched
      * @return null, if no match is found or matching and merged record otherwise
      */
     MailProcessingRecord matchMailRecord(MailProcessingRecord mailProcessingRecord);
 
+    /**
+     * count the valid matches
+     * @param mailProcessingRecord
+     */
+    void recordValidatedMatch(MailProcessingRecord matchedAndMergedRecord);    
+    
     void addJVMResult(JVMResourcesRecord jvmResourcesRecord);
 
     long getUnmatchedMails();
 
     long getMatchedMails();
+
+    long getValidMails();
 
     long getTimestampFirstResult();
 

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=442876&r1=442875&r2=442876
==============================================================================
--- 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 13 00:01:36 2006
@@ -53,6 +53,8 @@
 
     private long m_matchedMailCounter = 0;
 
+    private long m_validMailCounter = 0;
+
     private Map  m_environmentInfo = new LinkedHashMap();
 
     public void addNewMailRecord(MailProcessingRecord mailProcessingRecord) {
@@ -89,6 +91,16 @@
 
         return null;
     }
+    
+    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++;
+    }
 
     public void addJVMResult(JVMResourcesRecord jvmResourcesRecord) {
         m_jvmStatistics.add(jvmResourcesRecord);
@@ -104,6 +116,10 @@
 
     public long getMatchedMails() {
         return m_matchedMailCounter;
+    }
+
+    public long getValidMails() {
+        return m_validMailCounter;
     }
 
     public void writeMailResults(OutputStreamWriter outputStreamWriter, boolean flushOnlyMatched) throws IOException {

Added: 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=auto&rev=442876
==============================================================================
--- james/postage/trunk/src/main/java/org/apache/james/postage/smtpserver/SMTPMailAnalyzeStrategy.java (added)
+++ james/postage/trunk/src/main/java/org/apache/james/postage/smtpserver/SMTPMailAnalyzeStrategy.java Wed Sep 13 00:01:36 2006
@@ -0,0 +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;
+    }
+
+}

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=442876&r1=442875&r2=442876
==============================================================================
--- 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 13 00:01:36 2006
@@ -26,6 +26,7 @@
 import org.apache.james.postage.result.PostageRunnerResult;
 import org.apache.james.postage.mail.HeaderConstants;
 import org.apache.james.postage.mail.MailMatchingUtils;
+import org.apache.james.postage.mail.MailAnalyzeStrategy;
 import org.apache.james.services.MailRepository;
 import org.apache.james.services.MailServer;
 import org.apache.mailet.Mail;
@@ -35,6 +36,8 @@
 import javax.mail.MessagingException;
 import javax.mail.internet.InternetAddress;
 import javax.mail.internet.MimeMessage;
+import javax.mail.internet.MimeMultipart;
+
 import java.io.InputStream;
 import java.util.Collection;
 import java.util.HashSet;
@@ -52,40 +55,11 @@
     private PostageRunnerResult m_results;
 
     public void sendMail(MailAddress sender, Collection recipients, MimeMessage message) throws MessagingException {
-        //log.info("start processing incoming mail having id = " + msg.getMessageID());
-        MailProcessingRecord mailProcessingRecord = new MailProcessingRecord();
-        mailProcessingRecord.setReceivingQueue("smtpOutbound");
-        mailProcessingRecord.setTimeFetchStart(System.currentTimeMillis());
-        mailProcessingRecord.setByteReceivedTotal(message.getSize());
-
-        try {
-            if (!MailMatchingUtils.isMatchCandidate(message)) return;
-
-            String id = MailMatchingUtils.getMailIdHeader(message);
-            mailProcessingRecord.setMailId(id);
-
-            String[] subjectHeader = message.getHeader("Subject");
-            if (subjectHeader != null && subjectHeader.length > 0) {
-                mailProcessingRecord.setSubject(subjectHeader[0]);
-            }
-
-            // TODO mailProcessingRecord.setByteReceivedText();
-            // TODO mailProcessingRecord.setByteReceivedBinary();
-
-            mailProcessingRecord.setTimeFetchEnd(System.currentTimeMillis());
-        } catch(MessagingException e) {
-            log.error("error processing incoming mail: " + e.getMessage());
-            throw e; // rethrow after logging
-        } finally{
-        	MailProcessingRecord matchedAndMergedRecord = m_results.matchMailRecord(mailProcessingRecord);
-            if (matchedAndMergedRecord == null) {
-                if (mailProcessingRecord.getMailId() == null) mailProcessingRecord.setMailId(MailProcessingRecord.getNextId());
-                m_results.addNewMailRecord(mailProcessingRecord);
-            }
-            else {
-            	MailMatchingUtils.validateMail(message, matchedAndMergedRecord);
-            }
-        }
+    	try {
+            new SMTPMailAnalyzeStrategy("smtpOutbound", m_results, message).handle();
+		} 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