Support for multiple body parts

pull/174/head
M66B 5 years ago
parent d5cef39de0
commit 7347b161aa

@ -1221,41 +1221,50 @@ public class MessageHelper {
} }
class MessageParts { class MessageParts {
private Part plain = null; private List<Part> plain = new ArrayList<>();
private Part html = null; private List<Part> html = new ArrayList<>();
private List<AttachmentPart> attachments = new ArrayList<>(); private List<AttachmentPart> attachments = new ArrayList<>();
private ArrayList<String> warnings = new ArrayList<>(); private ArrayList<String> warnings = new ArrayList<>();
Boolean isPlainOnly() { Boolean isPlainOnly() {
if (plain == null && html == null) if (plain.size() + html.size() == 0)
return null; return null;
return (html == null); return (html.size() == 0);
} }
Long getBodySize() throws MessagingException { Long getBodySize() throws MessagingException {
Part part = (html == null ? plain : html); Long size = null;
if (part == null)
return null; List<Part> all = new ArrayList<>();
int size = part.getSize(); all.addAll(plain);
if (size < 0) all.addAll(html);
return null; for (Part p : all) {
int s = p.getSize();
if (s >= 0)
if (size == null)
size = (long) s;
else else
return (long) size; size += (long) s;
}
return size;
} }
String getHtml(Context context) throws MessagingException, IOException { String getHtml(Context context) throws MessagingException, IOException {
if (plain == null && html == null) { if (plain.size() + html.size() == 0) {
Log.i("No body part"); Log.i("No body part");
return null; return null;
} }
String result; StringBuilder sb = new StringBuilder();
Part part = (html == null ? plain : html);
for (Part part : html.size() > 0 ? html : plain) {
if (part.getSize() > MAX_MESSAGE_SIZE) { if (part.getSize() > MAX_MESSAGE_SIZE) {
warnings.add(context.getString(R.string.title_insufficient_memory)); warnings.add(context.getString(R.string.title_insufficient_memory));
return null; return null;
} }
String result;
try { try {
Object content = part.getContent(); Object content = part.getContent();
Log.i("Content class=" + (content == null ? null : content.getClass().getName())); Log.i("Content class=" + (content == null ? null : content.getClass().getName()));
@ -1289,10 +1298,13 @@ public class MessageHelper {
Log.e(ex); Log.e(ex);
} }
if (part == plain) if (part.isMimeType("text/plain"))
result = "<div>" + HtmlHelper.formatPre(result) + "</div>"; result = "<div>" + HtmlHelper.formatPre(result) + "</div>";
return result; sb.append(result);
}
return sb.toString();
} }
List<AttachmentPart> getAttachmentParts() { List<AttachmentPart> getAttachmentParts() {
@ -1637,14 +1649,11 @@ public class MessageHelper {
contentType = new ContentType(Helper.guessMimeType(filename)); contentType = new ContentType(Helper.guessMimeType(filename));
} }
if (!Part.ATTACHMENT.equalsIgnoreCase(disposition) && if (!Part.ATTACHMENT.equalsIgnoreCase(disposition) && TextUtils.isEmpty(filename)) {
TextUtils.isEmpty(filename) && if ("text/plain".equalsIgnoreCase(contentType.getBaseType()))
((parts.plain == null && "text/plain".equalsIgnoreCase(contentType.getBaseType())) || parts.plain.add(part);
(parts.html == null && "text/html".equalsIgnoreCase(contentType.getBaseType())))) { else if ("text/html".equalsIgnoreCase(contentType.getBaseType()))
if ("text/html".equalsIgnoreCase(contentType.getBaseType())) parts.html.add(part);
parts.html = part;
else
parts.plain = part;
} else { } else {
AttachmentPart apart = new AttachmentPart(); AttachmentPart apart = new AttachmentPart();
apart.disposition = disposition; apart.disposition = disposition;

Loading…
Cancel
Save