title: JavaMail - Issue with Multiple And Search Terms
body: <p>I would like to fetch recent, unread emails with a specific subject in a particular folder from my gmail account. I am using JavaMail API as below but it returns 0 results. However if I just use subjectTerm alone, I see results. Please let me know where am I going wrong. Thank you.</p>
  
  <p>Please note that I used  messages[0] below instead of looping through messages array for code simplicity to paste it here.</p>
  
  <pre><code>     public void openMailBox(String hostname, String username, String password, String folderName, String subject) throws MessagingException, GeneralSecurityException, IOException{
          props = System.getProperties();
          props.setProperty("mail.store.protocol", "imaps");
          props.setProperty("mail.imaps.host", "imap.gmail.com");
          props.setProperty("mail.imaps.port", "993");
          props.setProperty("mail.imaps.ssl.enable", "true");
          props.put("mail.imaps.ssl.socketFactory", new MailSSLSocketFactory()); 
          session = Session.getInstance(props);
          store = session.getStore();
          store.connect(username, password);
          folder = store.getFolder(folderName);
          folder.open(Folder.READ_ONLY);
          messages = folder.search(getSearchTerm(subject));
          if (messages[0].isMimeType("multipart/*")){
               Multipart multipart = (Multipart) messages[0].getContent();
               for(int i=0;i&lt;multipart.getCount();i++) {
                  BodyPart bodyPart = multipart.getBodyPart(0);
                  if (bodyPart.isMimeType("text/*")) {
                      msg = msg+bodyPart.getContent().toString();
                  }
               }
          }else{
              msg = messages[0].getContent().toString();
          }
          System.out.println(msg);
          folder.close(true);
          store.close();
      }
  
       public SearchTerm getSearchTerm(String subject){
           subjectTerm = new SubjectTerm(subject);
           unseenFlagTerm = new FlagTerm(new Flags(Flags.Flag.SEEN), false);
           recentFlagTerm; = new FlagTerm(new Flags(Flags.Flag.RECENT), true);
           return new AndTerm(subjectTerm, new AndTerm(unseenFlagTerm, recentFlagTerm));    
       } 
  }
  </code></pre>