org.subethamail.smtp.server
Class SMTPServer

java.lang.Object
  extended by org.subethamail.smtp.server.SMTPServer

public class SMTPServer
extends java.lang.Object

Main SMTPServer class. Construct this object, set the hostName, port, and bind address if you wish to override the defaults, and call start(). This class starts opens a Mina based listener and creates a new instance of the ConnectionHandler class when a new connection comes in. The ConnectionHandler then parses the incoming SMTP stream and hands off the processing to the CommandHandler which will execute the appropriate SMTP command class. There are two ways of using this server. The first is to construct with a MessageHandlerFactory. This provides the lowest-level and most flexible access. The second way is to construct with a collection of MessageListeners. This is a higher, and sometimes more convenient level of abstraction. In neither case is the SMTP server (this library) responsible for deciding what recipients to accept or what to do with the incoming data. That is left to you.

Author:
Jon Stevens, Ian McFarland <ian@neo.com>, Jeff Schnitzer This file has been used and differs from the original by the use of MINA NIO framework., De Oliveira Edouard <doe_wanted@yahoo.fr>

Field Summary
static java.nio.charset.Charset DEFAULT_CHARSET
           
protected static int DEFAULT_DATA_DEFERRED_SIZE
          4 megs by default.
 
Constructor Summary
SMTPServer(java.util.Collection<MessageListener> listeners)
          A convenience constructor that splits the smtp data among multiple listeners (and multiple recipients).
SMTPServer(MessageHandlerFactory handlerFactory)
          The primary constructor.
 
Method Summary
 boolean announceTLS()
           
 int getBacklog()
          The backlog is the Socket backlog.
 java.net.InetAddress getBindAddress()
          null means all interfaces
 CommandHandler getCommandHandler()
          The CommandHandler manages handling the SMTP commands such as QUIT, MAIL, RCPT, DATA, etc.
 int getConnectionTimeout()
          What is the connection timeout?
 int getDataDeferredSize()
          Get the maximum size in bytes of a single message before it is dumped to a temporary file.
 java.lang.String getHostName()
           
 int getMaxConnections()
          What is the maximum amount of connections?
 int getMaxRecipients()
          What is the maximum number of recipients for a single message ?
 MessageHandlerFactory getMessageHandlerFactory()
          All smtp data is eventually routed through the handlers.
 java.lang.String getName()
          The name of the server software.
 java.lang.String getNameVersion()
          The name + version of the server software.
 int getNumberOfConnections()
          Number of connections in the handler.
 int getPort()
          get the port the server is running on.
 boolean hasTooManyConnections()
          Are we over the maximum amount of connections ?
protected  boolean isPowerOfTwo(int x)
          Demonstration : if x is a power of 2, it can't share any bit with x-1.
 boolean isRunning()
          Is the server running after start() has been called?
 void setAnnounceTLS(boolean announceTls)
          Tells the server to announce the TLS support.
 void setBacklog(int backlog)
          The backlog is the Socket backlog.
 void setBindAddress(java.net.InetAddress bindAddress)
          null means all interfaces
 void setConnectionTimeout(int connectionTimeout)
          Set the connection timeout.
 void setDataDeferredSize(int dataDeferredSize)
          Set the maximum size in bytes of a single message before it is dumped to a temporary file.
 void setHostName(java.lang.String hostName)
          The host name that will be reported to SMTP clients
 void setMaxConnections(int maxConnections)
          Set's the maximum number of connections this server instance will accept.
 void setMaxRecipients(int maxRecipients)
          Set the maximum number of recipients for a single message.
 void setPort(int port)
          set the port the server is running on.
 void setReceiveBufferSize(int receiveBufferSize)
          Sets the receive buffer size.
 void start()
          Call this method to get things rolling after instantiating the SMTPServer.
 void startJMXService()
          Starts the JMX service with a polling interval default of 1000ms.
 void startJMXService(int pollingInterval)
          Start the JMX service.
 void stop()
          Shut things down gracefully.
 void stopJMXService()
          Stop the JMX service.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_CHARSET

public static final java.nio.charset.Charset DEFAULT_CHARSET

DEFAULT_DATA_DEFERRED_SIZE

protected static final int DEFAULT_DATA_DEFERRED_SIZE
4 megs by default. The server will buffer incoming messages to disk when they hit this limit in the DATA received.

See Also:
Constant Field Values
Constructor Detail

SMTPServer

public SMTPServer(MessageHandlerFactory handlerFactory)
The primary constructor.


SMTPServer

public SMTPServer(java.util.Collection<MessageListener> listeners)
A convenience constructor that splits the smtp data among multiple listeners (and multiple recipients).

Method Detail

startJMXService

public void startJMXService()
                     throws javax.management.InstanceAlreadyExistsException,
                            javax.management.MBeanRegistrationException,
                            javax.management.NotCompliantMBeanException
Starts the JMX service with a polling interval default of 1000ms.

Throws:
javax.management.InstanceAlreadyExistsException
javax.management.MBeanRegistrationException
javax.management.NotCompliantMBeanException

startJMXService

public void startJMXService(int pollingInterval)
                     throws javax.management.InstanceAlreadyExistsException,
                            javax.management.MBeanRegistrationException,
                            javax.management.NotCompliantMBeanException
Start the JMX service.

Parameters:
pollingInterval -
Throws:
javax.management.InstanceAlreadyExistsException
javax.management.MBeanRegistrationException
javax.management.NotCompliantMBeanException

stopJMXService

public void stopJMXService()
                    throws javax.management.InstanceNotFoundException,
                           javax.management.MBeanRegistrationException
Stop the JMX service.

Throws:
javax.management.InstanceNotFoundException
javax.management.MBeanRegistrationException

start

public void start()
Call this method to get things rolling after instantiating the SMTPServer.


stop

public void stop()
Shut things down gracefully.


setAnnounceTLS

public void setAnnounceTLS(boolean announceTls)
Tells the server to announce the TLS support. Defaults to true.


announceTLS

public boolean announceTLS()
Returns:
true if server is allowed to announce TLS support.

getHostName

public java.lang.String getHostName()
Returns:
the host name that will be reported to SMTP clients

setHostName

public void setHostName(java.lang.String hostName)
The host name that will be reported to SMTP clients


getBindAddress

public java.net.InetAddress getBindAddress()
null means all interfaces


setBindAddress

public void setBindAddress(java.net.InetAddress bindAddress)
null means all interfaces


getPort

public int getPort()
get the port the server is running on.


setPort

public void setPort(int port)
set the port the server is running on.

Parameters:
port -

isRunning

public boolean isRunning()
Is the server running after start() has been called?


getBacklog

public int getBacklog()
The backlog is the Socket backlog. The backlog argument must be a positive value greater than 0. If the value passed if equal or less than 0, then the default value will be assumed.

Returns:
the backlog

setBacklog

public void setBacklog(int backlog)
The backlog is the Socket backlog. The backlog argument must be a positive value greater than 0. If the value passed if equal or less than 0, then the default value will be assumed.


getName

public java.lang.String getName()
The name of the server software.


getNameVersion

public java.lang.String getNameVersion()
The name + version of the server software.


getMessageHandlerFactory

public MessageHandlerFactory getMessageHandlerFactory()
All smtp data is eventually routed through the handlers.


getCommandHandler

public CommandHandler getCommandHandler()
The CommandHandler manages handling the SMTP commands such as QUIT, MAIL, RCPT, DATA, etc.

Returns:
An instance of CommandHandler

getNumberOfConnections

public int getNumberOfConnections()
Number of connections in the handler.


hasTooManyConnections

public boolean hasTooManyConnections()
Are we over the maximum amount of connections ?


getMaxConnections

public int getMaxConnections()
What is the maximum amount of connections?


setMaxConnections

public void setMaxConnections(int maxConnections)
Set's the maximum number of connections this server instance will accept. If set to -1 then limit is ignored.

Parameters:
maxConnections -

getConnectionTimeout

public int getConnectionTimeout()
What is the connection timeout?


setConnectionTimeout

public void setConnectionTimeout(int connectionTimeout)
Set the connection timeout.


getMaxRecipients

public int getMaxRecipients()
What is the maximum number of recipients for a single message ?


setMaxRecipients

public void setMaxRecipients(int maxRecipients)
Set the maximum number of recipients for a single message. If set to -1 then limit is ignored.


getDataDeferredSize

public int getDataDeferredSize()
Get the maximum size in bytes of a single message before it is dumped to a temporary file.


setDataDeferredSize

public void setDataDeferredSize(int dataDeferredSize)
Set the maximum size in bytes of a single message before it is dumped to a temporary file. Argument must be a positive power of two in order to follow the expanding algorithm of ByteBuffer to prevent unnecessary memory consumption.


setReceiveBufferSize

public void setReceiveBufferSize(int receiveBufferSize)
Sets the receive buffer size.


isPowerOfTwo

protected boolean isPowerOfTwo(int x)
Demonstration : if x is a power of 2, it can't share any bit with x-1. So x & (x-1) should be equal to 0. To get rid of negative values, we check that x is higher than 1 (0 and 1 being of course unacceptable values for a buffer length).

Parameters:
x - the number to test
Returns:
true if x is a power of two


Copyright © 2011 SubEthaSMTP. All Rights Reserved. Build version: UNVERSIONED