Scarab commit: svn commit: r10736 - trunk/src/java/org/tigris/scarab/util/Email.java

Hussayn Dabbous <[email protected]>
Newsgroups gmane.comp.java.scarab.cvs
Message-ID <[email protected]>
Author: dabbous
Date: 2009-05-29 16:02:07-0700
New Revision: 10736

Modified:
   trunk/src/java/org/tigris/scarab/util/Email.java

Log:
SCB2873: truncate the EMAIL_REFERENCES string when the message length exceed the allowed 2000 characters

Modified: trunk/src/java/org/tigris/scarab/util/Email.java
Url: http://scarab.tigris.org/source/browse/scarab/trunk/src/java/org/tigris/scarab/util/Email.java?view=diff&pathrev=10736&r1=10735&r2=10736
==============================================================================
--- trunk/src/java/org/tigris/scarab/util/Email.java	(original)
+++ trunk/src/java/org/tigris/scarab/util/Email.java	2009-05-29 16:02:07-0700
@@ -267,25 +267,12 @@
             }
         }
 
+        String newEmailReference = null;
         try
         {
             log.debug("Sending email ...");
-            final String newEmailReference = te.send();
+            newEmailReference = te.send();
             log.debug("... sent " + newEmailReference);
-
-            if(null!=emailReferences)
-            {
-                // we record, within the varchar(2000) limit,
-                //  the MessageID of every mail sent if it's related to an issue change 
-                if(emailReferences.length() + newEmailReference.length() > 2000)
-                {
-                    // truncate emailReferences so it (& newEmailReferences) will fit
-                    emailReferences = emailReferences.substring(
-                            emailReferences.indexOf('<', newEmailReference.length()));
-                }
-                issue.setEmailReferences(emailReferences + ' ' + newEmailReference);
-                issue.save();
-            }
         }
         catch(EmailException me)
         {
@@ -297,6 +284,36 @@
             Throwable t = me.getCause();
             throw new ScarabException(L10NKeySet.ExceptionEmailFailure,t);
         }
+
+        if(null!=emailReferences && null!=newEmailReference)
+        {
+            // we record, within the varchar(2000) limit,
+            // the MessageID of every mail sent if it's related to an issue change 
+            // There must be an error in the length calculation, which sometimes causes
+            // the issue.save() to throw an illegalLength exception. I tried to take care
+            // of this here. [HD]
+
+            if(emailReferences.length()>0) emailReferences += ' ';
+            emailReferences += newEmailReference; 
+
+            if(emailReferences.length() > 2000)
+            {
+                emailReferences = emailReferences.substring(
+                        emailReferences.indexOf('<', emailReferences.length() - 2000));
+            }
+            try
+            {
+                issue.setEmailReferences(emailReferences);
+                issue.save();
+            }
+            catch(Exception e)
+            {
+                log.warn("Failed to store EMAIL_REFERENCES for issue ["+issue.getIdCount()+"]");
+                log.warn("EMAIL_REFERENCES.length was " + emailReferences.length());
+                log.warn("Detailed error message was: " + e.getMessage());
+                //Not throwing an exception here, because the email itself could be successfully transmitted
+            }
+        }
     }
     
     /**

------------------------------------------------------
http://scarab.tigris.org/ds/viewMessage.do?dsForumId=3577&dsMessageId=2357018
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.