Refactoring

This commit is contained in:
M66B 2020-04-07 19:43:02 +02:00
parent e4b3eb6276
commit c009f1c4bf
2 changed files with 23 additions and 20 deletions

View File

@ -936,6 +936,27 @@ public class HtmlHelper {
return false;
}
// https://tools.ietf.org/html/rfc3676
static String flow(String text) {
boolean continuation = false;
StringBuilder flowed = new StringBuilder();
for (String line : text.split("\\r?\\n")) {
if (continuation)
while (line.startsWith(">")) {
line = line.substring(1);
if (line.startsWith(" "))
line = line.substring(1);
}
continuation = (line.endsWith(" ") && !"-- ".equals(line));
flowed.append(line);
if (!continuation)
flowed.append("\r\n");
}
return flowed.toString();
}
static String formatPre(String text) {
int level = 0;
StringBuilder sb = new StringBuilder();

View File

@ -1481,26 +1481,8 @@ public class MessageHelper {
warnings.add(context.getString(R.string.title_no_charset, charset));
if (part.isMimeType("text/plain")) {
// https://tools.ietf.org/html/rfc3676
if ("flowed".equalsIgnoreCase(ct.getParameter("format"))) {
boolean continuation = false;
StringBuilder flowed = new StringBuilder();
for (String line : result.split("\\r?\\n")) {
if (continuation)
while (line.startsWith(">")) {
line = line.substring(1);
if (line.startsWith(" "))
line = line.substring(1);
}
continuation = (line.endsWith(" ") && !"-- ".equals(line));
flowed.append(line);
if (!continuation)
flowed.append("\r\n");
}
result = flowed.toString();
}
if ("flowed".equalsIgnoreCase(ct.getParameter("format")))
result = HtmlHelper.flow(result);
result = "<div>" + HtmlHelper.formatPre(result) + "</div>";
} else if (part.isMimeType("text/html")) {
if (TextUtils.isEmpty(charset)) {