mirror of https://github.com/M66B/FairEmail.git
Try parse string multipart
This commit is contained in:
parent
e8c0427141
commit
a23f535bb9
|
@ -107,6 +107,7 @@ import java.util.regex.Matcher;
|
|||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.activation.DataHandler;
|
||||
import javax.activation.DataSource;
|
||||
import javax.activation.FileDataSource;
|
||||
import javax.activation.FileTypeMap;
|
||||
import javax.mail.Address;
|
||||
|
@ -4051,6 +4052,10 @@ public class MessageHelper {
|
|||
|
||||
if (part.isMimeType("multipart/mixed")) {
|
||||
Object content = part.getContent();
|
||||
|
||||
if (content instanceof String)
|
||||
content = tryParseMultipart((String) content, part.getContentType());
|
||||
|
||||
if (content instanceof Multipart) {
|
||||
Multipart mp = (Multipart) content;
|
||||
for (int i = 0; i < mp.getCount(); i++) {
|
||||
|
@ -4074,6 +4079,10 @@ public class MessageHelper {
|
|||
"application/pkcs7-signature".equals(protocol) ||
|
||||
"application/x-pkcs7-signature".equals(protocol)) {
|
||||
Object content = part.getContent();
|
||||
|
||||
if (content instanceof String)
|
||||
content = tryParseMultipart((String) content, part.getContentType());
|
||||
|
||||
if (content instanceof Multipart) {
|
||||
Multipart multipart = (Multipart) content;
|
||||
if (multipart.getCount() == 2) {
|
||||
|
@ -4120,6 +4129,10 @@ public class MessageHelper {
|
|||
String protocol = ct.getParameter("protocol");
|
||||
if ("application/pgp-encrypted".equals(protocol) || protocol == null) {
|
||||
Object content = part.getContent();
|
||||
|
||||
if (content instanceof String)
|
||||
content = tryParseMultipart((String) content, part.getContentType());
|
||||
|
||||
if (content instanceof Multipart) {
|
||||
Multipart multipart = (Multipart) content;
|
||||
if (multipart.getCount() == 2) {
|
||||
|
@ -4218,6 +4231,10 @@ public class MessageHelper {
|
|||
if (part.isMimeType("multipart/*")) {
|
||||
Multipart multipart;
|
||||
Object content = part.getContent(); // Should always be Multipart
|
||||
|
||||
if (content instanceof String)
|
||||
content = tryParseMultipart((String) content, part.getContentType());
|
||||
|
||||
if (content instanceof Multipart) {
|
||||
multipart = (Multipart) part.getContent();
|
||||
int count = multipart.getCount();
|
||||
|
@ -4374,6 +4391,35 @@ public class MessageHelper {
|
|||
}
|
||||
}
|
||||
|
||||
private Object tryParseMultipart(String text, String contentType) {
|
||||
try {
|
||||
return new MimeMultipart(new DataSource() {
|
||||
@Override
|
||||
public InputStream getInputStream() throws IOException {
|
||||
return new ByteArrayInputStream(text.getBytes(StandardCharsets.ISO_8859_1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public OutputStream getOutputStream() throws IOException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getContentType() {
|
||||
return contentType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "String";
|
||||
}
|
||||
});
|
||||
} catch (MessagingException ex) {
|
||||
Log.e(ex);
|
||||
return text;
|
||||
}
|
||||
}
|
||||
|
||||
private void ensureEnvelope() throws MessagingException {
|
||||
_ensureMessage(false, false);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue