org.abstracthorizon.mercury.imap
Class IMAPSession

java.lang.Object
  extended by org.abstracthorizon.danube.connection.ConnectionWrapper
      extended by org.abstracthorizon.mercury.imap.IMAPSession
All Implemented Interfaces:
EventListener, javax.mail.event.MessageCountListener, org.abstracthorizon.danube.adapter.Adaptable, org.abstracthorizon.danube.connection.Connection

public class IMAPSession
extends org.abstracthorizon.danube.connection.ConnectionWrapper
implements javax.mail.event.MessageCountListener

A class that represents IMAP session. This is connection wrapper.

Author:
Daniel Sendula

Field Summary
protected  boolean authorised
          Is user authenticated and authorised to use some commands
protected  boolean cleanInput
          Clear flag is set to indicate that skip_line mustn't be called after command.
protected  String commandLine
          Current command line
protected  long commandStarted
          Timestamp command started
protected  String defaultDomain
          Default domain if not specified in username
protected  boolean idling
          Are we in IDLE mode
protected  LoginContext lc
          Login context
protected static org.slf4j.Logger logger
          Logger
protected  IMAPConnectionHandler parent
          Handler that created this session
protected  Reader reader
          Input reader
protected  IMAPScanner scanner
          IMAP scanner to be used
protected  boolean secure
          Is secure conneciton
protected  javax.mail.Folder selectedFolder
          Selected folder
protected  javax.mail.Session session
          Mail session
protected  Socket socket
          Cached socket
protected  javax.mail.Store store
          Mail store
protected  String tag
          Current tag
protected  Writer writer
          Output writer
 
Fields inherited from class org.abstracthorizon.danube.connection.ConnectionWrapper
connection
 
Constructor Summary
IMAPSession(org.abstracthorizon.danube.connection.Connection connection, IMAPConnectionHandler parent)
          Constructor
 
Method Summary
 boolean authorise(String user, String pass)
          Authorises session.
 void close()
          Closes IMAP session (connection)
 long getCommandLasted()
          Returns number of millis how long last command execution lasted.
 OutputStream getDebugStream()
          Returns debug output stream
 String getDefaultDomain()
          Returns default domain name
 javax.mail.Session getJavaMailSession()
          Returns JavaMail session
 boolean getKeepLog()
          Returns should log be kept or not
 IMAPConnectionHandler getParent()
          Returns imap connection handler that created this object
 IMAPScanner getScanner()
          IMAP scanner
 javax.mail.Folder getSelectedFolder()
          Returns selected Folder
 javax.mail.Store getStore()
          Returns JavaMail store
 String getTag()
          Returns current tag
 boolean isAuthorised()
          Is session authorised or not
 boolean isCleanInput()
          Returns if it is clean input
 boolean isIdling()
          Returns if IDLE command is allowed
 boolean isInsecureAllowed()
          Returns if insecure is allowed
 boolean isSecure()
          Returns if socket is SSL socket if socket available.
 void markCommandStarted()
          Marks when command has started
 void messagesAdded(javax.mail.event.MessageCountEvent event)
          Notifies that new message is added
 void messagesRemoved(javax.mail.event.MessageCountEvent event)
          NOtifies that message is removed
 void setCleanInput(boolean cleanInput)
          Sets if it is clean input
 void setDefaultDomain(String domain)
          Sets default domain name to be used with usernames
 void setIdling(boolean idling)
          Sets if IDLE command is allowed
 void setJavaMailSession(javax.mail.Session session)
          Sets JavaMail session
 void setKeepLog(boolean keepLog)
          Sets should log be kept or not
 void setSelectedFolder(javax.mail.Folder folder)
          Sets selected Folder
 void setTag(String tag)
          Sets current tag
 void switchToTLS()
          Switches to TLS (SSL) socket
 void unauthorise()
          Removes authorisation
 void writeLogMessage(String msg)
          Writes log message
 
Methods inherited from class org.abstracthorizon.danube.connection.ConnectionWrapper
adapt, isClosed
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected static final org.slf4j.Logger logger
Logger


parent

protected IMAPConnectionHandler parent
Handler that created this session


tag

protected String tag
Current tag


commandLine

protected String commandLine
Current command line


authorised

protected boolean authorised
Is user authenticated and authorised to use some commands


writer

protected Writer writer
Output writer


reader

protected Reader reader
Input reader


scanner

protected IMAPScanner scanner
IMAP scanner to be used


store

protected javax.mail.Store store
Mail store


selectedFolder

protected javax.mail.Folder selectedFolder
Selected folder


session

protected javax.mail.Session session
Mail session


lc

protected LoginContext lc
Login context


secure

