Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.mrbook.mrpostman.another
Class AnotherMailSession  view AnotherMailSession download AnotherMailSession.java

java.lang.Object
  extended byorg.mrbook.mrpostman.WebMailSession
      extended byorg.mrbook.mrpostman.another.AnotherMailSession

public class AnotherMailSession
extends org.mrbook.mrpostman.WebMailSession


Nested Class Summary
(package private)  class AnotherMailSession.AttachmentIdentifier
          Helper class to store attachement info.
(package private)  class AnotherMailSession.MailIdentifier
          Helper class used to store message info.
(package private)  class AnotherMailSession.MailMessage
          Helper class to store Message content
 
Field Summary
private  boolean authenticated
           
private static java.lang.String[] AUTHORS
           
private static java.lang.String baseUrl
           
private  java.lang.String cb
           
private  com.sonalb.net.http.cookie.CookieJar cj
           
static boolean CREATE_SUMMARY_INFO
          Generate summary information for all actions.
static java.lang.String CVSID
           
static boolean DEBUG_PAGE_HTML
          Include full html for the retrieved pages.
static boolean FLAG_MSG_AS_READ
          Flag message as read after RETR
private static java.lang.String httpLoginPageURL
           
private  java.util.LinkedHashSet inboxPageUrls
           
private static java.lang.String inboxUrl
           
static int INVALID_ID
           
private static java.util.logging.Logger logger
           
static int LOGIN_OK
           
private static java.lang.String loginURL
           
private static java.lang.String logoutURL
           
private static org.mrbook.mrpostman.ModuleInfo MODULE_INFO
          Our hardcoded ModuleInfo data.
private static java.lang.String moveToReadUrl
           
private  java.util.LinkedList msgHashCodes
           
private static java.lang.String msgReadBaseUrl
           
(package private)  int numMessages
           
private static org.mrbook.mrpostman.ModuleOption[] OPTIONS
           
static int PAGE_STRUCTURE_CHANGED
           
private  java.util.LinkedList readMessages
           
private  AnotherMailDropSummary summaryInfo
           
static int SYSTEM_ERROR
           
private static java.lang.String UserAgent
           
 
Fields inherited from class org.mrbook.mrpostman.WebMailSession
WMS_LOGIN_FAILED, WMS_LOGIN_OK, WMS_MODULE_ERROR, WMS_PAGE_STRUCTURE
 
Constructor Summary
AnotherMailSession()
           
 
Method Summary
private  java.util.LinkedList checkForAttachments(int num)
          Determine the attachment info for any attached files Does this by reading the message and searching for the download href
private  java.lang.String createPostRequest(java.lang.String username, java.lang.String password)
          Build the another.com login service post parameters
private  java.lang.String createUniqueBoundaryValue(AnotherMailSession.MailMessage message)
          Create a unique boundary string
 boolean deleteMessage(int num)
          Delete the message with the supplied index number.
 org.mrbook.mrpostman.ModuleInfo getModuleInfo()
          Return the module info.
 java.lang.String getModuleName()
          Return the module name to the MrPostman controller
 java.lang.String[] getRecognizedExtensions()
          Return the list of email extensions supported by this module
 int getSizeOfMessage(int num)
          Return the size of the specified msg (indexed from 1!) This is a bit of a frig - we can't tell how big the message is without reading it.
 java.lang.String getUniqueMessageId(int num)
          Return the unique id for this message.
 int login(java.lang.String username, java.lang.String password, boolean secureLogin)
          Perform the login and retrieve the authentication cookie needed for subsequent requests.
private  void logout()
          Logout from Another.com's service
static void main(java.lang.String[] args)
          A debug main method
