org.apache.geronimo.javamail.transport.nntp
Class NNTPConnection

java.lang.Object
  extended by org.apache.geronimo.javamail.util.MailConnection
      extended by org.apache.geronimo.javamail.transport.nntp.NNTPConnection

public class NNTPConnection
extends MailConnection

Simple implementation of NNTP transport. Just does plain RFC977-ish delivery.

Version:
$Rev: 673649 $ $Date: 2008-07-03 06:37:56 -0400 (Thu, 03 Jul 2008) $

Field Summary
protected  boolean authInfoSaslAllowed
           
protected  boolean authInfoUserAllowed
           
protected static char CR
          constants for EOL termination
protected static int DEFAULT_NNTP_PORT
          property keys for protocol properties.
protected  NNTPReply lastServerResponse
           
protected static char LF
           
protected  boolean postingAllowed
           
protected  BufferedReader reader
           
protected  String welcomeString
           
protected  PrintWriter writer
           
 
Fields inherited from class org.apache.geronimo.javamail.util.MailConnection
AUTHENTICATION_CRAMMD5, AUTHENTICATION_DIGESTMD5, AUTHENTICATION_LOGIN, AUTHENTICATION_PLAIN, authentications, authid, capabilities, CAPABILITY_STARTTLS, debug, debugStream, DEFAULT_MAIL_HOST, defaultPort, inputStream, localAddress, localHost, localPort, MAIL_AUTH, MAIL_AUTHORIZATIONID, MAIL_ENCODE_TRACE, MAIL_FACTORY_CLASS, MAIL_FACTORY_FALLBACK, MAIL_FACTORY_PORT, MAIL_LOCALADDRESS, MAIL_LOCALHOST, MAIL_LOCALPORT, MAIL_LOGIN_DISABLE, MAIL_PLAIN_DISABLE, MAIL_PORT, MAIL_SASL_ENABLE, MAIL_SASL_MECHANISMS, MAIL_SASL_REALM, MAIL_SSL_CIPHERSUITES, MAIL_SSL_ENABLE, MAIL_SSL_PROTOCOLS, MAIL_STARTTLS_ENABLE, MAIL_TIMEOUT, mechanisms, MIN_MILLIS, outputStream, password, props, protocol, realm, serverHost, serverPort, session, socket, sslConnection, timeout, TIMEOUT, username
 
Constructor Summary
NNTPConnection(ProtocolProperties props)
          Normal constructor for an NNTPConnection() object.
 
Method Summary
 void close()
          Close the connection.
 String extensionParameter(String name)
          Retrieve any argument information associated with a extension reported back by the server on the EHLO command.
protected  void getConnection()
          Create a transport connection object and connect it to the target server.
protected  void getExtensions()
          Ask the server what extensions it supports.
 String getLastServerResponse()
          Retrieve the last response received from the NNTP server.
 NNTPReply getReply()
          Get a reply line for an NNTP command.
protected  ClientAuthenticator getSaslAuthenticator()
          Attempt to retrieve a SASL authenticator for this protocol.
 void getWelcome()
          Get the servers welcome blob from the wire....
 String getWelcomeString()
          Retrieve the welcome string sent back from the server.
 boolean isPostingAllowed()
          Indicate whether posting is allowed for a given server.
protected  void processAuthentication(int request)
          Authenticate with the server, if necessary (or possible).
protected  void processAuthinfoSimple()
          Process an AUTHINFO SIMPLE command.
protected  void processAuthinfoUser()
          Process an AUTHINFO USER command.
protected  void processExtension(String extension)
          Process an extension string passed back as the LIST EXTENSIONS response.
protected  boolean processLogin(ClientAuthenticator authenticator)
          Process a login using the provided authenticator object.
