Methods Summary |
---|
private void | displayMessageHeaders(javax.mail.Message msg, java.io.PrintWriter out)
try {
out.println("<b>Date:</b> " + msg.getSentDate() + "<br>");
Address[] fr = msg.getFrom();
if (fr != null) {
boolean tf = true;
out.print("<b>From:</b> ");
for (int i = 0; i < fr.length; i++) {
out.print(((tf) ? " " : ", ") + getDisplayAddress(fr[i]));
tf = false;
}
out.println("<br>");
}
Address[] to = msg.getRecipients(Message.RecipientType.TO);
if (to != null) {
boolean tf = true;
out.print("<b>To:</b> ");
for (int i = 0; i < to.length; i++) {
out.print(((tf) ? " " : ", ") + getDisplayAddress(to[i]));
tf = false;
}
out.println("<br>");
}
Address[] cc = msg.getRecipients(Message.RecipientType.CC);
if (cc != null) {
boolean cf = true;
out.print("<b>CC:</b> ");
for (int i = 0; i < cc.length; i++) {
out.print(((cf) ? " " : ", ") + getDisplayAddress(cc[i]));
cf = false;
}
out.println("<br>");
}
out.print("<b>Subject:</b> " +
((msg.getSubject() !=null) ? msg.getSubject() : "") +
"<br>");
} catch (MessagingException mex) {
out.println(msg.toString());
}
|
public void | doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)The doGet will execute only when the Grizzly
JavaMailAsyncFilter determines this servlet can execute.
The JavaMailAsyncFilter will allow the execution of this
Servlet only if a new email message arrive in the remote email account.
PrintWriter out = response.getWriter();
try{
if ( messages != null) {
out.println("<html>");
out.println("<HEAD><TITLE>Async JavaMail Servlet</TITLE></HEAD>");
out.println("<BODY bgcolor=\"#ccccff\">");
out.print("<center><font face=\"Arial,Helvetica\" ");
out.println("font size=\"+3\"><b>");
out.println("You have " + messages.length + " messages in folder "
+ "inbox</b></font></center><p>");
for (int i=0; i < messages.length; i++){
try {
Message msg = messages[i];
displayMessageHeaders(msg, out);
try{
Object o = msg.getContent();
out.println("<pre>");
out.println((String)o);
out.println("</pre>");
} catch (NullPointerException ex){
; //If the message isn't having body
}
} catch (MessagingException mex) {
out.println(mex.toString());
}
}
}
out.println("</BODY></html>");
out.close();
} catch (Throwable t){
t.printStackTrace();
}
|
private java.lang.String | getDisplayAddress(javax.mail.Address a)
String pers = null;
String addr = null;
if (a instanceof InternetAddress &&
((pers = ((InternetAddress)a).getPersonal()) != null)) {
addr = pers + " "+"<"+((InternetAddress)a).getAddress()+">";
} else
addr = a.toString();
return addr;
|
public java.lang.String | getMailServer()
return mailServer;
|
public java.lang.String | getMailServerPort()
return mailServerPort;
|
public java.lang.String | getPassword()
return password;
|
public java.lang.String | getUserName()
return username;
|
public boolean | handleEvent(org.glassfish.grizzly.async.javamail.JavaMailAsyncFilterEvent event)The JavaMailAsyncFilter will invoke that method after
fetching the email from the remote account. This method will return
true if the messages retrived aren't new or no new message
has been found. Returning true means the Servlet shouldn't
yet be executed. Returning false will fire the execution
of this Servlet.
messages = event.getMessages();
if ( messages == null || messages.length == 0){
return true;
} else {
return false;
}
|
public void | init(javax.servlet.ServletConfig config)Init this Servlet by registering it with the
JavaMailAsyncFilter .
username = config.getInitParameter("username");
password = config.getInitParameter("password");
mailServer = config.getInitParameter("mailServer");
mailServerPort = config.getInitParameter("mailServerPort");
JavaMailAsyncFilter.register(
config.getInitParameter("contextPath"), this);
|