JavaMail BaseEncode64 Error
From a list of the known limitations, bugs, issues of JavaMail:
Certain IMAP servers do not implement the IMAP Partial FETCH functionality properly. This problem typically manifests as corrupt email attachments when downloading large messages from the IMAP server. To workaround this server bug, set the "mail.imap.partialfetch" property to false. You'll have to set this property in the Properties object that you provide to your Session.
So you should just turn off partial fetch in imap session. For example:
Properties props = System.getProperties();
props.setProperty("mail.store.protocol", "imap");
props.setProperty("mail.imap.partialfetch", "false");
Session session = Session.getDefaultInstance(props, null);
Store store = session.getStore("imaps");
store.connect("imap.gmail.com", "<username>","<password>");
source: https://javaee.github.io/javamail/docs/api/com/sun/mail/imap/package-summary.html