protected  boolean processSaslAuthentication()
          Process SASL-type authentication.
 boolean protocolConnect(String host, int port, String username, String password)
          Connect to the server and do the initial handshaking.
 String receiveLine()
          Receives one line from the server.
 NNTPReply selectGroup(String name)
          Tell the server to switch to a named group.
 NNTPReply sendAuthCommand(String data)
          Send a command to the server, returning the first response line back as a reply.
 NNTPReply sendCommand(String data)
          Send a command to the server, returning the first response line back as a reply.
 NNTPReply sendCommand(String command, int success)
          Issue a command and retrieve the response.
 void sendLine(String data)
          Sends a message down the socket and terminates with the appropriate CRLF
 void sendPost(Message msg)
          Sends the data in the message down the socket.
 void sendQuit()
          Sends the QUIT message and receieves the response
 boolean supportsExtension(String name)
          Tests whether the target server supports a named extension.
 String toString()
           
 
Methods inherited from class org.apache.geronimo.javamail.util.MailConnection
checkConnected, closeServerConnection, connect, debugOut, debugOut, getCapabilities, getConnectedSocket, getConnectedSSLSocket, getConnectedTLSSocket, getConnectionProperties, getConnectionStreams, getHost, getLocalHost, getLoginAuthenticator, getSaslMechanisms, getSASLRealm, getServerMechanisms, hasCapability, selectSaslMechanisms, setLocalHost, setSASLRealm, supportsMechanism
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CR

protected static final char CR
constants for EOL termination

See Also:
Constant Field Values

LF

protected static final char LF
See Also:
Constant Field Values

DEFAULT_NNTP_PORT

protected static final int DEFAULT_NNTP_PORT
property keys for protocol properties.

See Also:
Constant Field Values

postingAllowed

protected boolean postingAllowed

authInfoUserAllowed

protected boolean authInfoUserAllowed

authInfoSaslAllowed

protected boolean authInfoSaslAllowed

lastServerResponse

protected NNTPReply lastServerResponse

welcomeString

protected String welcomeString

reader

protected BufferedReader reader

writer

protected PrintWriter writer
Constructor Detail

NNTPConnection

public NNTPConnection(ProtocolProperties props)
Normal constructor for an NNTPConnection() object.

Parameters:
props - The property bundle for this protocol instance.
Method Detail

protocolConnect

public boolean protocolConnect(String host,
                               int port,
                               String username,
                               String password)
                        throws MessagingException
Connect to the server and do the initial handshaking.

Overrides:
protocolConnect in class MailConnection
Parameters:
host - The target host name.
port - The target port
username - The connection username (can be null)
password - The authentication password (can be null).
Returns:
true if we were able to obtain a connection and authenticate.
Throws:
MessagingException

getConnection

protected void getConnection()
                      throws MessagingException
Create a transport connection object and connect it to the target server.

Overrides:
getConnection in class MailConnection
Throws:
MessagingException

close

public void close()
           throws MessagingException
Close the connection. On completion, we'll be disconnected from the server and unable to send more data.

Throws:
MessagingException

toString

public String toString()
Overrides:
toString in class Object

getWelcome

public void getWelcome()
                throws MessagingException
Get the servers welcome blob from the wire....

Throws:
MessagingException

sendQuit

public void sendQuit()
              throws MessagingException
Sends the QUIT message and receieves the response

Throws:
MessagingException

selectGroup

public NNTPReply selectGroup(String name)
                      throws MessagingException
Tell the server to switch to a named group.

Parameters:
name - The name of the target group.
Returns:
The server response to the GROUP command.
Throws:
MessagingException

getExtensions

protected void getExtensions()
                      throws MessagingException
Ask the server what extensions it supports.

Throws:
MessagingException

processExtension

protected void processExtension(String extension)
Process an extension string passed back as the LIST EXTENSIONS response.

Parameters:
extension - The string value of the extension (which will be of the form "NAME arguments").

extensionParameter

public String extensionParameter(String name)
Retrieve any argument information associated with a extension reported back by the server on the EHLO command.

