public class JavaMailServlet extends HttpServlet implements SingleThreadModel
It allows the user to login to an IMAP/Pop store, list all the messages in the INBOX folder, view selected messages, compose and send a message, and logout.
For more information on servlets, see http://java.sun.com/products/java-server/servlets/index.html
Modifier and Type | Field and Description |
---|---|
(package private) String |
attachmentBackColour_
The string representing the html table background colour for
message attachments (ie #000066).
|
(package private) String |
bodyBackColour_
The string representing the html page background colour (ie #000066).
|
private static String |
BUILD_TAG
Build String.
|
private static Calendar |
calendar_ |
(package private) String |
composeBody_ |
private String |
composeBodyHeader_ |
(package private) String |
currTime
A holder of the current time.
|
private static String |
DEFAULT_HEAD_GRAPHIC
The DEFAULT name of the graphic that gets used at the top of all
the pages if one is not specified at runtime.
|
private static String |
DEFAULT_HOME_PAGE
The default html/jsp page to use as the home login page for this servlet.
|
private static String |
DEFAULT_HOME_URL
The default URL to use as the home login page for this servlet.
|
private static String |
DEFAULT_LOG_FILE
Log File Name.
|
private static int |
DEFAULT_MESSAGES_PER_PAGE
The default number of mail messages to show per page .
|
private static String |
DEFAULT_PROTOCOL
The default mail protocal to use.
|
private static String |
DEFAULT_SERVLET_PATHNAME
The default servlet pathname to use in the URL to call this mail servlet.
|
private String |
folderViewBodyClose_ |
(package private) String |
folderViewHead
The html header string (<head>) that is included on all folder view
pages.
|
(package private) String |
folderViewTitle_
The title to put on the folder view page.
|
private static String |
headGraphicName_
The name of the graphic that gets used at the top of all
the pages.
|
private static String |
homePage_
The string representing the path for the home page to serve for webmail.
|
private static String |
homeUrl_
The current URL to use as the home login page for this servlet.
|
(package private) String |
htmlMessageLinkColour_
The string representing the html link colour (ie #000066).
|
(package private) String |
linkColour_
The string representing the html link colour (ie #000066).
|
private static Log |
log
The debug logger.
|
private static String |
mailServerHostName_
The current mail server being used.
|
(package private) String |
mailToAddr_
the class copy of the next mailto address used in the compose form.
|
(package private) String |
mbox
The name of the Mailbox to Display/use.
|
(package private) String |
messageBackColour_
The string representing the html table background colour for the actual
message text (ie #000066).
|
(package private) String |
messageHeadBackColour_
The string representing the html table background colour for
message headers (ie #000066).
|
(package private) String |
messageTextColour_
The string representing the html colour for the message text(ie #000066).
|
(package private) String |
newMessageBackColour
The string representing the html table background colour for
NEW messages (ie #000066).
|
(package private) Properties |
props |
(package private) String |
replySubject_
the class copy of the next subject used in the compose form.
|
(package private) String |
rowColour_
The string representing the html table background colour for
NEW messages (ie #000066).
|
private static String |
SERVLET_VERSION
Version String.
|
private static String |
servletName_
The string representing the URL path to this servlet.
|
private static String |
servletUrl_
The string representing the FULL URL path to this servlet.
|
private static String |
SYSTEM_FILE_SEPERATOR |
private String |
tableBackColour_
The string representing the html table background colour (ie #000066).
|
(package private) String |
tableTextColour
The string representing the html text colour (ie #000066).
|
(package private) String |
textColour_
The string representing the html text colour (ie #000066).
|
private static String |
webServerHostName_
This servers name.
|
Constructor and Description |
---|
JavaMailServlet() |
Modifier and Type | Method and Description |
---|---|
private String |
buildFolderTableHTML(StringBuffer reqUrl,
URLName urlName,
int msgCount,
int newMsgCount)
A method to display messages in the folder.
|
private void |
compose(MailUserData mud,
HttpServletResponse res,
ServletOutputStream out)
This method handles the request when the user hits the Compose link.
|
void |
destroy()
Override to close the Log
|
private void |
displayCommandBarHtml(HttpServletRequest req,
ServletOutputStream out)
This method displays the URLs for the available commands in a html.
|
private void |
displayHeaderTableHtml(MailUserData mud,
HttpServletRequest req,
ServletOutputStream out,
int messagesPerPage,
int messageStartPage)
This method displays the URL's for the available commands and
the INBOX headerlist.
|
private void |
displayInboxHtml(MailUserData mud,
HttpServletRequest req,
ServletOutputStream out,
int numShowing,
int pageNum)
This method displays the INBOX headerlist.
|
private void |
displayMessage(MailUserData mud,
HttpServletRequest req,
ServletOutputStream out,
int msgNum)
The main method to display a message.
|
private void |
displayMessageHeaders(MailUserData mud,
Message msg,
ServletOutputStream out)
This is a utility method that pretty-prints the message headers for message
that is being displayed.
|
private void |
displayPart(MailUserData mud,
int msgNum,
int partNum,
ServletOutputStream out,
HttpServletResponse res)
This method gets the stream from for a given msg part and pushes it out to
the browser with the correct content type.
|
private void |
displayPart(MailUserData mud,
int msgNum,
Part part,
int partNum,
HttpServletRequest req,
ServletOutputStream out)
This method displays a message part.
|
void |
doGet(HttpServletRequest req,
HttpServletResponse res)
This method handles the GET requests for the client.
|
void |
doPost(HttpServletRequest req,
HttpServletResponse res)
This method handles the "POST" submission from two forms: the login form
and the message compose form.
|
private String |
getComposeBodyHeader()
A helper method that returns the Body tag with any predefined body header
info.
|
private String |
getComposeFormHtml()
Returns the Latest updated Compose Form HTML String.
|
private String |
getDisplayAddress(Address a)
Gets the DisplayAddress attribute of the JavaMailServlet object
|
private String |
getFolderListBodyHeader()
A helper method that returns the Body tag with any predefined body header
info.
|
private String |
getFolderViewBodyClose()
A helper method that returns the ENDING Body tag with any predefined closing
body info.
|
private String |
getFolderViewBodyHeader(String folderName)
A helper method that returns the Body tag with any predefined body header
info.
|
private String |
getMessageViewBodyClose()
A helper method that returns the ENDING Body tag with any predefined closing
body info.
|
private String |
getMessageViewBodyHeader(String folderName)
A helper method that returns the Body tag with any predefined body header
info.
|
private MailUserData |
getMUD(HttpSession ses)
Utility method for retrieving the MailUserData from the HttpSession
and return it.
|
private String |
getSelectedNums()
Gets the SelectedNums attribute of the JavaMailServlet object
|
String |
getServletInfo()
Gets the ServletInfo attribute of the JavaMailServlet object
|
void |
init(ServletConfig config)
The one time servlet init stuff goes here.
|
private void |
replyCompose(MailUserData mud,
HttpServletResponse res,
ServletOutputStream out,
String replyToAddr,
String replySubject)
This method handles the request when the user hits the ReplyTo link.
|
private void |
send(HttpServletRequest req,
HttpServletResponse res,
ServletOutputStream out,
HttpSession ssn)
This method processes the send request from the compose form
|
static String |
tokenReplace(String sentence,
String token,
String replacement)
A simple String token replacement routine.
|
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, service
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletName, init, log, log
private static final String SYSTEM_FILE_SEPERATOR
String bodyBackColour_
String linkColour_
String htmlMessageLinkColour_
String textColour_
String messageTextColour_
String rowColour_
private String tableBackColour_
String newMessageBackColour
String messageBackColour_
String messageHeadBackColour_
String attachmentBackColour_
String tableTextColour
String folderViewTitle_
String folderViewHead
private static final String DEFAULT_HEAD_GRAPHIC
private static final String DEFAULT_PROTOCOL
private static final int DEFAULT_MESSAGES_PER_PAGE
private static final String DEFAULT_SERVLET_PATHNAME
private static final String DEFAULT_HOME_PAGE
private static final String DEFAULT_HOME_URL
private static final String SERVLET_VERSION
private static final String BUILD_TAG
private static final String DEFAULT_LOG_FILE
private static String homeUrl_
private static String headGraphicName_
private static String mailServerHostName_
private static String webServerHostName_
private static String servletName_
private static String servletUrl_
private static String homePage_
String mailToAddr_
String replySubject_
String composeBody_
Properties props
private String composeBodyHeader_
private String folderViewBodyClose_
public JavaMailServlet()
public String getServletInfo()
getServletInfo
in interface Servlet
getServletInfo
in class GenericServlet
public void init(ServletConfig config) throws ServletException
init
in interface Servlet
init
in class GenericServlet
ServletException
public void destroy()
destroy
in interface Servlet
destroy
in class GenericServlet
public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
hostname
, username
, and password
.
The send
parameter denotes that the method is processing the
compose form submission.doPost
in class HttpServlet
req
- Description of Parameterres
- Description of ParameterServletException
- Description of ExceptionIOException
- Description of Exceptionpublic void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
doGet
in class HttpServlet
req
- Description of Parameterres
- Description of ParameterServletException
- Description of ExceptionIOException
- Description of Exceptionpublic static String tokenReplace(String sentence, String token, String replacement)
sentence
- The String to perform the token replacement ontoken
- the token String to seartch for and replacereplacement
- the tokens replacement valueprivate String getComposeBodyHeader()
private String getFolderListBodyHeader()
private String getFolderViewBodyHeader(String folderName)
folderName
- Description of Parameterprivate String getMessageViewBodyHeader(String folderName)
folderName
- Description of Parameterprivate String getFolderViewBodyClose()
private String getMessageViewBodyClose()
private String getSelectedNums()
private String getDisplayAddress(Address a)
a
- Description of Parameterprivate MailUserData getMUD(HttpSession ses) throws IOException
ses
- The Session to retrieve the MUD fromIOException
- Description of Exceptionprivate String buildFolderTableHTML(StringBuffer reqUrl, URLName urlName, int msgCount, int newMsgCount)
reqUrl
- Description of ParameterurlName
- Description of ParametermsgCount
- Description of ParameternewMsgCount
- Description of Parameterprivate void displayMessage(MailUserData mud, HttpServletRequest req, ServletOutputStream out, int msgNum) throws IOException
mud
- Description of Parameterreq
- Description of Parameterout
- Description of ParametermsgNum
- The Message number to display.IOException
- Description of Exceptionprivate void displayPart(MailUserData mud, int msgNum, Part part, int partNum, HttpServletRequest req, ServletOutputStream out) throws IOException
text/plain
content parts
are displayed inline. For all other parts, a URL is generated and displayed;
clicking on the URL brings up the part in a separate page.mud
- Description of ParametermsgNum
- Description of Parameterpart
- Description of ParameterpartNum
- Description of Parameterreq
- Description of Parameterout
- Description of ParameterIOException
- Description of Exceptionprivate void displayPart(MailUserData mud, int msgNum, int partNum, ServletOutputStream out, HttpServletResponse res) throws IOException
mud
- Description of ParametermsgNum
- Description of ParameterpartNum
- Description of Parameterout
- Description of Parameterres
- Description of ParameterIOException
- Description of Exceptionprivate void displayMessageHeaders(MailUserData mud, Message msg, ServletOutputStream out) throws IOException
mud
- The Mail User Data Object to usemsg
- The message to display the headers for.out
- The ServletOutputStreamIOException
- Description of Exceptionprivate void displayInboxHtml(MailUserData mud, HttpServletRequest req, ServletOutputStream out, int numShowing, int pageNum) throws IOException
mud
- The Mail User Data object to get the data from.req
- Description of Parameterout
- Description of ParameternumShowing
- The number of msgs to show per page.pageNum
- The page to display.IOException
- Description of Exceptionprivate void displayCommandBarHtml(HttpServletRequest req, ServletOutputStream out) throws IOException
req
- Description of Parameterout
- Description of ParameterIOException
- Description of Exceptionprivate void displayHeaderTableHtml(MailUserData mud, HttpServletRequest req, ServletOutputStream out, int messagesPerPage, int messageStartPage) throws IOException
mud
- The Mail User data for the logged in userreq
- This Sessions current requestout
- The req out streamIOException
- Description of Exceptionprivate void replyCompose(MailUserData mud, HttpServletResponse res, ServletOutputStream out, String replyToAddr, String replySubject) throws IOException
mud
- Description of Parameterres
- Description of Parameterout
- Description of ParameterreplyToAddr
- The email addr to prload into the to fieldIOException
- Description of Exceptionprivate String getComposeFormHtml()
private void compose(MailUserData mud, HttpServletResponse res, ServletOutputStream out) throws IOException
mud
- Description of Parameterres
- Description of Parameterout
- Description of ParameterIOException
- Description of Exceptionprivate void send(HttpServletRequest req, HttpServletResponse res, ServletOutputStream out, HttpSession ssn) throws IOException
req
- Description of Parameterres
- Description of Parameterout
- Description of Parameterssn
- Description of ParameterIOException
- Description of ExceptionWebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses