Class MailFolder

java.lang.Object
com.netlang.mail.MailFolder
Direct Known Subclasses:
Mailbox

public class MailFolder extends Object
This class represent a folder in a POP3 server.
  • Method Details

    • permanentlyRemoveDeleted

      public void permanentlyRemoveDeleted() throws javax.mail.MessagingException
      Remove deleted messages
      Throws:
      javax.mail.MessagingException
    • openForUpdate

      public void openForUpdate() throws javax.mail.MessagingException
      Open the folder for updates
      Throws:
      javax.mail.MessagingException
    • close

      public void close()
      Close mailbox
    • getName

      public String getName()
      Return the name of the folder
      Returns:
      the name of this folder.
    • getFullName

      public String getFullName()
      The full name of this folder
      Returns:
      the full name
    • getFolder

      public javax.mail.Folder getFolder()
      Get the internal JavaMail folder
      Returns:
      the folder
    • getMessageCount

      public int getMessageCount() throws Exception
      Get the message count
      Returns:
      the number of messages in the folder
      Throws:
      Exception
    • getUnreadMessageCount

      public int getUnreadMessageCount() throws Exception
      Get the unread message count
      Returns:
      the number of unread messages in the folder
      Throws:
      Exception
    • getDeletedMessageCount

      public int getDeletedMessageCount() throws Exception
      Get the deleted message count
      Returns:
      the number of deleted messages in the folder
      Throws:
      Exception
    • getNewMessageCount

      public int getNewMessageCount() throws Exception
      Get number of new messages
      Returns:
      Throws:
      Exception
    • getMessage

      public MailMessage getMessage(int index) throws Exception
      Get the message at the specified index
      Parameters:
      index - the one based index of the message in the folder
      Returns:
      the message
      Throws:
      Exception
    • getMessages

      public MailMessage[] getMessages() throws Exception
      Get all messages in this folder
      Returns:
      array with messages.
      Throws:
      Exception
    • getMessages

      public MailMessage[] getMessages(int start, int end) throws Exception
      Get the messages in this folder for message numbers ranging from start through end, both start and end inclusive.
      Returns:
      array with messages.
      Throws:
      Exception
    • getLastMessages

      public List<MailMessage> getLastMessages(int maxcount) throws Exception
      Returns the latest messages in the folder.
      Throws:
      Exception
    • getUnreadMessages

      public List<MailMessage> getUnreadMessages() throws Exception
      Returns all unread messages in this folder.
      Returns:
      all unread mails.
      Throws:
      Exception
    • getDeletedMessages

      public List<MailMessage> getDeletedMessages() throws Exception
      Get the unread messages
      Throws:
      Exception
    • searchMessages

      public List<MailMessage> searchMessages(Date after, Date before) throws Exception
      Search for the messages. Wildcard * are supported. A parameter value of null is the same as * which will match all messages
      Parameters:
      from - the from field search term
      subject - search for something in the subject
      message - the search term for the message body
      attachement - search for an attachment name
      Returns:
      the search result
      Throws:
      Exception
    • searchMessages

      public List<MailMessage> searchMessages(String text) throws Exception
      Search for the messages
      Parameters:
      text - any text that will be searched for in subject and body
      Returns:
      search result
      Throws:
      Exception
    • searchMessages

      public List<MailMessage> searchMessages(String from, String subject, String body, Date after, Date before, int answerOption, String to, String cc, String bcc) throws Exception
      Search for the messages. Wildcard * are supported. A parameter value of null is the same as * which will match all messages
      Parameters:
      from - the from field search term
      subject - search for something in the subject
      message - the search term for the message body
      attachement - search for an attachment name
      Returns:
      the search result
      Throws:
      Exception
    • searchMessagesInternal

      public javax.mail.Message[] searchMessagesInternal(javax.mail.search.SearchTerm term) throws Exception
      Search for the messages
      Parameters:
      term - the term to search for Example SearchTerm term = new AndTerm(new SubjectTerm("hello"), new BodyTerm("hello"));
      Returns:
      Throws:
      Exception
    • searchMessages

      public List<MailMessage> searchMessages(javax.mail.search.SearchTerm term) throws Exception
      Search for the messages
      Parameters:
      term - the term to search for Example SearchTerm term = new AndTerm(new SubjectTerm("hello"), new BodyTerm("hello"));
      Returns:
      Throws:
      Exception
    • getFolder

      public MailFolder getFolder(String name) throws Exception
      Get a mail folder
      Parameters:
      name - the name of the folder
      writeAccess - set this to true if write access is required
      Returns:
      the mailfolder
      Throws:
      Exception
    • getFolder

      public MailFolder getFolder(String name, boolean createIfNotExists) throws Exception
      Throws:
      Exception
    • getFolderNames

      public String[] getFolderNames() throws Exception
      Returns a list with mailfolders
      Returns:
      Throws:
      Exception
    • getFolders

      public MailFolder[] getFolders() throws Exception
      Returns a list with mailfolders
      Returns:
      Throws:
      Exception
    • getFolders

      public MailFolder[] getFolders(String pattern) throws Exception
      List the folders under this folder
      Parameters:
      pattern - return only folders matching the pattern
       As an example, given the folder hierarchy: 
       Personal/
          Finance/
            Stocks
            Bonus
            StockOptions
        Jokes
       getFolders("*") on "Personal" will return the whole hierarchy. 
       getFolders("%") on "Personal" will return "Finance" and "Jokes". 
       getFolders("Jokes") on "Personal" will return "Jokes".
       getFolders("Stock*") on "Finance" will return "Stocks" and "StockOptions".      
       
      Returns:
      Throws:
      Exception
    • createFolderContainer

      public MailFolder createFolderContainer(String name) throws Exception
      Create a folder containing other folders
      Parameters:
      name - the name of the folder to create
      Returns:
      Throws:
      Exception
    • createFolder

      public MailFolder createFolder(String name) throws Exception
      Create a folder for messages
      Parameters:
      name - the name of the folder to create
      Returns:
      Throws:
      Exception
    • hasMore

      public boolean hasMore()
      Return true if there are more mail to read The first(..) method must be called before this value is valid
      Returns:
    • first

      public MailMessage first(String from, String subject, String message, boolean removeAfterRead) throws Exception
      Search mailbox folder and position to first element
      Parameters:
      from -
      subject -
      message -
      attachement -
      removeAfterRead -
      Returns:
      Throws:
      Exception
    • next

      public MailMessage next() throws Exception
      Get next mail
      Returns:
      Throws:
      Exception
    • moveMessage

      public void moveMessage(MailMessage msg) throws Exception
      Throws:
      Exception
    • moveUnreadMessages

      public void moveUnreadMessages(MailFolder to) throws com.net4z.APIException
      Throws:
      com.net4z.APIException
    • moveAllMessages

      public void moveAllMessages(MailFolder to) throws com.net4z.APIException
      Throws:
      com.net4z.APIException
    • moveMessages

      public void moveMessages(MailFolder to, Date after, Date before) throws com.net4z.APIException
      Throws:
      com.net4z.APIException
    • moveMessages

      public void moveMessages(MailFolder to, String from, String subject, String body) throws com.net4z.APIException
      Throws:
      com.net4z.APIException
    • deleteUnreadMessages

      public void deleteUnreadMessages() throws com.net4z.APIException
      Throws:
      com.net4z.APIException
    • deleteAllMessages

      public void deleteAllMessages() throws com.net4z.APIException
      Throws:
      com.net4z.APIException
    • deleteMessages

      public void deleteMessages(Date after, Date before) throws com.net4z.APIException
      Throws:
      com.net4z.APIException
    • deleteMessages

      public void deleteMessages(String from, String subject, String body) throws com.net4z.APIException
      Throws:
      com.net4z.APIException