i2p.susi.webmail.pop3
Class POP3MailBox

java.lang.Object
  extended by i2p.susi.webmail.pop3.POP3MailBox
All Implemented Interfaces:
NewMailListener

public class POP3MailBox
extends Object
implements NewMailListener

Author:
susi23

Nested Class Summary
static interface POP3MailBox.FetchRequest
           
 
Constructor Summary
POP3MailBox(String host, int port, String user, String pass)
          Does not connect.
 
Method Summary
 void close()
          Close without waiting for response.
(package private)  void close(boolean shouldWait)
          Close and optionally wait for response.
 boolean connectToServer()
          Connect to pop3 server if not connected.
(package private)  Collection<String> delete(Collection<String> uidls)
          Delete all at once and close.
 void destroy()
          Close without waiting for response, and remove any delayed tasks and resources.
 void foundNewMail()
          Relay from the checker to the webmail session object, which relays to MailCache, which will fetch the mail from us in a big circle
 void getBodies(Collection<POP3MailBox.FetchRequest> requests)
          Fetch headers and/or bodies.
 ReadBuffer getBody(String uidl)
          Fetch the body.
 ReadBuffer getHeader(String uidl)
          Fetch the header.
(package private)  long getLastActivity()
          Timestamp.
(package private)  long getLastChecked()
          Timestamp.
(package private)  Object getLock()
          For helper threads to lock
 int getNumMails()
          Warning - forces a connection.
 int getSize(String uidl)
          Get cached size of a message (via previous LIST command).
 Collection<String> getUIDLs()
          Only if connected.
(package private)  boolean hasQueuedDeletions()
          Do we have UIDLs to delete?
 boolean isConnected()
          Is the connection is still alive
 String lastError()
           
 void queueForDeletion(Collection<String> uidls)
          Queue for later deletion.
 void queueForDeletion(String uidl)
          Queue for later deletion.
 void refresh()
           
 void setNewMailListener(NewMailListener nml)
          Relay from the checker to the webmail session object, which relays to MailCache, which will fetch the mail from us in a big circle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

POP3MailBox

public POP3MailBox(String host,
                   int port,
                   String user,
                   String pass)
Does not connect. Caller must call connectToServer() if desired.

Parameters:
host -
port -
user -
pass -
Method Detail

getHeader

public ReadBuffer getHeader(String uidl)
Fetch the header. Does not cache.

Parameters:
uidl -
Returns:
Byte buffer containing header data or null

getBody

public ReadBuffer getBody(String uidl)
Fetch the body. Does not cache.

Parameters:
uidl -
Returns:
Byte buffer containing body data or null

getBodies

public void getBodies(Collection<POP3MailBox.FetchRequest> requests)
Fetch headers and/or bodies. Does not cache. ReadBuffer objects are inserted into the requests. No total time limit.

Since:
0.9.13

queueForDeletion

public void queueForDeletion(Collection<String> uidls)
Queue for later deletion. Non-blocking.

Since:
0.9.13

queueForDeletion

public void queueForDeletion(String uidl)
Queue for later deletion. Non-blocking.

Since:
0.9.13

delete

Collection<String> delete(Collection<String> uidls)
Delete all at once and close. Does not reconnect. Do NOT call performDelete() after this. Returns all UIDLs successfully deleted OR were not known by the server.

Since:
0.9.13

getSize

public int getSize(String uidl)
Get cached size of a message (via previous LIST command).

Parameters:
uidl -
Returns:
Message size in bytes or 0 if not found

isConnected

public boolean isConnected()
Is the connection is still alive

Returns:
true or false

getLastActivity

long getLastActivity()
Timestamp.

Since:
0.9.13

getLastChecked

long getLastChecked()
Timestamp. When we last successfully got the UIDL list.

Since:
0.9.13

refresh

public void refresh()

connectToServer

public boolean connectToServer()
Connect to pop3 server if not connected. Does nothing if already connected.

Returns:
true if connected
Since:
0.9.13

getNumMails

public int getNumMails()
Warning - forces a connection.

Returns:
The amount of e-mails available.

lastError

public String lastError()
Returns:
The most recent error message.

setNewMailListener

public void setNewMailListener(NewMailListener nml)
Relay from the checker to the webmail session object, which relays to MailCache, which will fetch the mail from us in a big circle

Since:
0.9.13

foundNewMail

public void foundNewMail()
Relay from the checker to the webmail session object, which relays to MailCache, which will fetch the mail from us in a big circle

Specified by:
foundNewMail in interface NewMailListener
Since:
0.9.13

destroy

public void destroy()
Close without waiting for response, and remove any delayed tasks and resources.


getLock

Object getLock()
For helper threads to lock

Since:
0.9.13

hasQueuedDeletions

boolean hasQueuedDeletions()
Do we have UIDLs to delete?

Since:
0.9.13

close

public void close()
Close without waiting for response. Deletes all queued deletions.


close

void close(boolean shouldWait)
Close and optionally wait for response. Deletes all queued deletions.

Since:
0.9.13

getUIDLs

public Collection<String> getUIDLs()
Only if connected. Does not force a connect. If not connected, returns null.

Returns:
A new array of the available UIDLs. No particular order.