From d2e141e9f7dcf603d9137937784d8749abce2a72 Mon Sep 17 00:00:00 2001 From: mguessan Date: Mon, 23 Apr 2007 23:35:59 +0000 Subject: [PATCH] support delivery status notification report git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@47 3d1905a2-6b24-0410-a738-b14d5a86fcbd --- .../davmail/exchange/ExchangeSession.java | 41 +++++++++++-------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/src/java/davmail/exchange/ExchangeSession.java b/src/java/davmail/exchange/ExchangeSession.java index 57701527..82648282 100644 --- a/src/java/davmail/exchange/ExchangeSession.java +++ b/src/java/davmail/exchange/ExchangeSession.java @@ -447,7 +447,8 @@ public class ExchangeSession { Message message = buildMessage(entity); if ("urn:content-classes:message".equals(message.contentClass) || "urn:content-classes:calendarmessage".equals(message.contentClass) || - "urn:content-classes:recallmessage".equals(message.contentClass)) { + "urn:content-classes:recallmessage".equals(message.contentClass) || + "urn:content-classes:dsn".equals(message.contentClass)) { messages.add(message); } } @@ -785,7 +786,9 @@ public class ExchangeSession { public void writeMimeMessage(BufferedReader reader, OutputStream os, MimeHeader mimeHeader) throws IOException { String line; // with alternative, there are two body forms (plain+html) - if ("multipart/alternative".equalsIgnoreCase(mimeHeader.contentType)) { + // with multipart/report server sends plain and delivery-status + if ("multipart/alternative".equalsIgnoreCase(mimeHeader.contentType) || + "multipart/report".equalsIgnoreCase(mimeHeader.contentType)) { attachmentIndex--; } @@ -917,7 +920,7 @@ public class ExchangeSession { } catch (MessagingException e) { throw new IOException(e + " " + e.getMessage()); } - String currentBody; + String currentBody = null; if ("text/html".equalsIgnoreCase(mimeHeader.contentType)) { currentBody = htmlBody; // patch charset if null and html body encoded @@ -942,22 +945,24 @@ public class ExchangeSession { } } - } else { + } else if ("text/plain".equalsIgnoreCase(mimeHeader.contentType)) { currentBody = body; } - if (mimeHeader.charset != null) { - try { - quotedOs.write(currentBody.getBytes(MimeUtility.javaCharset(mimeHeader.charset))); - } catch (UnsupportedEncodingException uee) { - // TODO : try to decode other encodings + if (currentBody != null) { + if (mimeHeader.charset != null) { + try { + quotedOs.write(currentBody.getBytes(MimeUtility.javaCharset(mimeHeader.charset))); + } catch (UnsupportedEncodingException uee) { + // TODO : try to decode other encodings + quotedOs.write(currentBody.getBytes()); + } + } else { quotedOs.write(currentBody.getBytes()); } - } else { - quotedOs.write(currentBody.getBytes()); + quotedOs.flush(); + os.write('\r'); + os.write('\n'); } - quotedOs.flush(); - os.write('\r'); - os.write('\n'); } public void delete() throws IOException { @@ -1109,6 +1114,10 @@ public class ExchangeSession { attachmentsMap = new HashMap(); int attachmentIndex = 1; + // fix empty body in dsn report + if (body == null || body.length() == 0) { + body = xmlDocument.getValue("//textarea"); + } // list file attachments identified explicitly List list = xmlDocument.getNodes("//table[@id='idAttachmentWell']//a/@href"); for (Attribute element : list) { @@ -1169,9 +1178,9 @@ public class ExchangeSession { ByteArrayInputStream bais = new ByteArrayInputStream(htmlBody // quick fix remove default office namespace .replaceFirst("xmlns=\".*\"", "") - // quick fix remove inline processing instructions + // quick fix remove inline processing instructions .replaceAll("<\\?xml:namespace", "") - // quick fix invalid comments + // quick fix invalid comments .replaceAll("