private  void moveMessagesToRead()
          Move all the messages that we have read into the 'READ' folder
 int numMessages()
          Return the number of messages in the inbox (read and unread - we can't tell the difference!) In order to facilitate simple message retrieval, we'll take this opportunity to read all the message urls and hashcodes (used to delete or move a message) into our list.
private  void outputAttachment(AnotherMailSession.MailMessage message, AnotherMailSession.AttachmentIdentifier attachment, java.io.PrintWriter pw)
          Output an attachment
 void outputLinesMessage(int num, java.io.PrintWriter pw, int numLines)
          Retrieve the email header and numLines of the email body.
 void outputMessage(int num, java.io.PrintWriter pw)
          Retrieve and output the message.
private  void outputMessageBody(AnotherMailSession.MailMessage message, java.io.PrintWriter pw)
          Output the email body
private  void outputMessageHeader(AnotherMailSession.MailMessage message, java.io.PrintWriter pw)
          Output the email header
private  AnotherMailSession.MailMessage parseMessageHeaderAndBody(int num, int numLines)
          Retrieve the msg specified by the supplied msg number (indexed from 1!) Strip the HTML tags and parse the message header.
 void quitSession()
          Handle the QUIT command.
private  void readMessageInfoForPage(int hiID)
          Retrieve all the message urls and hashcodes for this particular mailbox page.
private  void retrieveMessage(int num, java.io.PrintWriter pw, int numLines)
          Retrieve the msg specified by the supplied msg number (indexed from 1!) This will use other methods to verify if the mail has attachements, retrieve the body text (always HTML) and attachements.
 void setOption(java.lang.String optionName, java.lang.String value)
          Set a module option with a value from the preferences or from the GUI Currently understood options are listed in the MODULE_INFO specification above.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CVSID

public static final java.lang.String CVSID
See Also:
Constant Field Values

AUTHORS

private static final java.lang.String[] AUTHORS

OPTIONS

private static final org.mrbook.mrpostman.ModuleOption[] OPTIONS

MODULE_INFO

private static final org.mrbook.mrpostman.ModuleInfo MODULE_INFO
Our hardcoded ModuleInfo data.


logger

private static java.util.logging.Logger logger

UserAgent

private static final java.lang.String UserAgent
See Also:
Constant Field Values

baseUrl

private static final java.lang.String baseUrl
See Also:
Constant Field Values

httpLoginPageURL

private static final java.lang.String httpLoginPageURL
See Also:
Constant Field Values

loginURL

private static java.lang.String loginURL

logoutURL

private static java.lang.String logoutURL

msgReadBaseUrl

private static java.lang.String msgReadBaseUrl

inboxUrl

private static java.lang.String inboxUrl

moveToReadUrl

private static java.lang.String moveToReadUrl

INVALID_ID

public static int INVALID_ID

PAGE_STRUCTURE_CHANGED

public static int PAGE_STRUCTURE_CHANGED

LOGIN_OK

public static int LOGIN_OK

SYSTEM_ERROR

public static int SYSTEM_ERROR

FLAG_MSG_AS_READ

public static final boolean FLAG_MSG_AS_READ
Flag message as read after RETR

See Also:
Constant Field Values

DEBUG_PAGE_HTML

public static final boolean DEBUG_PAGE_HTML
Include full html for the retrieved pages. Useful if the page structure changes.

See Also:
Constant Field Values

CREATE_SUMMARY_INFO

public static final boolean CREATE_SUMMARY_INFO
Generate summary information for all actions. If this is enabled, a maildrop summary will be output to the log.

See Also:
Constant Field Values

inboxPageUrls

private java.util.LinkedHashSet inboxPageUrls

msgHashCodes

private java.util.LinkedList msgHashCodes

readMessages

private java.util.LinkedList readMessages

authenticated

private boolean authenticated

numMessages

int numMessages

cb

private java.lang.String cb

cj

private com.sonalb.net.http.cookie.CookieJar cj

summaryInfo

private AnotherMailDropSummary summaryInfo
Constructor Detail

AnotherMailSession

public AnotherMailSession()
Method Detail

login

public int login(java.lang.String username,
                 java.lang.String password,
                 boolean secureLogin)
Perform the login and retrieve the authentication cookie needed for subsequent requests. We'll do this by: 1 Retrieving the www.another.com main page (to create a session cookie with this service) 2 Posting a login block 3 Verifying the page is not an error page


createPostRequest

private java.lang.String createPostRequest(java.lang.String username,
                                           java.lang.String password)
Build the another.com login service post parameters


logout

private void logout()
             throws org.mrbook.mrpostman.MailSessionException
Logout from Another.com's service


numMessages

public int numMessages()
Return the number of messages in the inbox (read and unread - we can't tell the difference!) In order to facilitate simple message retrieval, we'll take this opportunity to read all the message urls and hashcodes (used to delete or move a message) into our list. As the inbox will be spread across multiple pages, we'll have to do this once for each page. We already collected the page urls in the login() method :)


readMessageInfoForPage

private void readMessageInfoForPage(int hiID)
                             throws org.mrbook.mrpostman.MailSessionException
Retrieve all the message urls and hashcodes for this particular mailbox page.


outputMessage

public void outputMessage(int num,
                          java.io.PrintWriter pw)
Retrieve and output the message. If the option is enabled, move the message into the READ folder. This is called by the RETR command.


outputLinesMessage

public void outputLinesMessage(int num,
                               java.io.PrintWriter pw,
                               int numLines)
Retrieve the email header and numLines of the email body. The message will not be marked as read. This is called by the TOP command.


retrieveMessage

private void retrieveMessage(int num,
                             java.io.PrintWriter pw,
                             int numLines)
                      throws org.mrbook.mrpostman.MailSessionException
Retrieve the msg specified by the supplied msg number (indexed from 1!) This will use other methods to verify if the mail has attachements, retrieve the body text (always HTML) and attachements.


checkForAttachments

private java.util.LinkedList checkForAttachments(int num)
                                          throws org.mrbook.mrpostman.MailSessionException
Determine the attachment info for any attached files Does this by reading the message and searching for the download href


parseMessageHeaderAndBody

private AnotherMailSession.MailMessage parseMessageHeaderAndBody(int num,
                                                                 int numLines)
                                                          throws org.mrbook.mrpostman.MailSessionException
Retrieve the msg specified by the supplied msg number (indexed from 1!) Strip the HTML tags and parse the message header. Output the message body to the supplied PrintWriter if numLines != -1 then limit the number of body lines to be this value (used for the TOP command) Assumptions: the msg will be surrounded by 'pre' and '/pre' tags.


outputMessageHeader

private void outputMessageHeader(AnotherMailSession.MailMessage message,
                                 java.io.PrintWriter pw)
Output the email header


createUniqueBoundaryValue

private java.lang.String createUniqueBoundaryValue(AnotherMailSession.MailMessage message)
Create a unique boundary string


outputMessageBody

private void outputMessageBody(AnotherMailSession.MailMessage message,
                               java.io.PrintWriter pw)
Output the email body


outputAttachment

private void outputAttachment(AnotherMailSession.MailMessage message,
                              AnotherMailSession.AttachmentIdentifier attachment,
                              java.io.PrintWriter pw)
                       throws org.mrbook.mrpostman.MailSessionException
Output an attachment


getSizeOfMessage

public int getSizeOfMessage(int num)
Return the size of the specified msg (indexed from 1!) This is a bit of a frig - we can't tell how big the message is without reading it. So we won't actually bother! We'll make up a number and hope the client doesn't mind! Note: We can't use the figure specified by another.com as that doesn't include attachments and isn't very accurate anyhow.


getModuleName

public java.lang.String getModuleName()
Return the module name to the MrPostman controller


getRecognizedExtensions

public java.lang.String[] getRecognizedExtensions()
Return the list of email extensions supported by this module


deleteMessage

public boolean deleteMessage(int num)
Delete the message with the supplied index number.


quitSession

public void quitSession()
Handle the QUIT command. We need to move all our read messages to our READ folder and logout. NOTE: We can't do this after each RETR as that would adjust all the message ids!


moveMessagesToRead

private void moveMessagesToRead()
                         throws org.mrbook.mrpostman.MailSessionException
Move all the messages that we have read into the 'READ' folder


getUniqueMessageId

public java.lang.String getUniqueMessageId(int num)
                                    throws org.mrbook.mrpostman.MailSessionException
Return the unique id for this message. This is the another.com hashcode value


getModuleInfo

public org.mrbook.mrpostman.ModuleInfo getModuleInfo()
Return the module info.


setOption

public void setOption(java.lang.String optionName,
                      java.lang.String value)
Set a module option with a value from the preferences or from the GUI Currently understood options are listed in the MODULE_INFO specification above.


main

public static void main(java.lang.String[] args)
A debug main method