title: Get only unseen mails from Gmail - imap
body: <p>I have this code:</p>
  <pre><code>Properties properties = new Properties();
  properties.setProperty(&quot;mail.store.protocol&quot;, &quot;imaps&quot;);
      
  try(Store store = Session.getDefaultInstance(properties, null).getStore(&quot;imaps&quot;)){
  
      store.connect(&quot;imap.gmail.com&quot;, 993, username, password);
  
      Folder inboxFolder = store.getFolder(&quot;INBOX&quot;);
      
      try(inboxFolder){
      
          //open folder
          inboxFolder.open(Folder.READ_WRITE);
          
          //get messages
          Message[] messages = inboxFolder.search(new FlagTerm(new Flags(Flags.Flag.RECENT), true));
          
          Arrays.stream(messages)
              .forEach(message -&gt; {
              
                  try{
                  
                      System.out.println(message.getSubject());
                      
                  }catch(Exception e){ e.printStackTrace(); }
                  
              };  
                  
      }
  
  }catch(Exception e){
      e.printStackTrace();
  }
  </code></pre>
  <p>I try to read all unseen mails from INBOX from GMail.</p>
  <p>But in console is printed nothing and <code>messages.length</code> is 0.</p>
  <p>How I can read just unseen mails?</p>
  <p>P.S.: I just printed the flag of all messages(doesn't matter the flag) and I realized the unseen messages has no flag. This is how it is supposed to be?</p>
  <p>P.S.: I found out.</p>
  <pre><code>Message[] messages = inboxFolder.search(
      new FlagTerm(new Flags(Flags.Flag.SEEN), false)
  );
  </code></pre>
  <p>With this one works: <code>new FlagTerm(new Flags(Flags.Flag.SEEN), false)</code></p>