Package org.subethamail.smtp.server
Class Session
java.lang.Object
org.subethamail.smtp.server.Session
- All Implemented Interfaces:
Runnable,MessageContext
The thread that handles a connection. This class
passes most of it's responsibilities off to the
CommandHandler.
- Author:
- Jon Stevens, Jeff Schnitzer
-
Constructor Summary
ConstructorsConstructorDescriptionSession(SMTPServer server, org.subethamail.smtp.server.ServerThread serverThread, Socket socket) Creates the Runnable Session object. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddRecipient(String recipientAddress) voidClose the client socket if it is openintbooleanDeprecated.getHelo()Simple stateintReturns an identifier of the session which is reasonably unique within an extended time period.Returns the first accepted recipient if there is exactly one accepted recipient, otherwise it returns null.This method is only used by the start tls commandReturns the identity of the peer which was established as part of the TLS handshake as defined bySSLSession.getPeerCertificates().booleanbooleanReturns true if a mail transaction is started, i.e. a MAIL command is received, and the transaction is not yet completed or aborted.booleanvoidquit()Triggers the shutdown of the thread and the closing of the connection.voidStops the mail transaction if it in progress and resets all state related to mail transactions.voidDeprecated.voidReset the SMTP protocol to the initial state, which is the state after a server issues a 220 service ready greeting.voidrun()The thread for each session runs on this and shuts down when the quitting member goes true.voidsendResponse(String response) Sends the response to the clientvoidThis is called by the AuthCommand when a session is successfully authenticated.voidsetDeclaredMessageSize(int declaredMessageSize) voidvoidInitializes our reader, writer, and the i/o filter chains based on the specified socket.voidsetTlsPeerCertificates(Certificate[] tlsPeerCertificates) voidsetTlsStarted(boolean tlsStarted) voidStarts a mail transaction by creating a new message handler.
-
Constructor Details
-
Session
public Session(SMTPServer server, org.subethamail.smtp.server.ServerThread serverThread, Socket socket) throws IOException Creates the Runnable Session object.- Parameters:
server- a link to our parentsocket- is the socket to the client- Throws:
IOException
-
-
Method Details
-
getServer
- Returns:
- a reference to the master server object
-
run
public void run()The thread for each session runs on this and shuts down when the quitting member goes true. -
setSocket
Initializes our reader, writer, and the i/o filter chains based on the specified socket. This is called internally when we startup and when (if) SSL is started.- Throws:
IOException
-
getSocket
This method is only used by the start tls command- Returns:
- the current socket to the client
-
closeSocket
Close the client socket if it is open- Throws:
IOException
-
getRawInput
- Returns:
- the raw input stream from the client
-
getReader
- Returns:
- the cooked CRLF-terminated reader from the client
-
sendResponse
Sends the response to the client- Throws:
IOException
-
getSessionId
Returns an identifier of the session which is reasonably unique within an extended time period. -
getRemoteAddress
- Specified by:
getRemoteAddressin interfaceMessageContext- Returns:
- the IP address of the remote server.
-
getSMTPServer
- Specified by:
getSMTPServerin interfaceMessageContext- Returns:
- the SMTPServer object.
-
getMessageHandler
- Returns:
- the current message handler
-
getHelo
Simple state- Specified by:
getHeloin interfaceMessageContext- Returns:
- the host name or address literal the client supplied in the HELO or EHLO command, or null if neither of these commands were received yet. Note that SubEthaSMTP (along with some MTAs, but contrary to RFC 5321) accept mail transactions without these commands.
-
setHelo
-
getHasMailFrom
Deprecated. -
addRecipient
-
getRecipientCount
public int getRecipientCount() -
getSingleRecipient
Returns the first accepted recipient if there is exactly one accepted recipient, otherwise it returns null. -
isAuthenticated
public boolean isAuthenticated() -
getAuthenticationHandler
- Specified by:
getAuthenticationHandlerin interfaceMessageContext- Returns:
- the handler instance that was used to authenticate.
-
setAuthenticationHandler
This is called by the AuthCommand when a session is successfully authenticated. The handler will be an object created by the AuthenticationHandlerFactory. -
getDeclaredMessageSize
public int getDeclaredMessageSize()- Returns:
- the maxMessageSize
-
setDeclaredMessageSize
public void setDeclaredMessageSize(int declaredMessageSize) - Parameters:
declaredMessageSize- the size that the client says the message will be
-
startMailTransaction
Starts a mail transaction by creating a new message handler.- Throws:
IllegalStateException- if a mail transaction is already in progress
-
isMailTransactionInProgress
public boolean isMailTransactionInProgress()Returns true if a mail transaction is started, i.e. a MAIL command is received, and the transaction is not yet completed or aborted. A transaction is successfully completed after the message content is received and accepted at the end of the DATA command. -
resetMailTransaction
public void resetMailTransaction()Stops the mail transaction if it in progress and resets all state related to mail transactions.Note: Some state is associated with each particular message (senders, recipients, the message handler).
Some state is not; seeing hello, TLS, authentication. -
resetMessageState
Deprecated. -
resetSmtpProtocol
public void resetSmtpProtocol()Reset the SMTP protocol to the initial state, which is the state after a server issues a 220 service ready greeting. -
quit
public void quit()Triggers the shutdown of the thread and the closing of the connection. -
isTLSStarted
public boolean isTLSStarted()- Returns:
- true when the TLS handshake was completed, false otherwise
-
setTlsStarted
public void setTlsStarted(boolean tlsStarted) - Parameters:
tlsStarted- true when the TLS handshake was completed, false otherwise
-
setTlsPeerCertificates
-
getTlsPeerCertificates
Returns the identity of the peer which was established as part of the TLS handshake as defined bySSLSession.getPeerCertificates().In order to get this information, override
SMTPServer.createSSLSocket(java.net.Socket)and callsetNeedClientAuth(true)on the created socket.- Specified by:
getTlsPeerCertificatesin interfaceMessageContext- Returns:
- an ordered array of peer certificates, with the peer's own certificate first followed by any certificate authorities, or null when no such information is available
- See Also:
-
isMailTransactionInProgress()