You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ni...@apache.org on 2011/04/01 18:27:04 UTC
svn commit: r1087788 -
/poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java
Author: nick
Date: Fri Apr 1 16:27:03 2011
New Revision: 1087788
URL: http://svn.apache.org/viewvc?rev=1087788&view=rev
Log:
Tweak 7 bit guessing code
Modified:
poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java?rev=1087788&r1=1087787&r2=1087788&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java Fri Apr 1 16:27:03 2011
@@ -362,20 +362,18 @@ public class MAPIMessage extends POIDocu
public void guess7BitEncoding() {
try {
String[] headers = getHeaders();
- if(headers == null || headers.length == 0) {
- return;
- }
-
- // Look for a content type with a charset
- Pattern p = Pattern.compile("Content-Type:.*?charset=[\"']?(.*?)[\"']?");
- for(String header : headers) {
- if(header.startsWith("Content-Type")) {
- Matcher m = p.matcher(header);
- if(m.matches()) {
- // Found it! Tell all the string chunks
- String charset = m.group(1);
- set7BitEncoding(charset);
- return;
+ if(headers != null && headers.length > 0) {
+ // Look for a content type with a charset
+ Pattern p = Pattern.compile("Content-Type:.*?charset=[\"']?(.*?)[\"']?");
+ for(String header : headers) {
+ if(header.startsWith("Content-Type")) {
+ Matcher m = p.matcher(header);
+ if(m.matches()) {
+ // Found it! Tell all the string chunks
+ String charset = m.group(1);
+ set7BitEncoding(charset);
+ return;
+ }
}
}
}
@@ -384,17 +382,18 @@ public class MAPIMessage extends POIDocu
// Nothing suitable in the headers, try HTML
try {
String html = getHmtlBody();
-
- // Look for a content type in the meta headers
- Pattern p = Pattern.compile(
- "<META\\s+HTTP-EQUIV=\"Content-Type\"\\s+CONTENT=\"text/html;\\s+charset=(.*?)\""
- );
- Matcher m = p.matcher(html);
- if(m.find()) {
- // Found it! Tell all the string chunks
- String charset = m.group(1);
- set7BitEncoding(charset);
- return;
+ if(html != null && html.length() > 0) {
+ // Look for a content type in the meta headers
+ Pattern p = Pattern.compile(
+ "<META\\s+HTTP-EQUIV=\"Content-Type\"\\s+CONTENT=\"text/html;\\s+charset=(.*?)\""
+ );
+ Matcher m = p.matcher(html);
+ if(m.find()) {
+ // Found it! Tell all the string chunks
+ String charset = m.group(1);
+ set7BitEncoding(charset);
+ return;
+ }
}
} catch(ChunkNotFoundException e) {}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org