mirror of
https://github.com/moparisthebest/davmail
synced 2025-02-28 09:21:49 -05:00
Caldav: Handle non multipart mime message, improve debug log
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@415 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
cc1aa6ce32
commit
06f4b6075e
@ -25,6 +25,7 @@ import javax.mail.MessagingException;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
import javax.mail.internet.MimeMultipart;
|
||||
import javax.mail.internet.MimeBodyPart;
|
||||
import javax.mail.internet.MimePart;
|
||||
import java.io.*;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
@ -1145,17 +1146,26 @@ public class ExchangeSession {
|
||||
LOGGER.warn("Unable to get event at " + href + " status: " + status);
|
||||
}
|
||||
MimeMessage mimeMessage = new MimeMessage(null, method.getResponseBodyAsStream());
|
||||
MimeMultipart multiPart = (MimeMultipart) mimeMessage.getContent();
|
||||
MimeBodyPart bodyPart = null;
|
||||
for (int i = 0; i < multiPart.getCount(); i++) {
|
||||
String contentType = multiPart.getBodyPart(i).getContentType();
|
||||
if (contentType.startsWith("text/calendar") || contentType.startsWith("application/ics")) {
|
||||
bodyPart = (MimeBodyPart) multiPart.getBodyPart(i);
|
||||
Object mimeBody = mimeMessage.getContent();
|
||||
MimePart bodyPart = null;
|
||||
if (mimeBody instanceof MimeMultipart) {
|
||||
MimeMultipart multiPart = (MimeMultipart) mimeBody;
|
||||
for (int i = 0; i < multiPart.getCount(); i++) {
|
||||
String contentType = multiPart.getBodyPart(i).getContentType();
|
||||
if (contentType.startsWith("text/calendar") || contentType.startsWith("application/ics")) {
|
||||
bodyPart = (MimeBodyPart) multiPart.getBodyPart(i);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// no multipart, single body
|
||||
bodyPart = mimeMessage;
|
||||
}
|
||||
|
||||
if (bodyPart == null) {
|
||||
throw new IOException("Invalid message content");
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
mimeMessage.getDataHandler().writeTo(baos);
|
||||
baos.close();
|
||||
throw new IOException("Invalid calendar message content: " + new String(baos.toByteArray(), "UTF-8"));
|
||||
}
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
bodyPart.getDataHandler().writeTo(baos);
|
||||
|
Loading…
x
Reference in New Issue
Block a user