Skip to content

Commit c019d30

Browse files
committed
#8: Added heuristics and SmimeState to indicate probably signed messages, as the content-type is "multipart/signed", but the (S/MIME) protocol parameter is missing.
1 parent 61970a4 commit c019d30

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

src/main/java/org/simplejavamail/utils/mail/smime/SmimeState.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ public enum SmimeState {
1818
* encrypted.
1919
*/
2020
ENCRYPTED,
21-
21+
22+
/**
23+
* Indicates that the {@link MimePart} or {@link MimeMultipart} is probably S/MIME
24+
* signed (type was multipart/signed, but protocol was missing).
25+
*/
26+
PROBABLY_SIGNED,
27+
2228
/**
2329
* Indicates that the {@link MimePart} or {@link MimeMultipart} is S/MIME
2430
* signed.

src/main/java/org/simplejavamail/utils/mail/smime/SmimeUtil.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,8 @@ public static SmimeState getStatus(MimePart mimePart) {
656656
private static SmimeState getStatus(ContentType contentType) {
657657
if (isSmimeSignatureContentType(contentType)) {
658658
return SmimeState.SIGNED;
659+
} if (isProbablySmimeSignatureContentType(contentType)) {
660+
return SmimeState.PROBABLY_SIGNED;
659661
} else if (isSignatureSmimeType(contentType)) {
660662
return SmimeState.SIGNED_ENVELOPED;
661663
} else if (isSmimeEncryptionContenttype(contentType)) {
@@ -672,12 +674,16 @@ private static boolean isSmimeEncryptionContenttype(ContentType contentType) {
672674
}
673675

674676
private static boolean isSmimeSignatureContentType(ContentType contentType) {
675-
String baseContentType = contentType.getBaseType();
676677
String protocol = contentType.getParameter("protocol");
677-
return baseContentType.equalsIgnoreCase("multipart/signed")
678+
return contentType.getBaseType().equalsIgnoreCase("multipart/signed")
678679
&& protocol != null && isSmimeSignatureProtocoll(protocol);
679680
}
680681

682+
private static boolean isProbablySmimeSignatureContentType(ContentType contentType) {
683+
String protocol = contentType.getParameter("protocol");
684+
return contentType.getBaseType().equalsIgnoreCase("multipart/signed") && protocol == null;
685+
}
686+
681687
private static boolean isSignatureSmimeType(ContentType contentType) {
682688
String baseContentType = contentType.getBaseType();
683689
return baseContentType.equalsIgnoreCase("application/x-pkcs7-mime")

0 commit comments

Comments
 (0)