Quadcap Embeddable Server

com.quadcap.pop3.client.Session Class Reference

List of all members.

Detailed Description

This class implementes a simple mapping of the POP3 protocol onto methods of a java class.

Author:
Stan Bailes

Definition at line 69 of file Session.java.

Public Member Functions

 Session (String host, int port)
 Construct a POP3 client object.

int connect () throws IOException, UnknownHostException
 Open the socket to the server and return the status code for the server's greeting.

int getResponse () throws IOException
 Read a response line from the server.

InputStream getResponse (boolean get) throws IOException
 Prepare to read multi-line response.

int user (String name) throws IOException
int pass (String pass) throws IOException
InputStream list () throws IOException
Vector list (String msg) throws IOException
Vector stat () throws IOException
InputStream uidl () throws IOException
Vector uidl (String msg) throws IOException
InputStream retr (String msg) throws IOException
InputStream retr (int i) throws IOException
int dele (String msg) throws IOException
int dele (int i) throws IOException
InputStream top (String msg, int lines) throws IOException
int rset () throws IOException
int quit () throws IOException

Static Public Attributes

final int CR = '\r'
 Useful constant for CR.

final int LF = '\n'
 Useful constant for LF.

final int OK = 0
 Useful constant for OK status.

final int ERR = 1
 Useful constant for ERR status.


Package Functions

void writeCmd (byte[]cmd, String val) throws IOException
 Write a POP3 command and arguments.

int simpleCmd (byte[] cmd, String val) throws IOException
 Execute a simple command which just expects an OR or ERR response.

InputStream responseCmd (byte[] cmd, String val) throws IOException
 Execute a command which expects a multi-line response.

Vector vectorCmd (byte[] cmd, String val) throws IOException
 Execute a command which needs to parse the response line.


Package Attributes

String host = null
 server portion of host address.

int port = -1
 the port portion of the host address.

Socket socket = null
 Sockect used to communicate with the server.

InputStream in = null
 Input (responses) from server.

OutputStream out = null
 Output (commands) to the server.

ByteArrayOutputStream resp = new ByteArrayOutputStream()
 A temporary area used to collect server responses.

String response = null
 The last response, as a string.


Static Private Attributes

final byte[] CRLF = { CR, LF }
 Handy constant for CRLF sequence.

final byte[] userBytes
 The USER command.

final byte[] passBytes
 The PASS command.

final byte[] listBytes
 The LIST command.

final byte[] statBytes
 The STAT command.

final byte[] uidlBytes
 The UIDL command.

final byte[] retrBytes
 The RETR command.

final byte[] deleBytes
 The DELE command.

final byte[] topBytes
 The TOP command.

final byte[] rsetBytes
 The RSET command.

final byte[] quitBytes
 THE QUIT command.

final byte[] noopBytes
 The NOOP command.

final byte[] apopBytes
 THE APOP command.


Constructor & Destructor Documentation

com.quadcap.pop3.client.Session.Session String  host,
int  port
 

Construct a POP3 client object.

Initialize the host/port information, but don't actually open the socket.

Parameters:
host the server's host name
port the server's port number

Definition at line 112 of file Session.java.


Member Function Documentation

int com.quadcap.pop3.client.Session.connect  )  throws IOException, UnknownHostException
 

Open the socket to the server and return the status code for the server's greeting.

Definition at line 121 of file Session.java.

References com.quadcap.pop3.client.Session.getResponse(), com.quadcap.pop3.client.Session.host, com.quadcap.pop3.client.Session.in, com.quadcap.pop3.client.Session.out, com.quadcap.pop3.client.Session.port, and com.quadcap.pop3.client.Session.socket.

Referenced by com.quadcap.pop3.client.Pop3Agent.run(), com.quadcap.pop3.client.Agent.run(), and com.quadcap.pop3.client.Test.test0().

int com.quadcap.pop3.client.Session.dele int  i  )  throws IOException
 

Definition at line 294 of file Session.java.

int com.quadcap.pop3.client.Session.dele String  msg  )  throws IOException
 

Definition at line 291 of file Session.java.

References com.quadcap.pop3.client.Session.dele(), and com.quadcap.pop3.client.Session.deleBytes.

Referenced by com.quadcap.pop3.client.Session.dele(), com.quadcap.pop3.client.Pop3Agent.deleteMessages(), com.quadcap.pop3.client.Agent.getAndDeleteMail(), and com.quadcap.pop3.client.Pop3Agent.getMessages().

