Merge branch 'readonly-p4-donut' into donut
This commit is contained in:
commit
51249c25c5
@ -727,8 +727,8 @@ public class MessageView extends Activity
|
|||||||
*/
|
*/
|
||||||
/* package */ String resolveInlineImage(String text, Part part, int depth)
|
/* package */ String resolveInlineImage(String text, Part part, int depth)
|
||||||
throws MessagingException {
|
throws MessagingException {
|
||||||
// avoid too deep recursive call.
|
// avoid too deep recursive call or null text
|
||||||
if (depth >= 10) {
|
if (depth >= 10 || text == null) {
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
String contentType = MimeUtility.unfoldAndDecode(part.getContentType());
|
String contentType = MimeUtility.unfoldAndDecode(part.getContentType());
|
||||||
@ -945,20 +945,22 @@ public class MessageView extends Activity
|
|||||||
* Linkify the plain text and convert it to HTML by replacing
|
* Linkify the plain text and convert it to HTML by replacing
|
||||||
* \r?\n with <br> and adding a html/body wrapper.
|
* \r?\n with <br> and adding a html/body wrapper.
|
||||||
*/
|
*/
|
||||||
Matcher m = Regex.WEB_URL_PATTERN.matcher(text);
|
StringBuffer sb = new StringBuffer("<html><body>");
|
||||||
StringBuffer sb = new StringBuffer();
|
if (text != null) {
|
||||||
while (m.find()) {
|
Matcher m = Regex.WEB_URL_PATTERN.matcher(text);
|
||||||
int start = m.start();
|
while (m.find()) {
|
||||||
if (start != 0 && text.charAt(start - 1) != '@') {
|
int start = m.start();
|
||||||
m.appendReplacement(sb, "<a href=\"$0\">$0</a>");
|
if (start != 0 && text.charAt(start - 1) != '@') {
|
||||||
}
|
m.appendReplacement(sb, "<a href=\"$0\">$0</a>");
|
||||||
else {
|
}
|
||||||
m.appendReplacement(sb, "$0");
|
else {
|
||||||
|
m.appendReplacement(sb, "$0");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
m.appendTail(sb);
|
||||||
}
|
}
|
||||||
m.appendTail(sb);
|
sb.append("</body></html>");
|
||||||
text = sb.toString().replaceAll("\r?\n", "<br>");
|
text = sb.toString().replaceAll("\r?\n", "<br>");
|
||||||
text = "<html><body>" + text + "</body></html>";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -245,9 +245,9 @@ public class MimeUtility {
|
|||||||
/**
|
/**
|
||||||
* Reads the Part's body and returns a String based on any charset conversion that needed
|
* Reads the Part's body and returns a String based on any charset conversion that needed
|
||||||
* to be done.
|
* to be done.
|
||||||
* @param part
|
* @param part The part containing a body
|
||||||
* @return
|
* @return a String containing the converted text in the body, or null if there was no text
|
||||||
* @throws IOException
|
* or an error during conversion.
|
||||||
*/
|
*/
|
||||||
public static String getTextFromPart(Part part) {
|
public static String getTextFromPart(Part part) {
|
||||||
try {
|
try {
|
||||||
@ -261,43 +261,48 @@ public class MimeUtility {
|
|||||||
*/
|
*/
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
IOUtils.copy(in, out);
|
IOUtils.copy(in, out);
|
||||||
|
|
||||||
byte[] bytes = out.toByteArray();
|
|
||||||
in.close();
|
in.close();
|
||||||
out.close();
|
in = null; // we want all of our memory back, and close might not release
|
||||||
|
|
||||||
String charset = getHeaderParameter(part.getContentType(), "charset");
|
|
||||||
/*
|
/*
|
||||||
* We've got a text part, so let's see if it needs to be processed further.
|
* We've got a text part, so let's see if it needs to be processed further.
|
||||||
*/
|
*/
|
||||||
|
String charset = getHeaderParameter(part.getContentType(), "charset");
|
||||||
if (charset != null) {
|
if (charset != null) {
|
||||||
/*
|
/*
|
||||||
* See if there is conversion from the MIME charset to the Java one.
|
* See if there is conversion from the MIME charset to the Java one.
|
||||||
*/
|
*/
|
||||||
charset = CharsetUtil.toJavaCharset(charset);
|
charset = CharsetUtil.toJavaCharset(charset);
|
||||||
}
|
}
|
||||||
if (charset != null) {
|
/*
|
||||||
/*
|
* No encoding, so use us-ascii, which is the standard.
|
||||||
* We've got a charset encoding, so decode using it.
|
*/
|
||||||
*/
|
if (charset == null) {
|
||||||
return new String(bytes, 0, bytes.length, charset);
|
charset = "ASCII";
|
||||||
}
|
|
||||||
else {
|
|
||||||
/*
|
|
||||||
* No encoding, so use us-ascii, which is the standard.
|
|
||||||
*/
|
|
||||||
return new String(bytes, 0, bytes.length, "ASCII");
|
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
* Convert and return as new String
|
||||||
|
*/
|
||||||
|
String result = out.toString(charset);
|
||||||
|
out.close();
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
catch (OutOfMemoryError oom) {
|
||||||
|
/*
|
||||||
|
* If we are not able to process the body there's nothing we can do about it. Return
|
||||||
|
* null and let the upper layers handle the missing content.
|
||||||
|
*/
|
||||||
|
Log.e(Email.LOG_TAG, "Unable to getTextFromPart " + oom.toString());
|
||||||
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
/*
|
/*
|
||||||
* If we are not able to process the body there's nothing we can do about it. Return
|
* If we are not able to process the body there's nothing we can do about it. Return
|
||||||
* null and let the upper layers handle the missing content.
|
* null and let the upper layers handle the missing content.
|
||||||
*/
|
*/
|
||||||
Log.e(Email.LOG_TAG, "Unable to getTextFromPart", e);
|
Log.e(Email.LOG_TAG, "Unable to getTextFromPart " + e.toString());
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -231,6 +231,10 @@ public class MessageViewTests
|
|||||||
final String actual4 = a.resolveInlineImage(text2 + text1, msg4, 0);
|
final String actual4 = a.resolveInlineImage(text2 + text1, msg4, 0);
|
||||||
assertEquals("two content ids in deep multipart level are resolved",
|
assertEquals("two content ids in deep multipart level are resolved",
|
||||||
expected2 + expected1, actual4);
|
expected2 + expected1, actual4);
|
||||||
|
|
||||||
|
// No crash on null text
|
||||||
|
final String actual5 = a.resolveInlineImage(null, msg4, 0);
|
||||||
|
assertNull(actual5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user