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