InputStream com.quadcap.pop3.client.Session.getResponse boolean  get  )  throws IOException
 

Prepare to read multi-line response.

Return an input stream which must be read to actually get the response.

Definition at line 188 of file Session.java.

References com.quadcap.pop3.client.Session.getResponse(), com.quadcap.pop3.client.Session.in, and com.quadcap.pop3.client.Session.OK.

int com.quadcap.pop3.client.Session.getResponse  )  throws IOException
 

Read a response line from the server.

We expect this to be a string of the form '+OK ...' or '-ERR ...'.

Returns:
OK or ERR.

Definition at line 152 of file Session.java.

References com.quadcap.pop3.client.Session.CR, com.quadcap.pop3.client.Session.ERR, com.quadcap.pop3.client.Session.in, com.quadcap.pop3.client.Session.LF, com.quadcap.pop3.client.Session.OK, com.quadcap.pop3.client.Session.out, com.quadcap.pop3.client.Session.resp, and com.quadcap.pop3.client.Session.response.

Referenced by com.quadcap.pop3.client.Session.connect(), com.quadcap.pop3.client.Session.getResponse(), com.quadcap.pop3.client.Session.responseCmd(), com.quadcap.pop3.client.Session.simpleCmd(), and com.quadcap.pop3.client.Session.vectorCmd().

Vector com.quadcap.pop3.client.Session.list String  msg  )  throws IOException
 

Definition at line 255 of file Session.java.

References com.quadcap.pop3.client.Session.listBytes.

InputStream com.quadcap.pop3.client.Session.list  )  throws IOException
 

Definition at line 252 of file Session.java.

References com.quadcap.pop3.client.Session.listBytes.

Referenced by com.quadcap.pop3.client.Test.test0().

int com.quadcap.pop3.client.Session.pass String  pass  )  throws IOException
 

Definition at line 244 of file Session.java.

References com.quadcap.pop3.client.Session.pass(), and com.quadcap.pop3.client.Session.passBytes.

Referenced by com.quadcap.pop3.client.Session.pass(), com.quadcap.pop3.client.Pop3Agent.run(), com.quadcap.pop3.client.Agent.run(), and com.quadcap.pop3.client.Test.test0().

int com.quadcap.pop3.client.Session.quit  )  throws IOException
 

Definition at line 315 of file Session.java.

References com.quadcap.pop3.client.Session.OK, com.quadcap.pop3.client.Session.quitBytes, and com.quadcap.pop3.client.Session.socket.

Referenced by com.quadcap.pop3.client.Pop3Agent.run(), com.quadcap.pop3.client.Agent.run(), and com.quadcap.pop3.client.Test.test0().

InputStream com.quadcap.pop3.client.Session.responseCmd byte[]  cmd,
String  val
throws IOException [package]
 

Execute a command which expects a multi-line response.

Definition at line 218 of file Session.java.

References com.quadcap.pop3.client.Session.getResponse(), and com.quadcap.pop3.client.Session.responseCmd().

Referenced by com.quadcap.pop3.client.Session.responseCmd().

InputStream com.quadcap.pop3.client.Session.retr int  i  )  throws IOException
 

Definition at line 285 of file Session.java.

InputStream com.quadcap.pop3.client.Session.retr String  msg  )  throws IOException
 

Definition at line 282 of file Session.java.

References com.quadcap.pop3.client.Session.retr(), and com.quadcap.pop3.client.Session.retrBytes.

Referenced by com.quadcap.pop3.client.Agent.getAndDeleteMail(), com.quadcap.pop3.client.Pop3Agent.getMessages(), com.quadcap.pop3.client.Session.retr(), and com.quadcap.pop3.client.Test.test0().

int com.quadcap.pop3.client.Session.rset  )  throws IOException
 

Definition at line 307 of file Session.java.

References com.quadcap.pop3.client.Session.rsetBytes.

Referenced by com.quadcap.pop3.client.Test.test0().

int com.quadcap.pop3.client.Session.simpleCmd byte[]  cmd,
String  val
throws IOException [package]
 

Execute a simple command which just expects an OR or ERR response.

Definition at line 210 of file Session.java.

References com.quadcap.pop3.client.Session.getResponse(), and com.quadcap.pop3.client.Session.simpleCmd().

Referenced by com.quadcap.pop3.client.Session.simpleCmd().

Vector com.quadcap.pop3.client.Session.stat  )  throws IOException
 

Definition at line 263 of file Session.java.

References com.quadcap.pop3.client.Session.statBytes.

