Rakesh API

org.rakeshv.mail
Class SendHandler

java.lang.Object
  extended by org.rakeshv.mail.SendHandler

public class SendHandler
extends java.lang.Object

This class handles multipart/form-data encoded form posts from the write.jsp page that is used to compose email messages. This class parses out the message attributes, as well as all the attachments added to the message from the HttpServletRequest.

Copyright 2003, Rakesh Vidyadharan

Author:
Rakesh Vidyadharan 5th January 2003. $Id: SendHandler.java,v 1.5 2004/05/26 11:42:38 rakesh Exp $

Field Summary
private  AddressBook addressBook
          The AddressBook object for the current user.
private  javax.mail.Folder folder
          The Folder which the user is viewing at present.
private  WriteFormParser formParser
          The WriteFormParser class that is used to parse out the form parts and elements from the HttpRequest.
private  javax.mail.Message message
          The Message object that is to be created with all the attributes and parts specified in the form post.
private  javax.mail.Session session
          The web session for the user using the webmail service.
 
Constructor Summary
protected SendHandler()
          Default constructor.
  SendHandler(javax.mail.Folder folder, AddressBook addressBook, WriteFormParser formParser, javax.mail.Session session)
          Creates an instance of the handler, and sets the instance fields to the passed in values.
 
Method Summary
 javax.mail.Message createMessage()
          Creates the appropriate type of message.
 javax.mail.Message createMessage(javax.mail.Message currentMessage)
          Creates the appropriate type of message for forwarded mail.
private  void setBcc()
          Set the bcc attribute for the message.
private  void setBodyWithAttachments()
          Set the body parts for the reply.
private  void setCc()
          Set the cc attribute for the message.
private  void setDate()
          Set the date attribute for the message.
private  void setForwardBody(javax.mail.Message originalMessage)
          Set the body parts for the forwarded message.
private  void setFrom()
          Set the from attribute of the new message.
private  void setMessageAttributes()
          Set the common attributes for the message.
private  void setMessageBody()
          Sets the various body parts for the message.
private  void setSubject()
          Set the subject attribute for the message.
private  void setTo()
          Set the to attribute of the new message.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

session

private javax.mail.Session session
The web session for the user using the webmail service.


folder

private javax.mail.Folder folder
The Folder which the user is viewing at present. This is used to determine if the new message being created is a reply to an existing message or not.


addressBook

private AddressBook addressBook
The AddressBook object for the current user.


formParser

private WriteFormParser formParser
The WriteFormParser class that is used to parse out the form parts and elements from the HttpRequest.


message

private javax.mail.Message message
The Message object that is to be created with all the attributes and parts specified in the form post.

Constructor Detail

SendHandler

protected SendHandler()
Default constructor. Does nothing.


SendHandler

public SendHandler(javax.mail.Folder folder,
                   AddressBook addressBook,
                   WriteFormParser formParser,
                   javax.mail.Session session)
Creates an instance of the handler, and sets the instance fields to the passed in values.

Parameters:
folder - - The mail folder that the user is currently viewing. See folder.
addressBook - - The user's address book. See addressBook.
formParser - - The parsed contents of the form. The WriteFormParser.parseFormData() method must have been invoked prior to initialising this class.
session - - The web session. See session.
Method Detail

createMessage

public javax.mail.Message createMessage()
                                 throws javax.mail.MessagingException,
                                        java.io.IOException
Creates the appropriate type of message. Fetches all the attachments and properties for the new message from the WriteFormParser and creates the new Message. If no attachments were specified in the form post, a "text/plain" message is created, otherwise a "multipart/mixed" message is created.

Returns:
Message - The new message with all the message attributes including attachments set.
Throws:
javax.mail.MessagingException - - If any exceptions are encountered while creating the new message.
java.io.IOException - - If errors are encountered while setting the body of the message.
See Also:
createMessage( Message )

createMessage

public javax.mail.Message createMessage(javax.mail.Message currentMessage)
                                 throws javax.mail.MessagingException,
                                        java.io.IOException
Creates the appropriate type of message for forwarded mail. Fetches all the attachments and properties for the new message from the WriteFormParser and creates the new Message. This method also attaches any attachments that were originally part of the specified message to the new message being composed.

Parameters:
currentMessage - - The WebMailBean.currentMessage that is being forwarded.
Returns:
Message - The new message with all the message attributes including attachments set.
Throws:
javax.mail.MessagingException - - If any exceptions are encountered while creating the new message.
java.io.IOException - - If errors are encountered while setting the body of the message.

setMessageAttributes

private void setMessageAttributes()
                           throws javax.mail.MessagingException
Set the common attributes for the message. The common attributes set are from, to, cc, bcc, subject. The attributes are fetched from the HttpServetRequest and added to the new message. Simply calls the appropriate methods for setting the attributes.

Throws:
javax.mail.MessagingException - - If any exceptions are encountered while creating the new message.
See Also:
setFrom(), setTo(), setCc(), setBcc(), setSubject()

setFrom

private void setFrom()
              throws javax.mail.MessagingException
Set the from attribute of the new message.

Throws:
javax.mail.MessagingException - - If any exceptions are encountered while creating the new message.

setTo

private void setTo()
            throws javax.mail.MessagingException
Set the to attribute of the new message.

Throws:
javax.mail.MessagingException - - If any exceptions are encountered while creating the new message.

setCc

private void setCc()
            throws javax.mail.MessagingException
Set the cc attribute for the message.

Throws:
javax.mail.MessagingException - - If any exceptions are encountered while creating the new message.

setBcc

private void setBcc()
             throws javax.mail.MessagingException
Set the bcc attribute for the message.

Throws:
javax.mail.MessagingException - - If any exceptions are encountered while creating the new message.

setSubject

private void setSubject()
                 throws javax.mail.MessagingException
Set the subject attribute for the message.

Throws:
javax.mail.MessagingException - - If any exceptions are encountered while creating the new message.

setDate

private void setDate()
              throws javax.mail.MessagingException
Set the date attribute for the message.

Throws:
javax.mail.MessagingException - - If any exceptions are encountered while creating the new message.

setMessageBody

private void setMessageBody()
                     throws javax.mail.MessagingException,
                            java.io.IOException
Sets the various body parts for the message. If no attachments were included in the form post, or if no attachments were associated with the message to which this new message is a reply to, then a plain-text message will be created. Otherwise, a message with multiple body parts will be created.

Throws:
javax.mail.MessagingException - - If errors are encountered while setting the message body.
java.io.IOException - - If errors are encountered while fetching the content from the existing message.
See Also:
setBodyWithAttachments()

setForwardBody

private void setForwardBody(javax.mail.Message originalMessage)
                     throws javax.mail.MessagingException,
                            java.io.IOException
Set the body parts for the forwarded message. If the original message was a multipart message, then add all the original parts of the message to the new message. Also add any additional attachments added to the current new message.

Parameters:
originalMessage - - The message which is being forwarded.
Throws:
javax.mail.MessagingException - - If errors are encountered while adding the body to the reply message.
java.io.IOException - - If errors are encountered while fetching the content from the existing message.

setBodyWithAttachments

private void setBodyWithAttachments()
                             throws javax.mail.MessagingException,
                                    java.io.IOException
Set the body parts for the reply. If the original message was a multipart message, then add all the original parts of the message to the new message.

Throws:
javax.mail.MessagingException - - If errors are encountered while setting the body of the new message.
java.io.IOException

Rakesh API

Copyright © 2002-2005 - Rakesh Vidyadharan