details:   https://code.openbravo.com/erp/devel/pi/rev/2ccef54104f1
changeset: 35654:2ccef54104f1
user:      Javier Armendáriz <javier.armendariz <at> openbravo.com>
date:      Fri Apr 12 14:54:40 2019 +0200
summary:   Fixed issue 40603: NPE if email timeout is not set

Adding another null check to verify not only in the case that the email config
does not exist, but also that the timeout value is empty. In both cases the
default timeout should be used.

diffstat:

 src/org/openbravo/erpCommon/utility/poc/EmailManager.java |  14 +++++++++-----
 1 files changed, 9 insertions(+), 5 deletions(-)

diffs (44 lines):

diff -r f3ff80a1ad20 -r 2ccef54104f1 
src/org/openbravo/erpCommon/utility/poc/EmailManager.java
--- a/src/org/openbravo/erpCommon/utility/poc/EmailManager.java Fri Apr 12 
10:11:29 2019 +0200
+++ b/src/org/openbravo/erpCommon/utility/poc/EmailManager.java Fri Apr 12 
14:54:40 2019 +0200
@@ -9,7 +9,7 @@
  * either express or implied. See the License for the specific language
  * governing rights and limitations under the License. The Original Code is
  * Openbravo ERP. The Initial Developer of the Original Code is Openbravo SLU 
All
- * portions are Copyright (C) 2001-2018 Openbravo SLU All Rights Reserved.
+ * portions are Copyright (C) 2001-2019 Openbravo SLU All Rights Reserved.
  * Contributor(s): ______________________________________.
  * ***********************************************************************
  */
@@ -64,7 +64,7 @@
   public static void sendEmail(EmailServerConfiguration conf, EmailInfo email) 
throws Exception {
 
     String decryptedPassword = 
FormatUtilities.encryptDecrypt(conf.getSmtpServerPassword(), false);
-    Long timeoutMillis = 
TimeUnit.SECONDS.toMillis(conf.getSmtpConnectionTimeout());
+    Long timeoutMillis = getSmtpConnectionTimeout(conf);
 
     sendEmail(conf.getSmtpServer(), conf.isSMTPAuthentification(), 
conf.getSmtpServerAccount(),
         decryptedPassword, conf.getSmtpConnectionSecurity(), 
conf.getSmtpPort().intValue(),
@@ -85,15 +85,19 @@
 
     EmailServerConfiguration configuration = EmailUtils
         
.getEmailConfiguration(OBContext.getOBContext().getCurrentOrganization());
-    Long timeoutMillis = (configuration != null)
-        ? TimeUnit.SECONDS.toMillis(configuration.getSmtpConnectionTimeout())
-        : DEFAULT_SMTP_TIMEOUT;
+    Long timeoutMillis = getSmtpConnectionTimeout(configuration);
 
     sendEmail(host, auth, username, password, connSecurity, port, 
senderAddress, recipientTO,
         recipientCC, recipientBCC, replyTo, subject, content, contentType, 
attachments, sentDate,
         headerExtras, timeoutMillis.intValue());
   }
 
+  private static Long getSmtpConnectionTimeout(EmailServerConfiguration 
configuration) {
+    return (configuration != null && configuration.getSmtpConnectionTimeout() 
!= null)
+        ? TimeUnit.SECONDS.toMillis(configuration.getSmtpConnectionTimeout())
+        : DEFAULT_SMTP_TIMEOUT;
+  }
+
   private static void sendEmail(String host, boolean auth, String username, 
String password,
       String connSecurity, int port, String senderAddress, String recipientTO, 
String recipientCC,
       String recipientBCC, String replyTo, String subject, String content, 
String contentType,


_______________________________________________
Openbravo-commits mailing list
Openbravo-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to