Referenced by com.quadcap.pop3.client.Agent.getAndDeleteMail(), and com.quadcap.pop3.client.Test.test0().

InputStream com.quadcap.pop3.client.Session.top String  msg,
int  lines
throws IOException
 

Definition at line 299 of file Session.java.

References com.quadcap.pop3.client.Session.top(), and com.quadcap.pop3.client.Session.topBytes.

Referenced by com.quadcap.pop3.client.Pop3Agent.getMessages(), com.quadcap.pop3.client.Test.test0(), and com.quadcap.pop3.client.Session.top().

Vector com.quadcap.pop3.client.Session.uidl String  msg  )  throws IOException
 

Definition at line 274 of file Session.java.

References com.quadcap.pop3.client.Session.uidlBytes.

InputStream com.quadcap.pop3.client.Session.uidl  )  throws IOException
 

Definition at line 271 of file Session.java.

References com.quadcap.pop3.client.Session.uidlBytes.

Referenced by com.quadcap.pop3.client.Pop3Agent.getMail(), and com.quadcap.pop3.client.Test.test0().

int com.quadcap.pop3.client.Session.user String  name  )  throws IOException
 

Definition at line 236 of file Session.java.

References com.quadcap.pop3.client.Session.user(), and com.quadcap.pop3.client.Session.userBytes.

Referenced by com.quadcap.pop3.client.Pop3Agent.run(), com.quadcap.pop3.client.Agent.run(), com.quadcap.pop3.client.Test.test0(), and com.quadcap.pop3.client.Session.user().

Vector com.quadcap.pop3.client.Session.vectorCmd byte[]  cmd,
String  val
throws IOException [package]
 

Execute a command which needs to parse the response line.

Definition at line 226 of file Session.java.

References com.quadcap.pop3.client.Session.getResponse(), com.quadcap.pop3.client.Session.response, and com.quadcap.pop3.client.Session.vectorCmd().

Referenced by com.quadcap.pop3.client.Session.vectorCmd().

void com.quadcap.pop3.client.Session.writeCmd byte[]  cmd,
String  val
throws IOException [package]
 

Write a POP3 command and arguments.

Parameters:
cmd a byte array containing the command literal
val a String to be appended to the 'cmd'

Definition at line 201 of file Session.java.

References com.quadcap.pop3.client.Session.CRLF, com.quadcap.pop3.client.Session.out, and com.quadcap.pop3.client.Session.writeCmd().

Referenced by com.quadcap.pop3.client.Session.writeCmd().


Member Data Documentation

final byte [] com.quadcap.pop3.client.Session.apopBytes [static, private]
 

Initial value:

{(byte)'A', (byte)'P', (byte)'O', (byte)'P', (byte) }
THE APOP command.

Definition at line 330 of file Session.java.

final int com.quadcap.pop3.client.Session.CR = '\r' [static]
 

Useful constant for CR.

Definition at line 137 of file Session.java.

Referenced by com.quadcap.pop3.client.Session.getResponse().

final byte [] com.quadcap.pop3.client.Session.CRLF = { CR, LF } [static, private]
 

Handy constant for CRLF sequence.

Definition at line 194 of file Session.java.

Referenced by com.quadcap.pop3.client.Session.writeCmd().

final byte [] com.quadcap.pop3.client.Session.deleBytes [static, private]
 

Initial value:

{(byte)'D',(byte)'E', (byte)'L',(byte)'E', (byte) }
The DELE command.

Definition at line 288 of file Session.java.

Referenced by com.quadcap.pop3.client.Session.dele().

final int com.quadcap.pop3.client.Session.ERR = 1 [static]
 

Useful constant for ERR status.

Definition at line 144 of file Session.java.

Referenced by com.quadcap.pop3.client.Session.getResponse().

String com.quadcap.pop3.client.Session.host = null [package]
 

server portion of host address.

Definition at line 73 of file Session.java.

Referenced by com.quadcap.pop3.client.Session.connect().

InputStream com.quadcap.pop3.client.Session.in = null [package]
 

Input (responses) from server.

Definition at line 87 of file Session.java.

Referenced by com.quadcap.pop3.client.Session.connect(), and com.quadcap.pop3.client.Session.getResponse().

final int com.quadcap.pop3.client.Session.LF = '\n' [static]
 

Useful constant for LF.

Definition at line 139 of file Session.java.

Referenced by com.quadcap.pop3.client.Session.getResponse().

final byte [] com.quadcap.pop3.client.Session.listBytes [static, private]
 

Initial value:

