mirror of
https://github.com/moparisthebest/davmail
synced 2025-01-05 18:58:02 -05:00
Fix nullpointer when HTML body is empty
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@40 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
163e611bd1
commit
6a79873d29
@ -17,6 +17,7 @@ import org.w3c.tidy.Tidy;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.NamedNodeMap;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import javax.mail.MessagingException;
|
||||
import javax.mail.internet.MimeUtility;
|
||||
@ -1058,6 +1059,9 @@ public class ExchangeSession {
|
||||
XmlDocument xmlDocument = new XmlDocument();
|
||||
try {
|
||||
Document w3cDocument = tidy.parseDOM(inputStream, null);
|
||||
Element documentElement = w3cDocument.getDocumentElement();
|
||||
|
||||
if (documentElement != null) {
|
||||
// Fix broken Office xml document with empty namespace
|
||||
NamedNodeMap namedNodeMap = w3cDocument.getDocumentElement().getAttributes();
|
||||
for (int i = 0; i < namedNodeMap.getLength(); i++) {
|
||||
@ -1069,6 +1073,7 @@ public class ExchangeSession {
|
||||
w3cDocument.getDocumentElement().removeAttribute(nodeName);
|
||||
}
|
||||
}
|
||||
}
|
||||
xmlDocument.load(builder.build(w3cDocument));
|
||||
} catch (IOException ex1) {
|
||||
logger.error("Exception parsing document", ex1);
|
||||
@ -1149,6 +1154,8 @@ public class ExchangeSession {
|
||||
}
|
||||
}
|
||||
|
||||
// HTML body may be empty
|
||||
if (htmlBody != null && htmlBody.length() > 0) {
|
||||
// get inline images from htmlBody (without OWA transformation)
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(htmlBody
|
||||
// quick fix remove default office namespace
|
||||
@ -1223,6 +1230,7 @@ public class ExchangeSession {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -1314,19 +1322,19 @@ public class ExchangeSession {
|
||||
int equalsIndex = token.indexOf('=');
|
||||
if (equalsIndex > 0) {
|
||||
String tokenName = token.substring(0, equalsIndex);
|
||||
if ("charset".equals(tokenName)) {
|
||||
if ("charset".equalsIgnoreCase(tokenName)) {
|
||||
charset = token.substring(equalsIndex + 1);
|
||||
if (charset.startsWith("\"")) {
|
||||
charset = charset.substring(1, charset.lastIndexOf("\""));
|
||||
}
|
||||
} else if ("name".equals(tokenName.toLowerCase())) {
|
||||
} else if ("name".equalsIgnoreCase(tokenName.toLowerCase())) {
|
||||
name = token.substring(equalsIndex + 1);
|
||||
if (name.startsWith("\"")) {
|
||||
name = name.substring(1, name.lastIndexOf("\""));
|
||||
}
|
||||
// name can be mime encoded
|
||||
name = MimeUtility.decodeText(name);
|
||||
} else if ("boundary".equals(tokenName)) {
|
||||
} else if ("boundary".equalsIgnoreCase(tokenName)) {
|
||||
boundary = token.substring(equalsIndex + 1);
|
||||
if (boundary.startsWith("\"")) {
|
||||
boundary = boundary.substring(1, boundary.lastIndexOf("\""));
|
||||
|
Loading…
Reference in New Issue
Block a user