SMTP: adjust workaround for misconfigured Exchange server that return 406 Not Acceptable on draft message creation, look inside multipart messages

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1815 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2011-10-06 08:54:33 +00:00
parent c9280a0760
commit ca9308e059
1 changed files with 19 additions and 4 deletions

View File

@ -47,6 +47,8 @@ import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import javax.mail.internet.MimePart;
import javax.mail.util.SharedByteArrayInputStream;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
@ -2506,7 +2508,8 @@ public class DavExchangeSession extends ExchangeSession {
putmethod.setRequestEntity(new ByteArrayRequestEntity(baos.toByteArray()));
int code = httpClient.executeMethod(putmethod);
if (code != HttpStatus.SC_OK && code != HttpStatus.SC_CREATED && code != HttpStatus.SC_INSUFFICIENT_STORAGE) {
// workaround for misconfigured Exchange server
if (code == HttpStatus.SC_NOT_ACCEPTABLE) {
LOGGER.warn("Draft message creation failed, failover to property update. Note: attachments are lost");
ArrayList<DavConstants> propertyList = new ArrayList<DavConstants>();
@ -2514,12 +2517,24 @@ public class DavExchangeSession extends ExchangeSession {
propertyList.add(Field.createDavProperty("cc", mimeMessage.getHeader("cc", ",")));
propertyList.add(Field.createDavProperty("message-id", mimeMessage.getHeader("message-id", ",")));
String contentType = mimeMessage.getContentType();
MimePart mimePart = mimeMessage;
if (mimeMessage.getContent() instanceof MimeMultipart) {
MimeMultipart multiPart = (MimeMultipart) mimeMessage.getContent();
for (int i = 0; i < multiPart.getCount(); i++) {
String contentType = multiPart.getBodyPart(i).getContentType();
if (contentType.startsWith("text/")) {
mimePart = (MimePart) multiPart.getBodyPart(i);
break;
}
}
}
String contentType = mimePart.getContentType();
if (contentType.startsWith("text/plain")) {
propertyList.add(Field.createDavProperty("description", (String) mimeMessage.getContent()));
propertyList.add(Field.createDavProperty("description", (String) mimePart.getContent()));
} else if (contentType.startsWith("text/html")) {
propertyList.add(Field.createDavProperty("htmldescription", (String) mimeMessage.getContent()));
propertyList.add(Field.createDavProperty("htmldescription", (String) mimePart.getContent()));
} else {
LOGGER.warn("Unsupported content type: " + contentType + " message body will be empty");
}