{(byte)'L',(byte)'I', (byte)'S',(byte)'T', (byte) }
The LIST command.

Definition at line 249 of file Session.java.

Referenced by com.quadcap.pop3.client.Session.list().

final byte [] com.quadcap.pop3.client.Session.noopBytes [static, private]
 

Initial value:

{(byte)'N', (byte)'O', (byte)'O', (byte)'P', (byte) }
The NOOP command.

Definition at line 325 of file Session.java.

final int com.quadcap.pop3.client.Session.OK = 0 [static]
 

Useful constant for OK status.

Definition at line 142 of file Session.java.

Referenced by com.quadcap.pop3.client.Session.getResponse(), and com.quadcap.pop3.client.Session.quit().

OutputStream com.quadcap.pop3.client.Session.out = null [package]
 

Output (commands) to the server.

Definition at line 92 of file Session.java.

Referenced by com.quadcap.pop3.client.Session.connect(), com.quadcap.pop3.client.Session.getResponse(), and com.quadcap.pop3.client.Session.writeCmd().

final byte [] com.quadcap.pop3.client.Session.passBytes [static, private]
 

Initial value:

{(byte)'P',(byte)'A', (byte)'S',(byte)'S', (byte) }
The PASS command.

Definition at line 241 of file Session.java.

Referenced by com.quadcap.pop3.client.Session.pass().

int com.quadcap.pop3.client.Session.port = -1 [package]
 

the port portion of the host address.

Definition at line 77 of file Session.java.

Referenced by com.quadcap.pop3.client.Session.connect().

final byte [] com.quadcap.pop3.client.Session.quitBytes [static, private]
 

Initial value:

{(byte)'Q', (byte)'U', (byte)'I', (byte)'T', (byte) }
THE QUIT command.

Definition at line 312 of file Session.java.

Referenced by com.quadcap.pop3.client.Session.quit().

ByteArrayOutputStream com.quadcap.pop3.client.Session.resp = new ByteArrayOutputStream() [package]
 

A temporary area used to collect server responses.

Definition at line 97 of file Session.java.

Referenced by com.quadcap.pop3.client.Session.getResponse().

String com.quadcap.pop3.client.Session.response = null [package]
 

The last response, as a string.

Definition at line 102 of file Session.java.

Referenced by com.quadcap.pop3.client.Session.getResponse(), and com.quadcap.pop3.client.Session.vectorCmd().

final byte [] com.quadcap.pop3.client.Session.retrBytes [static, private]
 

Initial value:

{(byte)'R',(byte)'E', (byte)'T',(byte)'R', (byte) }
The RETR command.

Definition at line 279 of file Session.java.

Referenced by com.quadcap.pop3.client.Session.retr().

final byte [] com.quadcap.pop3.client.Session.rsetBytes [static, private]
 

Initial value:

{(byte)'R',(byte)'S', (byte)'E',(byte)'T', (byte) }
The RSET command.

Definition at line 304 of file Session.java.

Referenced by com.quadcap.pop3.client.Session.rset().

Socket com.quadcap.pop3.client.Session.socket = null [package]
 

Sockect used to communicate with the server.

Definition at line 82 of file Session.java.

Referenced by com.quadcap.pop3.client.Session.connect(), and com.quadcap.pop3.client.Session.quit().

final byte [] com.quadcap.pop3.client.Session.statBytes [static, private]
 

Initial value:

{(byte)'S',(byte)'T', (byte)'A',(byte)'T', (byte) }
The STAT command.

Definition at line 260 of file Session.java.

Referenced by com.quadcap.pop3.client.Session.stat().

final byte [] com.quadcap.pop3.client.Session.topBytes [static, private]
 

Initial value:

{(byte)'T',(byte)'O', (byte)'P',(byte) }
The TOP command.

Definition at line 297 of file Session.java.

Referenced by com.quadcap.pop3.client.Session.top().

final byte [] com.quadcap.pop3.client.Session.uidlBytes [static, private]
 

Initial value:

{(byte)'U',(byte)'I', (byte)'D',(byte)'L', (byte) }
The UIDL command.

Definition at line 268 of file Session.java.

Referenced by com.quadcap.pop3.client.Session.uidl().

final byte [] com.quadcap.pop3.client.Session.userBytes [static, private]
 

Initial value:

{(byte)'U',(byte)'S', (byte)'E',(byte)'R', (byte) }
The USER command.

Definition at line 233 of file Session.java.

Referenced by com.quadcap.pop3.client.Session.user().