public static void listMessagesFromInboxOfIMAPServer() {
    ImapClient client = new ImapClient();
    client.setHost("imap.gmail.com");
    client.setPort(993);
    client.setUsername("username");
    client.setPassword("password");
    client.setSecurityOptions(SecurityOptions.Auto);

    client.selectFolder(ImapFolderInfo.IN_BOX);
    ImapMessageInfoCollection coll = client.listMessages();
  }
  public static void fetchMessagesBySequenceNumber() {
    ImapClient client = new ImapClient();
    client.setHost("imap.gmail.com");
    client.setPort(993);
    client.setUsername("username");
    client.setPassword("password");
    client.setSecurityOptions(SecurityOptions.Auto);

    client.selectFolder(ImapFolderInfo.IN_BOX);
    ImapMessageInfoCollection coll = client.listMessages();

    for (int i = 1; i < coll.size(); i++) {
      MailMessage eml = client.fetchMessage(i); // use the sequence number to fetch messages
      eml.save(eml.getSubject() + ".eml", SaveOptions.getDefaultEml()); // save as EML
      eml.save(eml.getSubject() + ".msg", SaveOptions.getDefaultMsg()); // save as MSG
    }
  }