com.micromail
Class MailManager

java.lang.Object
  extended bycom.micromail.MailManager

public class MailManager
extends java.lang.Object

Manages the connection to the IMAP and SMTP servers and stores the FolderWrapper objects wrapping the standard Folder objects. It also stores the current HttpSession object


Nested Class Summary
 class MailManager.MyAuthenticator
          Provides user authentication for an SMTP server
 
Field Summary
static java.lang.String DRAFTS
          Generic identifer for the "Sent" folder
static java.lang.String INBOX
          Generic identifer for the "Inbox" folder
static java.lang.String SENT
          Generic identifer for the "Sent" folder
static java.lang.String TRASH
          Generic identifer for the "Trash" folder
 
Constructor Summary
MailManager(java.lang.String username, java.lang.String password, javax.servlet.http.HttpSession session)
          Creates a MailManager
 
Method Summary
 FolderWrapper copyToFolder(java.lang.String folderId, javax.mail.Message message)
          Copies a message to a folder
 FolderWrapper deleteFinal(FolderWrapper folderWrapper, java.lang.Integer[] messageNumbers)
          Deletes messages from a folder and creates a new FolderWrapper reflecting the changed content
 javax.servlet.ServletContext getContext()
          Gets the application ServletContext object
 FolderWrapper getFolderWrapper(java.lang.String folderId)
          Retrieves a specified Folder object from the from the mail server, and wraps it in a FolderWrapper object
 java.util.Iterator getfolderWrappers()
          Gets an Iterator across te set of FolderWrapper objects
 javax.mail.Session getMailSession()
          Gets the IMAP Session object
 javax.servlet.http.HttpSession getSession()
          Gets the current HttpSession object
 javax.mail.Session getSmtpSession()
          Getsthe SMTP Session object
 javax.mail.Store getStore()
          Getsthe IMAP Store object
 FolderWrapper moveToTrash(FolderWrapper folderWrapper, java.lang.Integer[] messageNumbers)
          Moves messages from a folder to the Trash foldera and creates a new FolderWrapper reflecting the changed content
 FolderWrapper saveDraft(java.lang.String to, java.lang.String subject, java.lang.String body, java.lang.String fromAddress, java.lang.String fromName)
          Saves a draft of a message.
 void sendMessage(java.lang.String to, java.lang.String subject, java.lang.String body, java.lang.String fromAddress, java.lang.String fromName, AttachmentManager attachmentManager)
          Assembles and sends a message
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INBOX

public static final java.lang.String INBOX
Generic identifer for the "Inbox" folder

See Also:
Constant Field Values

SENT

public static final java.lang.String SENT
Generic identifer for the "Sent" folder

See Also:
Constant Field Values

DRAFTS

public static final java.lang.String DRAFTS
Generic identifer for the "Sent" folder

See Also:
Constant Field Values

TRASH

public static final java.lang.String TRASH
Generic identifer for the "Trash" folder

See Also:
Constant Field Values
Constructor Detail

MailManager

public MailManager(java.lang.String username,
                   java.lang.String password,
                   javax.servlet.http.HttpSession session)
            throws javax.mail.NoSuchProviderException,
                   javax.mail.MessagingException
Creates a MailManager

Parameters:
username - the login username
Method Detail

getfolderWrappers

public java.util.Iterator getfolderWrappers()
Gets an Iterator across te set of FolderWrapper objects

Returns:
throws Iterator

getMailSession

public javax.mail.Session getMailSession()
Gets the IMAP Session object

Returns:
the Session object

getSmtpSession

public javax.mail.Session getSmtpSession()
Getsthe SMTP Session object

Returns:
the Session object

getStore

public javax.mail.Store getStore()
Getsthe IMAP Store object

Returns:
the Store object

getContext

public javax.servlet.ServletContext getContext()
Gets the application ServletContext object

Returns:
the ServletContext object

getSession

public javax.servlet.http.HttpSession getSession()
Gets the current HttpSession object

Returns:
the HttpSession object

getFolderWrapper

public FolderWrapper getFolderWrapper(java.lang.String folderId)
                               throws javax.mail.MessagingException
Retrieves a specified Folder object from the from the mail server, and wraps it in a FolderWrapper object

Parameters:
folderId - id of the desired folder
Throws:
javax.mail.MessagingException

deleteFinal

public FolderWrapper deleteFinal(FolderWrapper folderWrapper,
                                 java.lang.Integer[] messageNumbers)
                          throws javax.mail.MessagingException
Deletes messages from a folder and creates a new FolderWrapper reflecting the changed content

Parameters:
folderWrapper - the FolderWrapper object encapsulating the folder
messageNumbers - array of Integer objects identifying the messages to be deleted
Returns:
the new FolderWrapper object
Throws:
javax.mail.MessagingException

moveToTrash

public FolderWrapper moveToTrash(FolderWrapper folderWrapper,
                                 java.lang.Integer[] messageNumbers)
                          throws javax.mail.MessagingException
Moves messages from a folder to the Trash foldera and creates a new FolderWrapper reflecting the changed content

Parameters:
folderWrapper - the FolderWrapper object encapsulating the folder
messageNumbers - array of Integer objects identifying the messages to be deleted
Returns:
the new FolderWrapper object
Throws:
javax.mail.MessagingException

sendMessage

public void sendMessage(java.lang.String to,
                        java.lang.String subject,
                        java.lang.String body,
                        java.lang.String fromAddress,
                        java.lang.String fromName,
                        AttachmentManager attachmentManager)
                 throws javax.mail.internet.AddressException,
                        java.io.UnsupportedEncodingException,
                        javax.mail.MessagingException
Assembles and sends a message

Parameters:
to - recipient addresses
subject - message subject
body - text body of the message
fromAddress - sender address
fromName - sender name
attachmentManager - the attachment manager through which uploaded attachments are obtained
Throws:
javax.mail.internet.AddressException
java.io.UnsupportedEncodingException
javax.mail.MessagingException

saveDraft

public FolderWrapper saveDraft(java.lang.String to,
                               java.lang.String subject,
                               java.lang.String body,
                               java.lang.String fromAddress,
                               java.lang.String fromName)
                        throws javax.mail.MessagingException,
                               java.io.UnsupportedEncodingException
Saves a draft of a message. Attachments added to the message are not saved

Parameters:
to - recipient addresses
subject - message subject
body - text body of the message
fromAddress - sender address
fromName - sender name
Returns:
the FolderWrapper of the Drafts folder
Throws:
javax.mail.MessagingException
java.io.UnsupportedEncodingException

copyToFolder

public FolderWrapper copyToFolder(java.lang.String folderId,
                                  javax.mail.Message message)
                           throws javax.mail.MessagingException
Copies a message to a folder

Parameters:
folderId - id of the target folder
message - the message to be copied
Returns:
the wrappper object of the target folder
Throws:
javax.mail.MessagingException