Author: norman
Date: Tue Nov 28 03:21:34 2006
New Revision: 479994

URL: http://svn.apache.org/viewvc?view=rev&rev=479994
Log:
Add better logging for permanent and temporary errors on remote delivery. See 
JAMES-712

Modified:
    
james/server/trunk/src/java/org/apache/james/transport/mailets/RemoteDelivery.java

Modified: 
james/server/trunk/src/java/org/apache/james/transport/mailets/RemoteDelivery.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/transport/mailets/RemoteDelivery.java?view=diff&rev=479994&r1=479993&r2=479994
==============================================================================
--- 
james/server/trunk/src/java/org/apache/james/transport/mailets/RemoteDelivery.java
 (original)
+++ 
james/server/trunk/src/java/org/apache/james/transport/mailets/RemoteDelivery.java
 Tue Nov 28 03:21:34 2006
@@ -386,6 +386,57 @@
             dnsProblemRetry = Integer.parseInt(dnsRetry); 
         }
     }
+    
+    /**
+     * Try to return a usefull logString created of the Exception which was 
given.
+     * Return null if nothing usefull could be done
+     * 
+     * @param e The MessagingException to use
+     * @return logString
+     */
+    private String exceptionToLogString(MessagingException e) {
+        if (e instanceof SMTPSendFailedException) {
+              return "RemoteHost said: " + e.getMessage();
+        } else if (e instanceof SendFailedException) {
+            SendFailedException exception  = (SendFailedException) e;
+            
+            // No error
+            if ( exception.getInvalidAddresses().length == 0 && 
+                exception.getValidUnsentAddresses().length == 0) return null;
+            
+             Exception ex;
+             StringBuffer sb = new StringBuffer();
+             boolean smtpExFound = false;
+             sb.append("RemoteHost said:");
+
+             while((ex = e.getNextException()) != null & ex instanceof 
MessagingException) {
+                 e = (MessagingException)ex;
+                 if (ex instanceof SMTPAddressFailedException) {
+                     SMTPAddressFailedException exc = 
(SMTPAddressFailedException) ex;
+                     sb.append(" ( " + exc.getAddress() + " - [" + 
exc.getMessage().replace("\n", "") + "] )");
+                     smtpExFound = true;
+                 } 
+             }
+             if (!smtpExFound) {
+                boolean invalidAddr = false;
+                sb.append(" ( ");
+            
+                if (exception.getInvalidAddresses().length > 0) {
+                    sb.append(exception.getInvalidAddresses());
+                    invalidAddr = true;
+                }
+                if (exception.getValidUnsentAddresses().length > 0) {
+                    if (invalidAddr == true) sb.append(" " );
+                    sb.append(exception.getValidUnsentAddresses());
+                }
+                sb.append(" - [");
+                sb.append(exception.getMessage().replace("\n", ""));
+                sb.append("] )");
+             }
+             return sb.toString();
+        }
+        return null;
+    }
 
     /*
      * private method to log the extended SendFailedException introduced in 
JavaMail 1.3.2.
@@ -830,11 +881,20 @@
         } else {
             out.print("Temporary");
         }
+        
+        String exceptionLog = exceptionToLogString(ex);
+        
         StringBuffer logBuffer =
             new StringBuffer(64)
                 .append(" exception delivering mail (")
-                .append(mail.getName())
-                .append(": ");
+                .append(mail.getName());
+        
+        if (exceptionLog != null) { 
+            logBuffer.append(". ");
+            logBuffer.append(exceptionLog);
+        }
+        
+        logBuffer.append(": ");
         out.print(logBuffer.toString());
         if (isDebug) ex.printStackTrace(out);
         log(sout.toString());



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to