|
|
@ -740,65 +740,70 @@ public class MessageHelper {
|
|
|
|
Part part;
|
|
|
|
Part part;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MessageParts getMessageParts() throws IOException, MessagingException {
|
|
|
|
MessageParts getMessageParts() throws IOException {
|
|
|
|
MessageParts parts = new MessageParts();
|
|
|
|
MessageParts parts = new MessageParts();
|
|
|
|
getMessageParts(imessage, parts, false); // Can throw ParseException
|
|
|
|
getMessageParts(imessage, parts, false); // Can throw ParseException
|
|
|
|
return parts;
|
|
|
|
return parts;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void getMessageParts(Part part, MessageParts parts, boolean pgp) throws MessagingException, IOException {
|
|
|
|
private void getMessageParts(Part part, MessageParts parts, boolean pgp) throws IOException {
|
|
|
|
if (part.isMimeType("multipart/*")) {
|
|
|
|
try {
|
|
|
|
Multipart multipart = (Multipart) part.getContent();
|
|
|
|
if (part.isMimeType("multipart/*")) {
|
|
|
|
for (int i = 0; i < multipart.getCount(); i++)
|
|
|
|
Multipart multipart = (Multipart) part.getContent();
|
|
|
|
|
|
|
|
for (int i = 0; i < multipart.getCount(); i++)
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
Part cpart = multipart.getBodyPart(i);
|
|
|
|
|
|
|
|
getMessageParts(cpart, parts, pgp);
|
|
|
|
|
|
|
|
ContentType ct = new ContentType(cpart.getContentType());
|
|
|
|
|
|
|
|
if ("application/pgp-encrypted".equals(ct.getBaseType().toLowerCase()))
|
|
|
|
|
|
|
|
pgp = true;
|
|
|
|
|
|
|
|
} catch (ParseException ex) {
|
|
|
|
|
|
|
|
// Nested body: try to continue
|
|
|
|
|
|
|
|
// ParseException: In parameter list boundary="...">, expected parameter name, got ";"
|
|
|
|
|
|
|
|
Log.w(ex);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// https://www.iana.org/assignments/cont-disp/cont-disp.xhtml
|
|
|
|
|
|
|
|
String disposition;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Part cpart = multipart.getBodyPart(i);
|
|
|
|
disposition = part.getDisposition();
|
|
|
|
getMessageParts(cpart, parts, pgp);
|
|
|
|
} catch (MessagingException ex) {
|
|
|
|
ContentType ct = new ContentType(cpart.getContentType());
|
|
|
|
|
|
|
|
if ("application/pgp-encrypted".equals(ct.getBaseType().toLowerCase()))
|
|
|
|
|
|
|
|
pgp = true;
|
|
|
|
|
|
|
|
} catch (ParseException ex) {
|
|
|
|
|
|
|
|
// Nested body: try to continue
|
|
|
|
|
|
|
|
// ParseException: In parameter list boundary="...">, expected parameter name, got ";"
|
|
|
|
|
|
|
|
Log.w(ex);
|
|
|
|
Log.w(ex);
|
|
|
|
|
|
|
|
disposition = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// https://www.iana.org/assignments/cont-disp/cont-disp.xhtml
|
|
|
|
|
|
|
|
String disposition;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
disposition = part.getDisposition();
|
|
|
|
|
|
|
|
} catch (MessagingException ex) {
|
|
|
|
|
|
|
|
Log.w(ex);
|
|
|
|
|
|
|
|
disposition = null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String filename;
|
|
|
|
String filename;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
filename = part.getFileName();
|
|
|
|
filename = part.getFileName();
|
|
|
|
} catch (MessagingException ex) {
|
|
|
|
} catch (MessagingException ex) {
|
|
|
|
Log.w(ex);
|
|
|
|
Log.w(ex);
|
|
|
|
filename = null;
|
|
|
|
filename = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//Log.i("Part" +
|
|
|
|
//Log.i("Part" +
|
|
|
|
// " disposition=" + disposition +
|
|
|
|
// " disposition=" + disposition +
|
|
|
|
// " filename=" + filename +
|
|
|
|
// " filename=" + filename +
|
|
|
|
// " content type=" + part.getContentType());
|
|
|
|
// " content type=" + part.getContentType());
|
|
|
|
|
|
|
|
|
|
|
|
if (!Part.ATTACHMENT.equalsIgnoreCase(disposition) &&
|
|
|
|
if (!Part.ATTACHMENT.equalsIgnoreCase(disposition) &&
|
|
|
|
((parts.plain == null && part.isMimeType("text/plain")) ||
|
|
|
|
((parts.plain == null && part.isMimeType("text/plain")) ||
|
|
|
|
(parts.html == null && part.isMimeType("text/html")))) {
|
|
|
|
(parts.html == null && part.isMimeType("text/html")))) {
|
|
|
|
if (part.isMimeType("text/plain"))
|
|
|
|
if (part.isMimeType("text/plain"))
|
|
|
|
parts.plain = part;
|
|
|
|
parts.plain = part;
|
|
|
|
else
|
|
|
|
else
|
|
|
|
parts.html = part;
|
|
|
|
parts.html = part;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
AttachmentPart apart = new AttachmentPart();
|
|
|
|
AttachmentPart apart = new AttachmentPart();
|
|
|
|
apart.disposition = disposition;
|
|
|
|
apart.disposition = disposition;
|
|
|
|
apart.filename = filename;
|
|
|
|
apart.filename = filename;
|
|
|
|
apart.pgp = pgp;
|
|
|
|
apart.pgp = pgp;
|
|
|
|
apart.part = part;
|
|
|
|
apart.part = part;
|
|
|
|
parts.attachments.add(apart);
|
|
|
|
parts.attachments.add(apart);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (MessagingException ex) {
|
|
|
|
|
|
|
|
Log.w(ex);
|
|
|
|
|
|
|
|
parts.warnings.add(Helper.formatThrowable(ex));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|