mirror of
https://github.com/M66B/FairEmail.git
synced 2026-04-27 11:16:51 +02:00
Recognize S/MIME
This commit is contained in:
@@ -1604,7 +1604,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
||||
has_inline = true;
|
||||
if (Objects.equals(attachment.encryption, EntityAttachment.PGP_MESSAGE))
|
||||
is_encrypted = true;
|
||||
if (Objects.equals(attachment.encryption, EntityAttachment.PGP_CONTENT))
|
||||
if (Objects.equals(attachment.encryption, EntityAttachment.PGP_SIGNATURE))
|
||||
is_signed = true;
|
||||
if (attachment.progress == null && !attachment.available)
|
||||
download = true;
|
||||
|
||||
@@ -2147,10 +2147,15 @@ class Core {
|
||||
attachment.message = message.id;
|
||||
attachment.sequence = sequence++;
|
||||
attachment.id = db.attachment().insertAttachment(attachment);
|
||||
|
||||
if (EntityAttachment.PGP_SIGNATURE.equals(attachment.encryption))
|
||||
db.message().setMessageEncrypt(message.id, EntityMessage.PGP_SIGNONLY);
|
||||
else if (EntityAttachment.PGP_MESSAGE.equals(attachment.encryption))
|
||||
db.message().setMessageEncrypt(message.id, EntityMessage.PGP_SIGNENCRYPT);
|
||||
else if (EntityAttachment.SMIME_SIGNATURE.equals(attachment.encryption))
|
||||
db.message().setMessageEncrypt(message.id, EntityMessage.SMIME_SIGNONLY);
|
||||
else if (EntityAttachment.SMIME_MESSAGE.equals(attachment.encryption))
|
||||
db.message().setMessageEncrypt(message.id, EntityMessage.SMIME_SIGNENCRYPT);
|
||||
}
|
||||
|
||||
runRules(context, imessage, message, rules);
|
||||
|
||||
@@ -51,8 +51,8 @@ public interface DaoMessage {
|
||||
", SUM(1 - message.ui_seen) AS unseen" +
|
||||
", SUM(1 - message.ui_flagged) AS unflagged" +
|
||||
", SUM(folder.type = '" + EntityFolder.DRAFTS + "') AS drafts" +
|
||||
", SUM(message.encrypt = 2) AS signed" +
|
||||
", SUM(message.encrypt = 1) AS encrypted" +
|
||||
", SUM(message.encrypt IN (2, 4)) AS signed" +
|
||||
", SUM(message.encrypt IN (1, 3)) AS encrypted" +
|
||||
", COUNT(DISTINCT CASE WHEN message.msgid IS NULL THEN message.id ELSE message.msgid END) AS visible" +
|
||||
", SUM(message.total) AS totalSize" +
|
||||
", MAX(CASE WHEN" +
|
||||
@@ -102,8 +102,8 @@ public interface DaoMessage {
|
||||
", SUM(1 - message.ui_seen) AS unseen" +
|
||||
", SUM(1 - message.ui_flagged) AS unflagged" +
|
||||
", SUM(folder.type = '" + EntityFolder.DRAFTS + "') AS drafts" +
|
||||
", SUM(message.encrypt = 2) AS signed" +
|
||||
", SUM(message.encrypt = 1) AS encrypted" +
|
||||
", SUM(message.encrypt IN (2, 4)) AS signed" +
|
||||
", SUM(message.encrypt IN (1, 3)) AS encrypted" +
|
||||
", COUNT(DISTINCT CASE WHEN message.msgid IS NULL THEN message.id ELSE message.msgid END) AS visible" +
|
||||
", SUM(message.total) AS totalSize" +
|
||||
", MAX(CASE WHEN folder.id = :folder THEN message.received ELSE 0 END) AS dummy" +
|
||||
@@ -147,8 +147,8 @@ public interface DaoMessage {
|
||||
", CASE WHEN message.ui_seen THEN 0 ELSE 1 END AS unseen" +
|
||||
", CASE WHEN message.ui_flagged THEN 0 ELSE 1 END AS unflagged" +
|
||||
", (folder.type = '" + EntityFolder.DRAFTS + "') AS drafts" +
|
||||
", (message.encrypt = 2) AS signed" +
|
||||
", (message.encrypt = 1) AS encrypted" +
|
||||
", (message.encrypt IN (2, 4)) AS signed" +
|
||||
", (message.encrypt IN (1, 3)) AS encrypted" +
|
||||
", 1 AS visible" +
|
||||
", message.total AS totalSize" +
|
||||
" FROM message" +
|
||||
@@ -287,8 +287,8 @@ public interface DaoMessage {
|
||||
", CASE WHEN message.ui_seen THEN 0 ELSE 1 END AS unseen" +
|
||||
", CASE WHEN message.ui_flagged THEN 0 ELSE 1 END AS unflagged" +
|
||||
", (folder.type = '" + EntityFolder.DRAFTS + "') AS drafts" +
|
||||
", (message.encrypt = 2) AS signed" +
|
||||
", (message.encrypt = 1) AS encrypted" +
|
||||
", (message.encrypt IN (2, 4)) AS signed" +
|
||||
", (message.encrypt IN (1, 3)) AS encrypted" +
|
||||
", 1 AS visible" +
|
||||
", message.total AS totalSize" +
|
||||
" FROM message" +
|
||||
@@ -322,8 +322,8 @@ public interface DaoMessage {
|
||||
", 1 AS unseen" +
|
||||
", 0 AS unflagged" +
|
||||
", 0 AS drafts" +
|
||||
", (message.encrypt = 2) AS signed" +
|
||||
", (message.encrypt = 1) AS encrypted" +
|
||||
", (message.encrypt IN (2, 4)) AS signed" +
|
||||
", (message.encrypt IN (1, 3)) AS encrypted" +
|
||||
", 1 AS visible" +
|
||||
", message.total AS totalSize" +
|
||||
" FROM message" +
|
||||
|
||||
@@ -60,6 +60,9 @@ public class EntityAttachment {
|
||||
static final Integer PGP_SIGNATURE = 2;
|
||||
static final Integer PGP_KEY = 3;
|
||||
static final Integer PGP_CONTENT = 4;
|
||||
static final Integer SMIME_MESSAGE = 5;
|
||||
static final Integer SMIME_SIGNATURE = 6;
|
||||
static final Integer SMIME_CONTENT = 8;
|
||||
|
||||
// https://developer.android.com/guide/topics/media/media-formats#image-formats
|
||||
private static final List<String> IMAGE_TYPES = Collections.unmodifiableList(Arrays.asList(
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user