code: public void processMail(Folder folder)
      {
          try {
              int iCount = folder.getMessageCount();
              if (iCount == 0)
                  return;
  
              String pattern = REPLY_STRING;
              Message[] messages = null;
              if (this.getProperty(PATTERN) == null)
              {
                  messages = folder.getMessages();
              }
              else
              {
                  pattern = this.getProperty(PATTERN);
                  SubjectTerm st = new SubjectTerm(pattern);
                  // Get some message references
                  messages = folder.search(st);
              }
              
              for (int iMsgnum = 0; iMsgnum < messages.length; iMsgnum++)
              {
                  Message message = messages[iMsgnum];
                  String strSubject = message.getSubject();
                  if (strSubject != null)
                      if ((pattern == null) || (strSubject.indexOf(pattern) != -1))
                          this.processThisMessage(message);
                  message.setFlag(Flags.Flag.SEEN, true);  // Archives the message (so I don't process it again)
              }
          } catch (Exception ex) {
              ex.printStackTrace();
          }
      }
docs: Go through all the mail and process the messages.
  @param folder The inbox folder.