Parameters:
name - The name of the target server extension.
Returns:
Any argument passed on a server extension. Returns null if the extension did not include an argument or the extension was not supported.

supportsExtension

public boolean supportsExtension(String name)
Tests whether the target server supports a named extension.

Parameters:
name - The target extension name.
Returns:
true if the target server reported on the EHLO command that is supports the targer server, false if the extension was not supported.

sendPost

public void sendPost(Message msg)
              throws MessagingException
Sends the data in the message down the socket. This presumes the server is in the right place and ready for getting the DATA message and the data right place in the sequence

Throws:
MessagingException

sendCommand

public NNTPReply sendCommand(String command,
                             int success)
                      throws MessagingException
Issue a command and retrieve the response. If the given success indicator is received, the command is returning a longer response, terminated by a "crlf.crlf" sequence. These lines are attached to the reply.

Parameters:
command - The command to issue.
success - The command reply that indicates additional data should be retrieved.
Returns:
The command reply.
Throws:
MessagingException

sendCommand

public NNTPReply sendCommand(String data)
                      throws MessagingException
Send a command to the server, returning the first response line back as a reply.

Parameters:
data - The data to send.
Returns:
A reply object with the reply line.
Throws:
MessagingException

sendAuthCommand

public NNTPReply sendAuthCommand(String data)
                          throws MessagingException
Send a command to the server, returning the first response line back as a reply.

Parameters:
data - The data to send.
Returns:
A reply object with the reply line.
Throws:
MessagingException

sendLine

public void sendLine(String data)
              throws MessagingException
Sends a message down the socket and terminates with the appropriate CRLF

Throws:
MessagingException

getReply

public NNTPReply getReply()
                   throws MessagingException
Get a reply line for an NNTP command.

Returns:
An NNTP reply object from the stream.
Throws:
MessagingException

getLastServerResponse

public String getLastServerResponse()
Retrieve the last response received from the NNTP server.

Returns:
The raw response string (including the error code) returned from the NNTP server.

receiveLine

public String receiveLine()
                   throws MessagingException
Receives one line from the server. A line is a sequence of bytes terminated by a CRLF

Returns:
the line from the server as String
Throws:
MessagingException

processAuthentication

protected void processAuthentication(int request)
                              throws MessagingException
Authenticate with the server, if necessary (or possible).

Throws:
MessagingException

processAuthinfoSimple

protected void processAuthinfoSimple()
                              throws MessagingException
Process an AUTHINFO SIMPLE command. Not widely used, but if the server asks for it, we can respond.

Throws:
MessagingException

processSaslAuthentication

protected boolean processSaslAuthentication()
                                     throws MessagingException
Process SASL-type authentication.

Returns:
Returns true if the server support a SASL authentication mechanism and accepted reponse challenges.
Throws:
MessagingException

getSaslAuthenticator

protected ClientAuthenticator getSaslAuthenticator()
Attempt to retrieve a SASL authenticator for this protocol.

Returns:
A SASL authenticator, or null if a suitable one was not located.

processLogin

protected boolean processLogin(ClientAuthenticator authenticator)
                        throws MessagingException
Process a login using the provided authenticator object. NB: This method is synchronized because we have a multi-step process going on here. No other commands should be sent to the server until we complete.

Returns:
Returns true if the server support a SASL authentication mechanism and accepted reponse challenges.
Throws:
MessagingException

processAuthinfoUser

protected void processAuthinfoUser()
                            throws MessagingException
Process an AUTHINFO USER command. Most common form of NNTP authentication.

Throws:
MessagingException

isPostingAllowed

public boolean isPostingAllowed()
Indicate whether posting is allowed for a given server.

Returns:
True if the server allows posting, false if the server is read-only.

getWelcomeString

public String getWelcomeString()
Retrieve the welcome string sent back from the server.

Returns:
The server provided welcome string.


Copyright © 2003-2009 The Apache Software Foundation. All Rights Reserved.