Skip to content

NullPointerException in SmimeUtilFixed when protocol is missing (which is valid) #292

@Faelean

Description

@Faelean

When using the outlookMsgToEmailBuilder function

public static EmailFromOutlookMessage outlookMsgToEmailBuilder(@NotNull final InputStream msgInputStream) {

I sometimes get this error message:

org.simplejavamail.internal.smimesupport.SmimeException: Error unwrapping S/MIME enveloped attachment: 
	AttachmentResource{
		name='smime.p7s',
		dataSource.name=smime.p7s,
		dataSource.getContentType=multipart/signed
	}

This is caused by a Nullpointer in this function when the contentType in the calling function does not contain the parameter protocol:

private static boolean isSmimeSignatureProtocoll(String protocol) {
return protocol.equalsIgnoreCase("application/pkcs7-signature")
|| protocol.equalsIgnoreCase("application/x-pkcs7-signature");
}

private static boolean isSmimeSignatureContentType(ContentType contentType) {
String baseContentType = contentType.getBaseType();
return baseContentType.equalsIgnoreCase("multipart/signed")
&& isSmimeSignatureProtocoll(contentType.getParameter("protocol"));
}

I haven't been able to create an email with this problem myself (if necessary I can obtain one) but here is the way we handle these emails:

  • Drag & Drop from Outlook to a Browser
  • Transfer the file to a server
  • Convert the file to a ByteArrayInputStream
  • Call outlookMsgToEmailBuilder with that InputStream

I don't know why these mails don't contain a protocol, but the easiest way to prevent the NullPointer would be to make the isSmimeSignatureProtocoll function nullsave by using protocol as input parameter for equalsIgnoreCase:

"application/pkcs7-signature".equalsIgnoreCase(protocol) || "application/x-pkcs7-signature".equalsIgnoreCase(protocol)

This would change the NullPointer to a false.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions