support delivery status notification report

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@47 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2007-04-23 23:35:59 +00:00
parent 3582bac793
commit d2e141e9f7
1 changed files with 25 additions and 16 deletions

View File

@ -447,7 +447,8 @@ public class ExchangeSession {
Message message = buildMessage(entity); Message message = buildMessage(entity);
if ("urn:content-classes:message".equals(message.contentClass) || if ("urn:content-classes:message".equals(message.contentClass) ||
"urn:content-classes:calendarmessage".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); messages.add(message);
} }
} }
@ -785,7 +786,9 @@ public class ExchangeSession {
public void writeMimeMessage(BufferedReader reader, OutputStream os, MimeHeader mimeHeader) throws IOException { public void writeMimeMessage(BufferedReader reader, OutputStream os, MimeHeader mimeHeader) throws IOException {
String line; String line;
// with alternative, there are two body forms (plain+html) // 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--; attachmentIndex--;
} }
@ -917,7 +920,7 @@ public class ExchangeSession {
} catch (MessagingException e) { } catch (MessagingException e) {
throw new IOException(e + " " + e.getMessage()); throw new IOException(e + " " + e.getMessage());
} }
String currentBody; String currentBody = null;
if ("text/html".equalsIgnoreCase(mimeHeader.contentType)) { if ("text/html".equalsIgnoreCase(mimeHeader.contentType)) {
currentBody = htmlBody; currentBody = htmlBody;
// patch charset if null and html body encoded // 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; currentBody = body;
} }
if (mimeHeader.charset != null) { if (currentBody != null) {
try { if (mimeHeader.charset != null) {
quotedOs.write(currentBody.getBytes(MimeUtility.javaCharset(mimeHeader.charset))); try {
} catch (UnsupportedEncodingException uee) { quotedOs.write(currentBody.getBytes(MimeUtility.javaCharset(mimeHeader.charset)));
// TODO : try to decode other encodings } catch (UnsupportedEncodingException uee) {
// TODO : try to decode other encodings
quotedOs.write(currentBody.getBytes());
}
} else {
quotedOs.write(currentBody.getBytes()); quotedOs.write(currentBody.getBytes());
} }
} else { quotedOs.flush();
quotedOs.write(currentBody.getBytes()); os.write('\r');
os.write('\n');
} }
quotedOs.flush();
os.write('\r');
os.write('\n');
} }
public void delete() throws IOException { public void delete() throws IOException {
@ -1109,6 +1114,10 @@ public class ExchangeSession {
attachmentsMap = new HashMap<String, Attachment>(); attachmentsMap = new HashMap<String, Attachment>();
int attachmentIndex = 1; 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 file attachments identified explicitly
List<Attribute> list = xmlDocument.getNodes("//table[@id='idAttachmentWell']//a/@href"); List<Attribute> list = xmlDocument.getNodes("//table[@id='idAttachmentWell']//a/@href");
for (Attribute element : list) { for (Attribute element : list) {
@ -1169,9 +1178,9 @@ public class ExchangeSession {
ByteArrayInputStream bais = new ByteArrayInputStream(htmlBody ByteArrayInputStream bais = new ByteArrayInputStream(htmlBody
// quick fix remove default office namespace // quick fix remove default office namespace
.replaceFirst("xmlns=\".*\"", "") .replaceFirst("xmlns=\".*\"", "")
// quick fix remove inline processing instructions // quick fix remove inline processing instructions
.replaceAll("<\\?xml:namespace", "") .replaceAll("<\\?xml:namespace", "")
// quick fix invalid comments // quick fix invalid comments
.replaceAll("<!---", "<!-- -") .replaceAll("<!---", "<!-- -")
.getBytes("UTF-8")); .getBytes("UTF-8"));
XmlDocument xmlBody = tidyDocument(bais); XmlDocument xmlBody = tidyDocument(bais);