[vlma-devel] commit: Don't try to send a mail if there is no recipient. (Adrien Grand )

git version control git at videolan.org
Thu May 15 00:56:01 CEST 2008


vlma | branch: master | Adrien Grand <jpountz at videolan.org> | Thu May 15 00:45:57 2008 +0200| [4ece85800bd66ece257e41c57adf4b0e91a95ef3]

Don't try to send a mail if there is no recipient.

> http://git.videolan.org/gitweb.cgi/vlma.git/?a=commit;h=4ece85800bd66ece257e41c57adf4b0e91a95ef3
---

 .../org/videolan/vlma/notifier/MailNotifier.java   |   35 ++++++++++++--------
 1 files changed, 21 insertions(+), 14 deletions(-)

diff --git a/vlma-core/src/main/java/org/videolan/vlma/notifier/MailNotifier.java b/vlma-core/src/main/java/org/videolan/vlma/notifier/MailNotifier.java
index 27ec87f..0ec83ab 100644
--- a/vlma-core/src/main/java/org/videolan/vlma/notifier/MailNotifier.java
+++ b/vlma-core/src/main/java/org/videolan/vlma/notifier/MailNotifier.java
@@ -38,22 +38,29 @@ public class MailNotifier extends Notifier {
         this.mailSender = mailSender;
     }
 
+    private boolean isMailEnabled() {
+        String tmp = VLMa.getInstance().getString("vlma.notification.mail.recipients");
+        return (tmp != null && tmp.length() > 0);
+    }
+
     @Override
     public void sendNotification(String message) {
-        SimpleMailMessage msg = new SimpleMailMessage();
-        String from = VLMa.getInstance().getString("vlma.notification.mail.sender");
-        String[] recipients = VLMa.getInstance().getString("vlma.notification.mail.recipients").split(",");
-        mailSender.setHost(VLMa.getInstance().getString("vlma.notification.mail.host"));
-        msg.setFrom(from);
-        msg.setTo(recipients);
-        msg.setSubject(message);
-        msg.setText(message);
-        try{
-            this.mailSender.send(msg);
-        }
-        catch(MailException e) {
-            // TODO: Do better?
-            logger.error("Mail could not be sent.", e);
+        if (isMailEnabled()) {
+            SimpleMailMessage msg = new SimpleMailMessage();
+            String from = VLMa.getInstance().getString("vlma.notification.mail.sender");
+            String[] recipients = VLMa.getInstance().getString("vlma.notification.mail.recipients").split(",");
+            mailSender.setHost(VLMa.getInstance().getString("vlma.notification.mail.host"));
+            msg.setFrom(from);
+            msg.setTo(recipients);
+            msg.setSubject(message);
+            msg.setText(message);
+            try{
+                this.mailSender.send(msg);
+            }
+            catch(MailException e) {
+                // TODO: Do better?
+                logger.error("Mail could not be sent.", e);
+            }
         }
     }
 



More information about the vlma-devel mailing list