mirror of https://github.com/M66B/FairEmail.git
Refactoring
This commit is contained in:
parent
1401e36e75
commit
e677c68e9c
|
@ -1617,13 +1617,17 @@ public class MessageHelper {
|
||||||
class PartHolder {
|
class PartHolder {
|
||||||
Multipart parent;
|
Multipart parent;
|
||||||
Part part;
|
Part part;
|
||||||
String contentType;
|
ContentType contentType;
|
||||||
|
|
||||||
PartHolder(Multipart parent, Part part, String contentType) {
|
PartHolder(Multipart parent, Part part, ContentType contentType) {
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
this.part = part;
|
this.part = part;
|
||||||
this.contentType = contentType;
|
this.contentType = contentType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean isPlainText() {
|
||||||
|
return "text/plain".equalsIgnoreCase(contentType.getBaseType());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class MessageParts {
|
class MessageParts {
|
||||||
|
@ -1633,6 +1637,8 @@ public class MessageHelper {
|
||||||
private ArrayList<String> warnings = new ArrayList<>();
|
private ArrayList<String> warnings = new ArrayList<>();
|
||||||
|
|
||||||
MessageParts select() {
|
MessageParts select() {
|
||||||
|
// Prefer HTML over alternative text
|
||||||
|
|
||||||
Map<Multipart, List<PartHolder>> map = new HashMap<>();
|
Map<Multipart, List<PartHolder>> map = new HashMap<>();
|
||||||
for (PartHolder h : text)
|
for (PartHolder h : text)
|
||||||
if (h.parent != null) {
|
if (h.parent != null) {
|
||||||
|
@ -1643,18 +1649,15 @@ public class MessageHelper {
|
||||||
|
|
||||||
for (Multipart mp : map.keySet())
|
for (Multipart mp : map.keySet())
|
||||||
try {
|
try {
|
||||||
if (new ContentType(mp.getContentType())
|
boolean plain = true;
|
||||||
.getBaseType().equalsIgnoreCase("multipart/alternative")) {
|
for (PartHolder h : map.get(mp))
|
||||||
boolean plain = true;
|
if (!h.isPlainText()) {
|
||||||
for (PartHolder h : map.get(mp))
|
plain = false;
|
||||||
if (!"text/plain".equalsIgnoreCase(h.contentType)) {
|
break;
|
||||||
plain = false;
|
}
|
||||||
break;
|
for (PartHolder h : map.get(mp))
|
||||||
}
|
if (!plain && h.isPlainText())
|
||||||
for (PartHolder h : map.get(mp))
|
text.remove(h);
|
||||||
if (!plain && "text/plain".equalsIgnoreCase(h.contentType))
|
|
||||||
text.remove(h);
|
|
||||||
}
|
|
||||||
} catch (Throwable ex) {
|
} catch (Throwable ex) {
|
||||||
Log.w(ex);
|
Log.w(ex);
|
||||||
}
|
}
|
||||||
|
@ -1666,7 +1669,7 @@ public class MessageHelper {
|
||||||
if (text.size() + extra.size() == 0)
|
if (text.size() + extra.size() == 0)
|
||||||
return null;
|
return null;
|
||||||
for (PartHolder h : text)
|
for (PartHolder h : text)
|
||||||
if (!"text/plain".equalsIgnoreCase(h.contentType))
|
if (!h.isPlainText())
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -2180,9 +2183,10 @@ public class MessageHelper {
|
||||||
} else
|
} else
|
||||||
throw new ParseException(content.getClass().getName());
|
throw new ParseException(content.getClass().getName());
|
||||||
|
|
||||||
|
boolean alternative = part.isMimeType("multipart/alternative");
|
||||||
for (int i = 0; i < multipart.getCount(); i++)
|
for (int i = 0; i < multipart.getCount(); i++)
|
||||||
try {
|
try {
|
||||||
getMessageParts(multipart, multipart.getBodyPart(i), parts, encrypt);
|
getMessageParts(alternative ? multipart : null, multipart.getBodyPart(i), parts, encrypt);
|
||||||
} catch (ParseException ex) {
|
} catch (ParseException ex) {
|
||||||
// Nested body: try to continue
|
// Nested body: try to continue
|
||||||
// ParseException: In parameter list boundary="...">, expected parameter name, got ";"
|
// ParseException: In parameter list boundary="...">, expected parameter name, got ";"
|
||||||
|
@ -2227,11 +2231,11 @@ public class MessageHelper {
|
||||||
String ct = contentType.getBaseType();
|
String ct = contentType.getBaseType();
|
||||||
if (("text/plain".equalsIgnoreCase(ct) || "text/html".equalsIgnoreCase(ct)) &&
|
if (("text/plain".equalsIgnoreCase(ct) || "text/html".equalsIgnoreCase(ct)) &&
|
||||||
!Part.ATTACHMENT.equalsIgnoreCase(disposition) && TextUtils.isEmpty(filename)) {
|
!Part.ATTACHMENT.equalsIgnoreCase(disposition) && TextUtils.isEmpty(filename)) {
|
||||||
parts.text.add(new PartHolder(parent, part, ct));
|
parts.text.add(new PartHolder(parent, part, contentType));
|
||||||
} else {
|
} else {
|
||||||
if ("message/delivery-status".equalsIgnoreCase(contentType.getBaseType()) ||
|
if ("message/delivery-status".equalsIgnoreCase(contentType.getBaseType()) ||
|
||||||
"message/disposition-notification".equalsIgnoreCase(contentType.getBaseType()))
|
"message/disposition-notification".equalsIgnoreCase(contentType.getBaseType()))
|
||||||
parts.extra.add(new PartHolder(parent, part, ct));
|
parts.extra.add(new PartHolder(parent, part, contentType));
|
||||||
|
|
||||||
AttachmentPart apart = new AttachmentPart();
|
AttachmentPart apart = new AttachmentPart();
|
||||||
apart.disposition = disposition;
|
apart.disposition = disposition;
|
||||||
|
|
Loading…
Reference in New Issue