/*
 * $Id: PlumberBean.java 988 2008-12-30 08:51:13Z lhoriman $
 * $URL: http://subetha.tigris.org/svn/subetha/branches/resin/core/src/org/subethamail/core/admin/PlumberBean.java $
 */

package org.subethamail.core.admin;

import javax.annotation.security.RolesAllowed;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import javax.mail.Session;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.subethamail.core.admin.i.Eegor;
import org.subethamail.core.post.OutboundMTA;
import org.subethamail.core.smtp.SMTPService;

import com.caucho.remote.HessianService;

/**
 * Implements some basic plumbing methods for testing.
 * 
 * @author Jeff Schnitzer
 * @author Scott Hernandez
 */
@Singleton
@Named("eegor")
@HessianService(urlPattern="/api/Eegor")
public class EegorBean implements Eegor
{
	/** */
	private final static Logger log = LoggerFactory.getLogger(EegorBean.class);

	/** */
	@Inject @OutboundMTA Session mailSession;
	
	String mailSmtpHost;
	String mailSmtpPort;
	
	/** Needed to get/set the fallback host */
	@Inject SMTPService smtpService;

	/* (non-Javadoc)
	 * @see org.subethamail.core.admin.i.EegorBringMeAnotherBrain#log(java.lang.String)
	 */
	public void log(String msg)
	{
		log.info(msg);
	}
	
	/*
	 * (non-Javadoc)
	 */
	@RolesAllowed("siteAdmin")
	public void enableTestMode(String mtaHost)
	{
		log.debug("#### Enabling test mode to " + mtaHost);
		
		if (!this.isTestModeEnabled())
		{
			this.mailSmtpHost = this.mailSession.getProperties().getProperty("mail.smtp.host");
			this.mailSmtpPort = this.mailSession.getProperties().getProperty("mail.smtp.port");
		}
		
		// If there was a port, separate the two
		String[] parts = mtaHost.split(":");
		String newHost = parts[0];
		String newPort = (parts.length > 1) ? parts[1] : "25";

		//store old value, and update the overrides
		this.mailSession.getProperties().setProperty("mail.smtp.host", newHost);
		this.mailSession.getProperties().setProperty("mail.smtp.port", newPort);
	}

	/*
	 * (non-Javadoc)
	 */
	@RolesAllowed("siteAdmin")
	public void disableTestMode()
	{
		//if (!this.isTestModeEnabled())
		if (this.mailSmtpHost == null)
		{
			log.warn("Test mode already disabled");
		}
		else
		{
			log.info("Restoring base mail configuration");

			this.mailSession.getProperties().setProperty("mail.smtp.host", this.mailSmtpHost);
			this.mailSession.getProperties().setProperty("mail.smtp.port", this.mailSmtpPort);

			this.mailSmtpHost = null;
			this.mailSmtpPort = null;
		}
	}

	/** */
	public boolean isTestModeEnabled()
	{
		return this.mailSmtpHost != null;
		//return true;
	}

	/* (non-Javadoc)
	 * @see org.subethamail.core.admin.i.Eegor#setFallbackHost(java.lang.String)
	 */
	@Override
	public void setFallbackHost(String host)
	{
		this.smtpService.setFallbackHost(host);
	}
}

@@ -219,24 +219,59 @@
 e.admin;%0D%0A%0D%0A
+import java.util.logging.Level;%0D%0A%0D%0A
 import javax
@@ -302,24 +302,24 @@
 esAllowed;%0D%0A
-
 import javax
@@ -436,60 +436,35 @@
 ort 
-org.slf4j.Logger;%0D%0Aimport org.slf4j.LoggerFactory
+lombok.extern.java.Log
 ;%0D%0A
+%0D%0A
 impo
@@ -840,16 +840,22 @@
 egor%22)%0D%0A
+@Log%0D%0A
 public c
@@ -894,97 +894,8 @@
 %0A%7B%0D%0A
-%09/** */%0D%0A%09private final static Logger log = LoggerFactory.getLogger(EegorBean.class);%0D%0A%0D%0A
 %09/**
@@ -1360,19 +1360,31 @@
 %7B%0D%0A%09
-%09log.debug(
+    log.log(Level.FINE,
 %22###
@@ -1411,11 +1411,13 @@
  to 
-%22 +
+%7B0%7D%22,
  mta
@@ -2197,24 +2197,24 @@
 null)%0D%0A%09%09%7B%0D%0A
-
 %09%09%09log.warn(
@@ -2212,16 +2212,19 @@
 log.warn
+ing
 (%22Test m

switch logging framework