In Java? Roundcube has no external API so it might be easier to connect directly from your Java application to the IMAP server to retrieve messages rather than trying to force a connection from one client (your Java application) to another (Roundcube) and then to the server.