Attualmente sto sviluppando un'applicazione che scarica l'allegato dall'account Gmail. In questo momento, ho ricevuto un errore ogni volta che scaricavo un allegato zippato. Ma non tutti, alcuni posso recuperarlo senza errori. Ecco il messaggio di eccezione:JavaMail BaseEncode64 Errore
Exception in thread "main" com.sun.mail.util.DecodingException: BASE64Decoder: Error in encoded stream: needed 4 valid base64 characters but only got 1 before EOF, the 10 most recent characters were: "Q3w5ilxj2P"
FYI: Sono riuscito a scaricare l'allegato tramite l'interfaccia web di Gmail.
Ecco il frammento:
Multipart multipart = (Multipart) message.getContent();
for (int i = 0; i < multipart.getCount(); i++) {
BodyPart bodyPart = multipart.getBodyPart(i);
if (bodyPart.getFileName().toLowerCase().endsWith("zip") ||
bodyPart.getFileName().toLowerCase().endsWith("rar")) {
InputStream is = bodyPart.getInputStream();
File f = new File("/tmp/" + bodyPart.getFileName());
FileOutputStream fos = new FileOutputStream(f);
byte[] buf = new byte[bodyPart.getSize()];
int bytesRead;
while ((bytesRead = is.read(buf)) != -1) {
fos.write(buf, 0, bytesRead);
}
fos.close();
}
}
}
Qualcuno ha idea, come risolvere questo problema?
Hai ancora fortuna? – William
no, non ancora. Sembra come. nessuno è interessato a java mail :( – ariefbayu