From 4bc0773aa7cff2a6e15f48c7276a8f9bfb6cebb9 Mon Sep 17 00:00:00 2001 From: mguessan Date: Fri, 5 Aug 2011 20:05:58 +0000 Subject: [PATCH] IMAP: Fix 3383832, set ItemClass to send read receipt over EWS to avoid ErrorObjectTypeChanged git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1762 3d1905a2-6b24-0410-a738-b14d5a86fcbd --- src/java/davmail/exchange/ExchangeSession.java | 14 +++----------- .../exchange/dav/DavExchangeSession.java | 6 ++++-- src/java/davmail/exchange/ews/EWSMethod.java | 10 +++++----- .../exchange/ews/EwsExchangeSession.java | 18 +++++++++++++----- 4 files changed, 25 insertions(+), 23 deletions(-) diff --git a/src/java/davmail/exchange/ExchangeSession.java b/src/java/davmail/exchange/ExchangeSession.java index e1cd0163..35beaf68 100644 --- a/src/java/davmail/exchange/ExchangeSession.java +++ b/src/java/davmail/exchange/ExchangeSession.java @@ -658,14 +658,6 @@ public abstract class ExchangeSession { */ public abstract void deleteMessage(Message message) throws IOException; - /** - * Send message. - * - * @param messageBody MIME message body - * @throws IOException on error - */ - public abstract void sendMessage(byte[] messageBody) throws IOException; - /** * Get raw MIME message content * @@ -1236,7 +1228,7 @@ public abstract class ExchangeSession { * @param mimeMessage MIME message * @throws IOException on error */ - public abstract void sendMessage(MimeMessage mimeMessage) throws IOException; + public abstract void sendMessage(MimeMessage mimeMessage) throws IOException, MessagingException; /** * Get folder object. @@ -2224,9 +2216,9 @@ public abstract class ExchangeSession { protected byte[] getICS(InputStream mimeInputStream) throws IOException, MessagingException { byte[] result; MimeMessage mimeMessage = new MimeMessage(null, mimeInputStream); - String[] contentClass = mimeMessage.getHeader("Content-class"); + String[] contentClassHeader = mimeMessage.getHeader("Content-class"); // task item, return null - if (contentClass != null && contentClass.length > 0 && "urn:content-classes:task".equals(contentClass[0])) { + if (contentClassHeader != null && contentClassHeader.length > 0 && "urn:content-classes:task".equals(contentClassHeader[0])) { return null; } Object mimeBody = mimeMessage.getContent(); diff --git a/src/java/davmail/exchange/dav/DavExchangeSession.java b/src/java/davmail/exchange/dav/DavExchangeSession.java index 84dd67be..96f327e0 100644 --- a/src/java/davmail/exchange/dav/DavExchangeSession.java +++ b/src/java/davmail/exchange/dav/DavExchangeSession.java @@ -2490,9 +2490,11 @@ public class DavExchangeSession extends ExchangeSession { } /** - * @inheritDoc + * Send message. + * + * @param messageBody MIME message body + * @throws IOException on error */ - @Override public void sendMessage(byte[] messageBody) throws IOException { try { sendMessage(new MimeMessage(null, new SharedByteArrayInputStream(messageBody))); diff --git a/src/java/davmail/exchange/ews/EWSMethod.java b/src/java/davmail/exchange/ews/EWSMethod.java index 793f7b06..68472796 100644 --- a/src/java/davmail/exchange/ews/EWSMethod.java +++ b/src/java/davmail/exchange/ews/EWSMethod.java @@ -500,6 +500,11 @@ public abstract class EWSMethod extends PostMethod { writer.write(""); + if (mimeContent != null) { + writer.write(""); + writer.write(new String(mimeContent)); + writer.write(""); + } // write ordered fields for (String key : fieldNames) { if ("MeetingTimeZone".equals(key)) { @@ -520,11 +525,6 @@ public abstract class EWSMethod extends PostMethod { writer.write(">"); } } - if (mimeContent != null) { - writer.write(""); - writer.write(new String(mimeContent)); - writer.write(""); - } if (fieldUpdates != null) { for (FieldUpdate fieldUpdate : fieldUpdates) { fieldUpdate.write(null, writer); diff --git a/src/java/davmail/exchange/ews/EwsExchangeSession.java b/src/java/davmail/exchange/ews/EwsExchangeSession.java index d9df659c..3c762cb8 100644 --- a/src/java/davmail/exchange/ews/EwsExchangeSession.java +++ b/src/java/davmail/exchange/ews/EwsExchangeSession.java @@ -440,11 +440,14 @@ public class EwsExchangeSession extends ExchangeSession { executeMethod(deleteItemMethod); } - @Override - public void sendMessage(byte[] messageBody) throws IOException { + + public void sendMessage(String itemClass, byte[] messageBody) throws IOException { EWSMethod.Item item = new EWSMethod.Item(); item.type = "Message"; item.mimeContent = Base64.encodeBase64(messageBody); + if (itemClass != null) { + item.put("ItemClass", itemClass); + } MessageDisposition messageDisposition; if (Settings.getBooleanProperty("davmail.smtpSaveInSent", true)) { @@ -458,14 +461,19 @@ public class EwsExchangeSession extends ExchangeSession { } @Override - public void sendMessage(MimeMessage mimeMessage) throws IOException { + public void sendMessage(MimeMessage mimeMessage) throws IOException, MessagingException { + String itemClass = null; + if (mimeMessage.getContentType().startsWith("multipart/report")) { + itemClass = "REPORT.IPM.Note.IPNRN"; + } + ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { mimeMessage.writeTo(baos); } catch (MessagingException e) { throw new IOException(e.getMessage()); } - sendMessage(baos.toByteArray()); + sendMessage(itemClass, baos.toByteArray()); } /** @@ -1684,7 +1692,7 @@ public class EwsExchangeSession extends ExchangeSession { // no recipients, cancel return HttpStatus.SC_NO_CONTENT; } else { - sendMessage(mimeContent); + sendMessage(null, mimeContent); return HttpStatus.SC_OK; } }