Class DefaultMailReader

java.lang.Object
de.muehlencord.shared.network.mail.DefaultMailReader
All Implemented Interfaces:
MailReader
Direct Known Subclasses:
ImapMailReader

public abstract class DefaultMailReader extends Object implements MailReader
MailReader to connect and work with IMAP mailboxes. Also works with exchange servers.
Author:
Joern Muehlencord (joern@muehlencord.de)
  • Constructor Details

    • DefaultMailReader

      public DefaultMailReader(MailReaderConfiguration config)
      creates a new instance of the DefaultMailReader and updates needed values and settings
      Parameters:
      config - the configuration for the reader
  • Method Details

    • connect

      public abstract void connect() throws MailReaderConnectionException
      connects to the mailbox
      Specified by:
      connect in interface MailReader
      Throws:
      MailReaderConnectionException - if the connection cannot be established
    • disconnect

      public void disconnect()
      disconnects from mailbox
      Specified by:
      disconnect in interface MailReader
    • getDefaultFolder

      public String getDefaultFolder() throws MailReaderException
      returns the default folder
      Specified by:
      getDefaultFolder in interface MailReader
      Returns:
      the default folder
      Throws:
      MailReaderException - if the default folder cannot be found
    • getSubFolder

      public List<String> getSubFolder(javax.mail.Folder sourceFolder) throws MailReaderException
      returns the list of subfolders of the specified source folder
      Parameters:
      sourceFolder - the folder to return the folder list for
      Returns:
      the list of subfolders of the specified source folder
      Throws:
      MailReaderException - if the folder list cannot be retrieved
    • getDefaultSession

      protected javax.mail.Session getDefaultSession()
      returns the session object to use
      Returns:
      the session object to use
    • getStore

      protected javax.mail.Store getStore()
      Returns:
      the store
    • setStore

      protected void setStore(javax.mail.Store store)
      Parameters:
      store - the store to set
    • getConfiguration

      protected MailReaderConfiguration getConfiguration()
      returns the configuration object
      Returns:
      returns the configuration
    • getFolder

      public String getFolder(String folderPath) throws MailReaderException
      returns the folder, if folder path is a valid path to an existing folder
      Specified by:
      getFolder in interface MailReader
      Parameters:
      folderPath - the folder to return
      Returns:
      the folder, if folder path is a valid path to an existing folder
      Throws:
      MailReaderException - if the folder cannot be found
    • getSubFolder

      public List<String> getSubFolder(String sourceFolder) throws MailReaderException
      returns the list of subfolders of the specified source folder
      Specified by:
      getSubFolder in interface MailReader
      Parameters:
      sourceFolder - the folder to return the folder list for
      Returns:
      the list of subfolders of the specified source folder
      Throws:
      MailReaderException - if the folder list cannot be retrieved
    • getMessageCount

      public int getMessageCount(String sourceFolder) throws MailReaderException
      returns the message count for the given folder
      Specified by:
      getMessageCount in interface MailReader
      Parameters:
      sourceFolder - the folder to return the message count for
      Returns:
      the message count for the given folder
      Throws:
      MailReaderException - if the amount of messages cannot be determined
    • getMessages

      public List<MailMessage> getMessages(String sourceFolder) throws MailReaderException
      retrieves the list of messages stored in the given folder
      Specified by:
      getMessages in interface MailReader
      Parameters:
      sourceFolder - the folder to search return the emails for
      Returns:
      list of messages stored in the given folder
      Throws:
      MailReaderException - if the message list cannot be retrieved
    • getMessages

      public List<MailMessage> getMessages(String sourceFolder, int start, int end) throws MailReaderException
      retrieves the list of messages stored in the given folder
      Specified by:
      getMessages in interface MailReader
      Parameters:
      sourceFolder - the folder to search return the emails for
      start - the number of the first message
      end - the number of the last message
      Returns:
      list of messages stored in the given folder
      Throws:
      MailReaderException - if the message list cannot be retrieved
    • copyMessage

      public void copyMessage(MailMessage mm, String sourceFolder, String destFolder) throws MailReaderException
      copies the given message from the source folder to the destination folder
      Specified by:
      copyMessage in interface MailReader
      Parameters:
      mm - the message to copy
      sourceFolder - the folder the message currently resists in
      destFolder - the folder the message should be copied to
      Throws:
      MailReaderException - if the operation fails
    • moveMessage

      public void moveMessage(MailMessage mm, String sourceFolder, String destFolder) throws MailReaderException
      moves the given message from the source folder to the destination folder
      Specified by:
      moveMessage in interface MailReader
      Parameters:
      mm - the message to move
      sourceFolder - the folder the message currently resists in
      destFolder - the folder the message should be moved to
      Throws:
      MailReaderException - if the operation fails
    • setSeenFlag

      public void setSeenFlag(String folderName, MailMessage mm, boolean flagValue) throws MailReaderException
      marks the messages as seen
      Specified by:
      setSeenFlag in interface MailReader
      Parameters:
      folderName - the folder to search for the email
      mm - the message to mark as seen
      flagValue - if set to true, the seen flag is set; otherwise it is removed (unset)
      Throws:
      MailReaderException - if the flag cannot be set