protected boolean secure
Is secure conneciton


idling

protected boolean idling
Are we in IDLE mode


cleanInput

protected boolean cleanInput
Clear flag is set to indicate that skip_line mustn't be called after command. This was needed for STARTTLS command.


socket

protected Socket socket
Cached socket


commandStarted

protected long commandStarted
Timestamp command started


defaultDomain

protected String defaultDomain
Default domain if not specified in username

Constructor Detail

IMAPSession

public IMAPSession(org.abstracthorizon.danube.connection.Connection connection,
                   IMAPConnectionHandler parent)
Constructor

Parameters:
connection - connection
parent - imap connection handler that is creating this object
Method Detail

getParent

public IMAPConnectionHandler getParent()
Returns imap connection handler that created this object

Returns:
imap connection handler that created this object

setKeepLog

public void setKeepLog(boolean keepLog)
Sets should log be kept or not

Parameters:
keepLog - should log be kept

getKeepLog

public boolean getKeepLog()
Returns should log be kept or not

Returns:
should log be kept or not

writeLogMessage

public void writeLogMessage(String msg)
Writes log message

Parameters:
msg - log message

getDebugStream

public OutputStream getDebugStream()
Returns debug output stream

Returns:
debug output stream

isAuthorised

public boolean isAuthorised()
Is session authorised or not

Returns:

getCommandLasted

public long getCommandLasted()
Returns number of millis how long last command execution lasted.

Returns:
difference of time between now and when last command has been started

markCommandStarted

public void markCommandStarted()
Marks when command has started


getStore

public javax.mail.Store getStore()
Returns JavaMail store

Returns:
JavaMail store

getSelectedFolder

public javax.mail.Folder getSelectedFolder()
Returns selected Folder

Returns:
selected Folder

setSelectedFolder

public void setSelectedFolder(javax.mail.Folder folder)
Sets selected Folder

Parameters:
folder - selected Folder

getScanner

public IMAPScanner getScanner()
IMAP scanner

Returns:
IMAP scanner

getJavaMailSession

public javax.mail.Session getJavaMailSession()
Returns JavaMail session

Returns:
JavaMail session

setJavaMailSession

public void setJavaMailSession(javax.mail.Session session)
Sets JavaMail session

Parameters:
session - JavaMail session

isInsecureAllowed

public boolean isInsecureAllowed()
Returns if insecure is allowed

Returns:
if insecure is allowed

isSecure

public boolean isSecure()
Returns if socket is SSL socket if socket available. Otherwise true

Returns:
if socket is SSL socket

setIdling

public void setIdling(boolean idling)
Sets if IDLE command is allowed

Parameters:
idling - if IDLE command is allowed

isIdling

public boolean isIdling()
Returns if IDLE command is allowed

Returns:
if IDLE command is allowed

isCleanInput

public boolean isCleanInput()
Returns if it is clean input

Returns:
if it is clean input

setCleanInput

public void setCleanInput(boolean cleanInput)
Sets if it is clean input

Parameters:
cleanInput - is clean input

getTag

public String getTag()
Returns current tag

Returns:
current tag

setTag

public void setTag(String tag)
Sets current tag

Parameters:
tag - current tag

getDefaultDomain

public String getDefaultDomain()
Returns default domain name

Returns:
default domain name

setDefaultDomain

public void setDefaultDomain(String domain)
Sets default domain name to be used with usernames

Parameters:
domain -

authorise

public boolean authorise(String user,
                         String pass)
                  throws javax.mail.MessagingException
Authorises session. It uses storage manager for it. If username doesn't contain domain then it uses default domain name as set in setDefaultDomain(String)

Parameters:
user - username
pass - password
Returns:
true if it succeded
Throws:
javax.mail.MessagingException

unauthorise

public void unauthorise()
Removes authorisation


close

public void close()
Closes IMAP session (connection)

Specified by:
close in interface org.abstracthorizon.danube.connection.Connection
Overrides:
close in class org.abstracthorizon.danube.connection.ConnectionWrapper

switchToTLS

public void switchToTLS()
                 throws IOException
Switches to TLS (SSL) socket

Throws:
IOException

messagesAdded

public void messagesAdded(javax.mail.event.MessageCountEvent event)
Notifies that new message is added

Specified by:
messagesAdded in interface javax.mail.event.MessageCountListener
Parameters:
event - message count event

messagesRemoved

public void messagesRemoved(javax.mail.event.MessageCountEvent event)
NOtifies that message is removed

Specified by:
messagesRemoved in interface javax.mail.event.MessageCountListener
Parameters:
even - event


Copyright © 2005-2009 Abstract Horizon. All Rights Reserved.