org.mailster.server
Class MailsterSMTPServer

java.lang.Object
  extended by org.mailster.smtp.api.listener.MessageListenerAdapter
      extended by org.mailster.server.MailsterSMTPServer
All Implemented Interfaces:
org.mailster.smtp.api.listener.MessageListener

public class MailsterSMTPServer
extends org.mailster.smtp.api.listener.MessageListenerAdapter

---
Mailster (C) 2007-2009 De Oliveira Edouard

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

See  Mailster Web Site
---

MailsterSMTPServer.java - The smtp server.

Version:
$Revision: 1.3 $, $Date: 2009/02/07 19:42:12 $
Author:
Edouard De Oliveira

Nested Class Summary
(package private)  class MailsterSMTPServer.EmailReceivedTask
          Task event dispatched when an email has been received.
(package private)  class MailsterSMTPServer.ServerStateUpdatedTask
          Task event dispatched when server state has been updated.
 
Field Summary
private  int connectionTimeout
          The timeout before closing connection.
private  boolean debug
          Output client/server commands for debugging.
static java.lang.String DEFAULT_SMTP_HOST
          Defaut SMTP host is null to listen on all subnets.
static int DEFAULT_SMTP_PORT
          Default SMTP port is 25.
static int DEFAULT_TIMEOUT
          The default timeout.
private  MailsterSMTPServer.EmailReceivedTask emailTask
          The email received event task.
private  java.util.concurrent.Executor eventDispatcher
          The event dispatcher executor.
private  java.util.Collection<SMTPServerListener> externalListeners
          The list of smtp server events listeners.
private  java.lang.String hostName
          Hostname the server listens on.
private  int port
          Port the server listens on - set to the default SMTP port initially.
private  org.mailster.smtp.SMTPServer server
          The SubethaSmtp server.
private  MailsterSMTPServer.ServerStateUpdatedTask serverStateTask
          The server state updated event task.
 
Constructor Summary
MailsterSMTPServer()
          Creates an instance of SimpleSmtpServer.
MailsterSMTPServer(boolean debug)
          Creates an instance of SimpleSmtpServer.
MailsterSMTPServer(int port)
          Creates an instance of SimpleSmtpServer.
MailsterSMTPServer(int port, boolean debug)
          Creates an instance of SimpleSmtpServer.
MailsterSMTPServer(java.lang.String hostname, int port, boolean debug)
          Creates an instance of SimpleSmtpServer.
 
Method Summary
 void addSMTPServerListener(SMTPServerListener listener)
           
private  java.util.ArrayList<SMTPServerListener> copyListeners()
           
 void deliver(java.lang.String from, java.util.List<java.lang.String> recipients, java.io.InputStream data)
           
private  void fireMessageReceived(SmtpMessage msg)
           
private  void fireServerStateUpdated()
           
 int getConnectionTimeout()
           
 int getPort()
           
 boolean isDebug()
           
 boolean isStopped()
          Check if the server has been placed in a stopped state.
 void removeSMTPServerListener(SMTPServerListener listener)
           
 void setConnectionTimeout(int connectionTimeout)
           
 void setDebug(boolean debug)
           
 void setHostName(java.lang.String hostName)
           
 void setPort(int port)
           
static void setupSSLParameters(X509SecureSocketFactory.SSLProtocol protocol, boolean clientAuthNeeded)
           
 void start()
          Starts an instance of SimpleSmtpServer.
 void stop()
          Stops the server.
 
Methods inherited from class org.mailster.smtp.api.listener.MessageListenerAdapter
accept, deliver
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_TIMEOUT

public static final int DEFAULT_TIMEOUT
The default timeout.

See Also:
Constant Field Values

DEFAULT_SMTP_HOST

public static final java.lang.String DEFAULT_SMTP_HOST
Defaut SMTP host is null to listen on all subnets. If a hostname is specified, then server socket will ONLY listen on this particular ip address this is not the preferred default behaviour.

See Also:
InetSocketAddress

DEFAULT_SMTP_PORT

public static final int DEFAULT_SMTP_PORT
Default SMTP port is 25.

See Also:
Constant Field Values

connectionTimeout

private int connectionTimeout
The timeout before closing connection. Set to 5 minutes.


debug

private boolean debug
Output client/server commands for debugging. Off by default.


port

private int port
Port the server listens on - set to the default SMTP port initially.


hostName

private java.lang.String hostName
Hostname the server listens on.


server

private org.mailster.smtp.SMTPServer server
The SubethaSmtp server.


externalListeners

private java.util.Collection<SMTPServerListener> externalListeners
The list of smtp server events listeners.


eventDispatcher

private java.util.concurrent.Executor eventDispatcher
The event dispatcher executor.


emailTask

private MailsterSMTPServer.EmailReceivedTask emailTask
The email received event task.


serverStateTask

private MailsterSMTPServer.ServerStateUpdatedTask serverStateTask
The server state updated event task.

Constructor Detail

MailsterSMTPServer

public MailsterSMTPServer()
Creates an instance of SimpleSmtpServer. Server will listen on the default host:port. Debug mode is off by default.


MailsterSMTPServer

public MailsterSMTPServer(boolean debug)
Creates an instance of SimpleSmtpServer. Server will listen on the default host:port.

Parameters:
debug - if true debug mode is enabled

MailsterSMTPServer

public MailsterSMTPServer(int port)
Creates an instance of SimpleSmtpServer. Server will listen on the default host. Debug mode is off by default.

Parameters:
port - port number the server should listen to

MailsterSMTPServer

public MailsterSMTPServer(int port,
                          boolean debug)
Creates an instance of SimpleSmtpServer. Server will listen on the default host.

Parameters:
port - port number the server should listen to
debug - if true debug mode is enabled

MailsterSMTPServer

public MailsterSMTPServer(java.lang.String hostname,
                          int port,
                          boolean debug)
Creates an instance of SimpleSmtpServer.

Parameters:
hostname - hostname the server should listen on
port - port number the server should listen to
debug - if true debug mode is enabled
Method Detail

setupSSLParameters

public static void setupSSLParameters(X509SecureSocketFactory.SSLProtocol protocol,
                                      boolean clientAuthNeeded)

start

public void start()
Starts an instance of SimpleSmtpServer.


stop

public void stop()
Stops the server. Server is shut down after processing of the current request is complete.


addSMTPServerListener

public void addSMTPServerListener(SMTPServerListener listener)

removeSMTPServerListener

public void removeSMTPServerListener(SMTPServerListener listener)

isStopped

public boolean isStopped()
Check if the server has been placed in a stopped state.

Returns:
true if the server is stopped, false otherwise

deliver

public void deliver(java.lang.String from,
                    java.util.List<java.lang.String> recipients,
                    java.io.InputStream data)
             throws org.mailster.smtp.api.TooMuchDataException,
                    java.io.IOException
Throws:
org.mailster.smtp.api.TooMuchDataException
java.io.IOException

copyListeners

private java.util.ArrayList<SMTPServerListener> copyListeners()

fireMessageReceived

private void fireMessageReceived(SmtpMessage msg)

fireServerStateUpdated

private void fireServerStateUpdated()

isDebug

public boolean isDebug()

setDebug

public void setDebug(boolean debug)

setHostName

public void setHostName(java.lang.String hostName)

getPort

public int getPort()

setPort

public void setPort(int port)

getConnectionTimeout

public int getConnectionTimeout()

setConnectionTimeout

public void setConnectionTimeout(int connectionTimeout)