title: IMAP client in Java: JavaMail API or Apache Commons Net?
body: <p>I have to implement an IMAP Client in Java.</p>
  
  <p>Which advantages has using the Apache Commons Net library? Does it make the implementation robust and more flexible?</p>
  
  <p>How do I have to handle return values, it always produces strings.</p>
  
  <p>For example:</p>
  
  <pre><code>public static void main(String[] args) throws Exception {
      IMAPClient client = new IMAPClient();
      client.connect(SERVER);
      client.login(USERNAME, PASSWORD);
      client.select("INBOX");
      client.fetch("1", "body[header]");
  }
  </code></pre>
  
  <p>and we can direct the output to string by</p>
  
  <pre><code>client.addProtocolCommandListener(new PrintCommandListener(System.out, true));
  </code></pre>
  
  <p>But how can I get a list of folders as folder instances instead of pure string output?</p>