public final class Session extends Object implements Runnable, MessageContext
| Constructor and Description |
|---|
Session(SMTPServer server,
ServerThread serverThread,
Socket socket,
ProxyHandler proxyHandler)
Creates the Runnable Session object.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addRecipient(String recipientAddress) |
void |
closeSocket()
Close the client socket if it is open
|
Optional<AuthenticationHandler> |
getAuthenticationHandler() |
int |
getDeclaredMessageSize() |
Optional<String> |
getHelo()
Simple state
|
MessageHandler |
getMessageHandler() |
InputStream |
getRawInput() |
CRLFTerminatedReader |
getReader() |
InetSocketAddress |
getRealRemoteAddress()
Returns the real connection remote address as seen by socket.
|
int |
getRecipientCount() |
InetSocketAddress |
getRemoteAddress() |
SMTPServer |
getServer() |
String |
getSessionId()
Returns an identifier of the session which is reasonably unique within an
extended time period.
|
Optional<String> |
getSingleRecipient()
Returns the first accepted recipient if there is exactly one accepted
recipient, otherwise it returns null.
|
SMTPServer |
getSMTPServer() |
Socket |
getSocket()
This method is only used by the start tls command
|
Certificate[] |
getTlsPeerCertificates()
Returns the identity of the peer which was established as part of the TLS handshake
as defined by
SSLSession.getPeerCertificates(). |
boolean |
isAuthenticated() |
boolean |
isMailTransactionInProgress()
Returns true if a mail transaction is started, i.e.
|
boolean |
isTLSStarted() |
void |
quit()
Triggers the shutdown of the thread and the closing of the connection.
|
void |
resetMailTransaction()
Stops the mail transaction if it in progress and resets all state related
to mail transactions.
|
void |
resetSmtpProtocol()
Reset the SMTP protocol to the initial state, which is the state after a
server issues a 220 service ready greeting.
|
void |
run()
The thread for each session runs on this and shuts down when the quitting
member goes true.
|
void |
sendResponse(String response)
Sends the response to the client
|
void |
setAuthenticationHandler(AuthenticationHandler handler)
This is called by the AuthCommand when a session is successfully
authenticated.
|
void |
setDeclaredMessageSize(int declaredMessageSize) |
void |
setHelo(String value) |
void |
setSocket(Socket socket)
Initializes our reader, writer, and the i/o filter chains based on the
specified socket.
|
void |
setTlsPeerCertificates(Certificate[] tlsPeerCertificates) |
void |
setTlsStarted(boolean tlsStarted) |
void |
startMailTransaction()
Starts a mail transaction by creating a new message handler.
|
public Session(SMTPServer server, ServerThread serverThread, Socket socket, ProxyHandler proxyHandler) throws IOException
server - a link to our parentsocket - is the socket to the clientIOExceptionpublic SMTPServer getServer()
public void run()
public void setSocket(Socket socket) throws IOException
IOExceptionpublic Socket getSocket()
public void closeSocket()
throws IOException
IOExceptionpublic InputStream getRawInput()
public CRLFTerminatedReader getReader()
public void sendResponse(String response) throws IOException
IOExceptionpublic String getSessionId()
getSessionId in interface MessageContextpublic InetSocketAddress getRealRemoteAddress()
getRemoteAddress() if
some proxy mechanism is in use.public InetSocketAddress getRemoteAddress()
getRemoteAddress in interface MessageContextNote that the returned object is always an instance of InetSocketAddress so you
can cast the returned object to that class for more information. In subethasmtp 6.x the
method return type will be changed to InetSocketAddress.
public SMTPServer getSMTPServer()
getSMTPServer in interface MessageContextpublic MessageHandler getMessageHandler()
public Optional<String> getHelo()
getHelo in interface MessageContextpublic void setHelo(String value)
public void addRecipient(String recipientAddress)
public int getRecipientCount()
public Optional<String> getSingleRecipient()
public boolean isAuthenticated()
public Optional<AuthenticationHandler> getAuthenticationHandler()
getAuthenticationHandler in interface MessageContextpublic void setAuthenticationHandler(AuthenticationHandler handler)
public int getDeclaredMessageSize()
public void setDeclaredMessageSize(int declaredMessageSize)
declaredMessageSize - the size that the client says the message will bepublic void startMailTransaction()
throws IllegalStateException
IllegalStateException - if a mail transaction is already in progresspublic boolean isMailTransactionInProgress()
public void resetMailTransaction()
Note: Some state is associated with each particular message (senders,
recipients, the message handler).
Some state is not; seeing hello, TLS, authentication.
public void resetSmtpProtocol()
public void quit()
public boolean isTLSStarted()
public void setTlsStarted(boolean tlsStarted)
tlsStarted - true when the TLS handshake was completed, false otherwisepublic void setTlsPeerCertificates(Certificate[] tlsPeerCertificates)
public Certificate[] getTlsPeerCertificates()
MessageContextSSLSession.getPeerCertificates().
In order to get this information, override SMTPServer.createSSLSocket(java.net.Socket) and call
setNeedClientAuth(true) on the created socket.getTlsPeerCertificates in interface MessageContextSSLSession.getPeerCertificates()Copyright © 2006–2024. All rights reserved.