Package i2p.susi.webmail.pop3
Class POP3MailBox
java.lang.Object
i2p.susi.webmail.pop3.POP3MailBox
- All Implemented Interfaces:
NewMailListener
public class POP3MailBox extends Object implements NewMailListener
- Author:
- susi23
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
POP3MailBox.FetchRequest
-
Constructor Summary
Constructors Constructor Description POP3MailBox(String host, int port, String user, String pass)
Does not connect. -
Method Summary
Modifier and Type Method Description (package private) boolean
blockingConnectToServer()
Connect to pop3 server if not connected.void
close()
Close without waiting for response.(package private) void
close(boolean shouldWait)
Close and optionally wait for response.boolean
connectToServer(NewMailListener nml)
Connect to pop3 server if not connected.(package private) void
deletePending(boolean noWait)
Delete all pending deletions at once.void
destroy()
Close without waiting for response, and remove any delayed tasks and resources.void
foundNewMail(boolean yes)
Relay from the checker to the webmail session object, which relays to MailCache, which will fetch the mail from us in a big circlevoid
getBodies(Collection<POP3MailBox.FetchRequest> requests)
Fetch headers and/or bodies.Buffer
getBody(String uidl, Buffer buffer)
Fetch the body.Buffer
getHeader(String uidl)
Fetch the header.(package private) long
getLastActivity()
Timestamp.(package private) long
getLastChecked()
Timestamp.(package private) Object
getLock()
For helper threads to lockint
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?(package private) boolean
isConnected()
Is the connection is still aliveString
lastError()
void
queueForDeletion(String uidl)
Queue for later deletion.void
queueForDeletion(Collection<String> uidls)
Queue for later deletion.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
-
Constructor Details
-
POP3MailBox
Does not connect. Caller must call connectToServer() if desired.- Parameters:
host
-port
-user
-pass
-
-
-
Method Details
-
getHeader
Fetch the header. Does not cache.- Parameters:
uidl
-- Returns:
- Byte buffer containing header data or null
-
getBody
Fetch the body. Does not cache.- Parameters:
uidl
-- Returns:
- the buffer containing body data or null
-
getBodies
Fetch headers and/or bodies. Does not cache. ReadBuffer objects are inserted into the requests. No total time limit.- Since:
- 0.9.13
-
queueForDeletion
Queue for later deletion. Non-blocking.- Since:
- 0.9.13
-
queueForDeletion
Queue for later deletion. Non-blocking.- Since:
- 0.9.13
-
deletePending
void deletePending(boolean noWait)Delete all pending deletions at once. If previously connected, leaves connected. If not previously connected, closes connection when done.- Parameters:
noWait
- fire-and-forget mode, only if connected- Since:
- 0.9.13
-
getSize
Get cached size of a message (via previous LIST command).- Parameters:
uidl
-- Returns:
- Message size in bytes or 0 if not found
-
isConnected
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
-
connectToServer
Connect to pop3 server if not connected. Checks mail if already connected. Non-Blocking unless an action already in progress. This will NOT call any configured NewMailListener, only the one passed in. It will be called with the value true if the connect was successful, false if not. Call getNumMails() to see if there really was any new mail. After the callback is executed, the information on new mails, if any, is available via getNumMails(), getUIDLs(), and getSize(). The connection to the server will remain open, so that new emails may be retrieved via getHeader(), getBody(), and getBodies(). Failure info is available via lastError().- Returns:
- true if nml will be called back, false on failure and nml will NOT be called back
- Since:
- 0.9.13
-
blockingConnectToServer
boolean blockingConnectToServer()Connect to pop3 server if not connected. Does nothing if already connected. Blocking. This will NOT call any configured NewMailListener. After the callback is executed, the information on new mails, if any, is available via getNumMails(), getUIDLs(), and getSize(). The connection to the server will remain open, so that new emails may be retrieved via getHeader(), getBody(), and getBodies(). Failure info is available via lastError().- Returns:
- true if connected
- Since:
- 0.9.13
-
getNumMails
public int getNumMails()Warning - forces a connection.- Returns:
- The amount of e-mails available.
-
lastError
- Returns:
- The most recent error message. Probably not terminated with a newline.
-
setNewMailListener
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(boolean yes)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 interfaceNewMailListener
- 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
Only if connected. Does not force a connect. If not connected, returns null.- Returns:
- A new array of the available UIDLs. No particular order.
-