Added message warnings

This commit is contained in:
M66B 2019-01-16 18:01:00 +00:00
parent 2539f540f3
commit 5493bdd3c9
2 changed files with 21 additions and 0 deletions

View File

@ -535,6 +535,7 @@ public class MessageHelper {
private Part plain = null;
private Part html = null;
private List<AttachmentPart> attachments = new ArrayList<>();
private List<String> warnings = new ArrayList<>();
String getHtml() throws MessagingException {
if (plain == null && html == null)
@ -559,6 +560,16 @@ public class MessageHelper {
result = ex + "\n" + android.util.Log.getStackTraceString(ex);
}
ContentType ct = new ContentType(part.getContentType());
String charset = ct.getParameter("charset");
if (TextUtils.isEmpty(charset))
warnings.add("Missing charset");
else {
if ("US-ASCII".equals(Charset.forName(charset).name()) &&
!"US-ASCII".equals(charset.toUpperCase()))
warnings.add("Unknown charset " + charset);
}
if (part.isMimeType("text/plain") || text)
result = "<pre>" + result.replaceAll("\\r?\\n", "<br />") + "</pre>";
@ -666,6 +677,13 @@ public class MessageHelper {
os.close();
}
}
String getWarnings() {
if (warnings.size() == 0)
return null;
else
return TextUtils.join(", ", warnings);
}
}
private class AttachmentPart {

View File

@ -2628,6 +2628,9 @@ public class ServiceSynchronize extends LifecycleService {
String body = parts.getHtml();
message.write(context, body);
db.message().setMessageContent(message.id, true, HtmlHelper.getPreview(body));
String warnings = parts.getWarnings();
if (warnings != null)
db.message().setMessageError(message.id, warnings);
Log.i(folder.name + " downloaded message id=" + message.id + " size=" + message.size);
}