Actualmente estoy desarrollando una aplicación que descarga archivos adjuntos de la cuenta de Gmail. Ahora mismo, recibí un error al descargar archivos adjuntos comprimidos. Pero, no todos, algunos puedo recuperarlo sin error. Aquí está el mensaje de excepción:JavaMail BaseEncode64 Error
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: yo era capaz de descargar el archivo adjunto a través de la interfaz web de Gmail.
Aquí está el fragmento:
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();
}
}
}
Alguien tiene idea de cómo solucionar este problema?
¿Alguna suerte con esto todavía? – William
no, aún no. Parece. nadie está interesado en el correo de Java :( – ariefbayu