From aac5e7c070a6b16143e7a184f82e82a81973389e Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Fri, 21 Feb 2014 10:10:41 -0500
Subject: [PATCH] Add timestamp to the default log4j configuration

---
 src/main/java/com/gitblit/manager/NotificationManager.java |   49 ++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 38 insertions(+), 11 deletions(-)

diff --git a/src/main/java/com/gitblit/manager/NotificationManager.java b/src/main/java/com/gitblit/manager/NotificationManager.java
index eae563f..22ae551 100644
--- a/src/main/java/com/gitblit/manager/NotificationManager.java
+++ b/src/main/java/com/gitblit/manager/NotificationManager.java
@@ -32,7 +32,7 @@
 
 import com.gitblit.IStoredSettings;
 import com.gitblit.Keys;
-import com.gitblit.MailExecutor;
+import com.gitblit.service.MailService;
 
 /**
  * The notification manager dispatches notifications.  Currently, email is the
@@ -50,26 +50,27 @@
 
 	private final IStoredSettings settings;
 
-	private final MailExecutor mailExecutor;
+	private final MailService mailExecutor;
 
 	public NotificationManager(IStoredSettings settings) {
 		this.settings = settings;
-		this.mailExecutor = new MailExecutor(settings);
+		this.mailExecutor = new MailService(settings);
 	}
 
 	@Override
-	public IManager setup() {
+	public NotificationManager start() {
 		if (mailExecutor.isReady()) {
-			logger.info("Mail executor is scheduled to process the message queue every 2 minutes.");
-			scheduledExecutor.scheduleAtFixedRate(mailExecutor, 1, 2, TimeUnit.MINUTES);
+			int period = 2;
+			logger.info("Mail service will process the queue every {} minutes.", period);
+			scheduledExecutor.scheduleAtFixedRate(mailExecutor, 1, period, TimeUnit.MINUTES);
 		} else {
-			logger.warn("Mail server is not properly configured.  Mail services disabled.");
+			logger.warn("Mail service disabled.");
 		}
 		return this;
 	}
 
 	@Override
-	public IManager stop() {
+	public NotificationManager stop() {
 		scheduledExecutor.shutdownNow();
 		return this;
 	}
@@ -141,7 +142,20 @@
 	 */
 	@Override
 	public void sendHtmlMail(String subject, String message, Collection<String> toAddresses) {
-		this.sendHtmlMail(subject, message, toAddresses.toArray(new String[0]));
+		this.sendHtmlMail(null, subject, message, toAddresses.toArray(new String[0]));
+	}
+
+	/**
+	 * Notify users by email of something.
+	 *
+	 * @param from
+	 * @param subject
+	 * @param message
+	 * @param toAddresses
+	 */
+	@Override
+	public void sendHtmlMail(String from, String subject, String message, Collection<String> toAddresses) {
+		this.sendHtmlMail(from, subject, message, toAddresses.toArray(new String[0]));
 	}
 
 	/**
@@ -153,12 +167,25 @@
 	 */
 	@Override
 	public void sendHtmlMail(String subject, String message, String... toAddresses) {
+		this.sendHtmlMail(null, message, toAddresses);
+	}
+
+	/**
+	 * Notify users by email of something.
+	 *
+	 * @param from
+	 * @param subject
+	 * @param message
+	 * @param toAddresses
+	 */
+	@Override
+	public void sendHtmlMail(String from, String subject, String message, String... toAddresses) {
 		if (toAddresses == null || toAddresses.length == 0) {
-			logger.debug(MessageFormat.format("Dropping message {0} because there are no recipients", subject));
+			logger.debug("Dropping message {} because there are no recipients", subject);
 			return;
 		}
 		try {
-			Message mail = mailExecutor.createMessage(toAddresses);
+			Message mail = mailExecutor.createMessage(from, toAddresses);
 			if (mail != null) {
 				mail.setSubject(subject);
 

--
Gitblit v1.9.1