From b39a7e852dae83a342ab8db683860f51c09bb142 Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 2 Dec 2019 08:35:09 +0100 Subject: [PATCH] Recognize S/MIME --- .../eu/faircode/email/AdapterMessage.java | 2 +- app/src/main/java/eu/faircode/email/Core.java | 5 ++ .../java/eu/faircode/email/DaoMessage.java | 20 +++--- .../eu/faircode/email/EntityAttachment.java | 3 + .../java/eu/faircode/email/EntityMessage.java | 2 + .../eu/faircode/email/EntityOperation.java | 4 +- .../eu/faircode/email/FragmentCompose.java | 1 - .../java/eu/faircode/email/MessageHelper.java | 65 ++++++++++++------- 8 files changed, 66 insertions(+), 36 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/AdapterMessage.java b/app/src/main/java/eu/faircode/email/AdapterMessage.java index 52149fe18c..d37d08fdff 100644 --- a/app/src/main/java/eu/faircode/email/AdapterMessage.java +++ b/app/src/main/java/eu/faircode/email/AdapterMessage.java @@ -1604,7 +1604,7 @@ public class AdapterMessage extends RecyclerView.Adapter IMAGE_TYPES = Collections.unmodifiableList(Arrays.asList( diff --git a/app/src/main/java/eu/faircode/email/EntityMessage.java b/app/src/main/java/eu/faircode/email/EntityMessage.java index c41d8dee6f..539f648738 100644 --- a/app/src/main/java/eu/faircode/email/EntityMessage.java +++ b/app/src/main/java/eu/faircode/email/EntityMessage.java @@ -83,6 +83,8 @@ public class EntityMessage implements Serializable { static final Integer ENCRYPT_NONE = 0; static final Integer PGP_SIGNENCRYPT = 1; static final Integer PGP_SIGNONLY = 2; + static final Integer SMIME_SIGNENCRYPT = 3; + static final Integer SMIME_SIGNONLY = 4; static final Integer PRIORITIY_LOW = 0; static final Integer PRIORITIY_NORMAL = 1; diff --git a/app/src/main/java/eu/faircode/email/EntityOperation.java b/app/src/main/java/eu/faircode/email/EntityOperation.java index 0a50967b0f..8fc537ebd6 100644 --- a/app/src/main/java/eu/faircode/email/EntityOperation.java +++ b/app/src/main/java/eu/faircode/email/EntityOperation.java @@ -121,7 +121,9 @@ public class EntityOperation { for (Object value : values) jargs.put(value); - if (MOVE.equals(name) && EntityMessage.PGP_SIGNENCRYPT.equals(message.encrypt)) { + if (MOVE.equals(name) && + (EntityMessage.PGP_SIGNENCRYPT.equals(message.encrypt) || + EntityMessage.SMIME_SIGNENCRYPT.equals(message.encrypt))) { EntityFolder folder = db.folder().getFolder(message.folder); if (folder != null && EntityFolder.DRAFTS.equals(folder.type)) name = DELETE; diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index 127a619b4c..8aa322b222 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -1225,7 +1225,6 @@ public class FragmentCompose extends FragmentBase { Intent intent; if (EntityMessage.PGP_SIGNONLY.equals(draft.encrypt)) { - // TODO use previously selected sign key intent = new Intent(OpenPgpApi.ACTION_GET_SIGN_KEY_ID); intent.putExtra(BuildConfig.APPLICATION_ID, working); } else if (EntityMessage.PGP_SIGNENCRYPT.equals(draft.encrypt)) { diff --git a/app/src/main/java/eu/faircode/email/MessageHelper.java b/app/src/main/java/eu/faircode/email/MessageHelper.java index 367f6f422f..63a308ea30 100644 --- a/app/src/main/java/eu/faircode/email/MessageHelper.java +++ b/app/src/main/java/eu/faircode/email/MessageHelper.java @@ -1276,35 +1276,54 @@ public class MessageHelper { try { if (imessage.isMimeType("multipart/signed")) { - Multipart multipart = (Multipart) imessage.getContent(); - if (multipart.getCount() == 2) { - getMessageParts(multipart.getBodyPart(0), parts, null); - getMessageParts(multipart.getBodyPart(1), parts, EntityAttachment.PGP_SIGNATURE); + ContentType ct = new ContentType(imessage.getContentType()); + String protocol = ct.getParameter("protocol"); + if ("application/pgp-signature".equals(protocol) || + "application/pkcs7-signature".equals(protocol)) { + Multipart multipart = (Multipart) imessage.getContent(); + if (multipart.getCount() == 2) { + getMessageParts(multipart.getBodyPart(0), parts, null); + getMessageParts(multipart.getBodyPart(1), parts, + "application/pgp-signature".equals(protocol) + ? EntityAttachment.PGP_SIGNATURE + : EntityAttachment.SMIME_SIGNATURE); - AttachmentPart apart = new AttachmentPart(); - apart.disposition = Part.INLINE; - apart.filename = "content.asc"; - apart.encrypt = EntityAttachment.PGP_CONTENT; - apart.part = imessage; + AttachmentPart apart = new AttachmentPart(); + apart.disposition = Part.INLINE; + apart.filename = "content.asc"; + apart.encrypt = "application/pgp-signature".equals(protocol) + ? EntityAttachment.PGP_CONTENT + : EntityAttachment.SMIME_CONTENT; + apart.part = imessage; - ContentType ct = new ContentType(multipart.getBodyPart(0).getContentType()); + apart.attachment = new EntityAttachment(); + apart.attachment.disposition = apart.disposition; + apart.attachment.name = apart.filename; + apart.attachment.type = "text/plain"; + apart.attachment.size = getSize(); + apart.attachment.encryption = apart.encrypt; - apart.attachment = new EntityAttachment(); - apart.attachment.disposition = apart.disposition; - apart.attachment.name = apart.filename; - apart.attachment.type = "text/plain"; - apart.attachment.size = getSize(); - apart.attachment.encryption = apart.encrypt; + parts.attachments.add(apart); - parts.attachments.add(apart); - - return parts; + return parts; + } } } else if (imessage.isMimeType("multipart/encrypted")) { - Multipart multipart = (Multipart) imessage.getContent(); - if (multipart.getCount() == 2) { - // Ignore header - getMessageParts(multipart.getBodyPart(1), parts, EntityAttachment.PGP_MESSAGE); + ContentType ct = new ContentType(imessage.getContentType()); + String protocol = ct.getParameter("protocol"); + if ("application/pgp-encrypted".equals(protocol)) { + Multipart multipart = (Multipart) imessage.getContent(); + if (multipart.getCount() == 2) { + // Ignore header + getMessageParts(multipart.getBodyPart(1), parts, EntityAttachment.PGP_MESSAGE); + return parts; + } + } + } else if (imessage.isMimeType("application/pkcs7-mime")) { + ContentType ct = new ContentType(imessage.getContentType()); + String smimeType = ct.getParameter("smime-type"); + if ("enveloped-data".equals(smimeType)) { + getMessageParts(imessage, parts, EntityAttachment.SMIME_MESSAGE); return parts; } }