From 5debe74dd68df32e86478a2e54e6f5efdddbf236 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Fri, 15 Dec 2017 12:28:29 +0500 Subject: Handle boolean parameters in mail related attributes --- src/org/traccar/notification/NotificationMail.java | 12 ++++++------ src/org/traccar/notification/PropertiesProvider.java | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 6 deletions(-) (limited to 'src/org') diff --git a/src/org/traccar/notification/NotificationMail.java b/src/org/traccar/notification/NotificationMail.java index 8707b10da..1631a4c3a 100644 --- a/src/org/traccar/notification/NotificationMail.java +++ b/src/org/traccar/notification/NotificationMail.java @@ -45,18 +45,18 @@ public final class NotificationMail { properties.put("mail.smtp.host", host); properties.put("mail.smtp.port", String.valueOf(provider.getInteger("mail.smtp.port", 25))); - String starttlsEnable = provider.getString("mail.smtp.starttls.enable"); + Boolean starttlsEnable = provider.getBoolean("mail.smtp.starttls.enable"); if (starttlsEnable != null) { - properties.put("mail.smtp.starttls.enable", Boolean.parseBoolean(starttlsEnable)); + properties.put("mail.smtp.starttls.enable", starttlsEnable); } - String starttlsRequired = provider.getString("mail.smtp.starttls.required"); + Boolean starttlsRequired = provider.getBoolean("mail.smtp.starttls.required"); if (starttlsRequired != null) { - properties.put("mail.smtp.starttls.required", Boolean.parseBoolean(starttlsRequired)); + properties.put("mail.smtp.starttls.required", starttlsRequired); } - String sslEnable = provider.getString("mail.smtp.ssl.enable"); + Boolean sslEnable = provider.getBoolean("mail.smtp.ssl.enable"); if (sslEnable != null) { - properties.put("mail.smtp.ssl.enable", Boolean.parseBoolean(sslEnable)); + properties.put("mail.smtp.ssl.enable", sslEnable); } String sslTrust = provider.getString("mail.smtp.ssl.trust"); if (sslTrust != null) { diff --git a/src/org/traccar/notification/PropertiesProvider.java b/src/org/traccar/notification/PropertiesProvider.java index c5ba688e8..8f5965a82 100644 --- a/src/org/traccar/notification/PropertiesProvider.java +++ b/src/org/traccar/notification/PropertiesProvider.java @@ -61,4 +61,21 @@ public class PropertiesProvider { } } + public Boolean getBoolean(String key) { + if (config != null) { + if (config.hasKey(key)) { + return config.getBoolean(key); + } else { + return null; + } + } else { + Object result = extendedModel.getAttributes().get(key); + if (result != null) { + return result instanceof String ? Boolean.valueOf((String) result) : (Boolean) result; + } else { + return null; + } + } + } + } -- cgit v1.2.3 From f8a481a3a4da75139a9b68beef83c3f0528b4572 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Fri, 15 Dec 2017 15:01:03 +0500 Subject: Put mail properties as string --- src/org/traccar/notification/NotificationMail.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/org') diff --git a/src/org/traccar/notification/NotificationMail.java b/src/org/traccar/notification/NotificationMail.java index 1631a4c3a..6c81ecc79 100644 --- a/src/org/traccar/notification/NotificationMail.java +++ b/src/org/traccar/notification/NotificationMail.java @@ -47,16 +47,16 @@ public final class NotificationMail { Boolean starttlsEnable = provider.getBoolean("mail.smtp.starttls.enable"); if (starttlsEnable != null) { - properties.put("mail.smtp.starttls.enable", starttlsEnable); + properties.put("mail.smtp.starttls.enable", String.valueOf(starttlsEnable)); } Boolean starttlsRequired = provider.getBoolean("mail.smtp.starttls.required"); if (starttlsRequired != null) { - properties.put("mail.smtp.starttls.required", starttlsRequired); + properties.put("mail.smtp.starttls.required", String.valueOf(starttlsRequired)); } Boolean sslEnable = provider.getBoolean("mail.smtp.ssl.enable"); if (sslEnable != null) { - properties.put("mail.smtp.ssl.enable", sslEnable); + properties.put("mail.smtp.ssl.enable", String.valueOf(sslEnable)); } String sslTrust = provider.getString("mail.smtp.ssl.trust"); if (sslTrust != null) { -- cgit v1.2.3