@Test public void extractMessage_multipartSigned_UnknownProtocol() throws Exception { Message message = messageFromBody( multipart("signed", "protocol=\"application/pkcs7-signature\"", bodypart("text/plain", "text"), bodypart("application/pkcs7-signature", "signature") ) ); MessageViewInfo messageViewInfo = messageViewInfoExtractor.extractMessageForView(message, null); assertEquals("<pre class=\"k9mail\">text</pre>", messageViewInfo.text); assertNull(messageViewInfo.cryptoResultAnnotation); assertTrue(messageViewInfo.attachments.isEmpty()); assertTrue(messageViewInfo.extraAttachments.isEmpty()); }
@WorkerThread public MessageViewInfo extractMessageForView(Message message, @Nullable MessageCryptoAnnotations cryptoAnnotations) throws MessagingException { ArrayList<Part> extraParts = new ArrayList<>(); Part cryptoContentPart = MessageCryptoStructureDetector.findPrimaryEncryptedOrSignedPart(message, extraParts); if (cryptoContentPart == null) { if (cryptoAnnotations != null && !cryptoAnnotations.isEmpty()) { Timber.e("Got crypto message cryptoContentAnnotations but no crypto root part!"); } return extractSimpleMessageForView(message, message); } boolean isOpenPgpEncrypted = (MessageCryptoStructureDetector.isPartMultipartEncrypted(cryptoContentPart) && MessageCryptoStructureDetector.isMultipartEncryptedOpenPgpProtocol(cryptoContentPart)) || MessageCryptoStructureDetector.isPartPgpInlineEncrypted(cryptoContentPart); boolean isSMimeEncrypted = (MessageCryptoStructureDetector.isPartMultipartEncrypted(cryptoContentPart) && MessageCryptoStructureDetector.isMultipartEncryptedSMimeProtocol(cryptoContentPart)); if ((!QMail.isOpenPgpProviderConfigured() && isOpenPgpEncrypted) || (!QMail.isSMimeProviderConfigured() && isSMimeEncrypted)) { CryptoResultAnnotation noProviderAnnotation = CryptoResultAnnotation.createErrorAnnotation( CryptoError.SMIME_ENCRYPTED_NO_PROVIDER, null); return MessageViewInfo.createWithErrorState(message, false) .withCryptoData(noProviderAnnotation, null, null, null); } CryptoResultAnnotation cryptoContentPartAnnotation = cryptoAnnotations != null ? cryptoAnnotations.get(cryptoContentPart) : null; if (cryptoContentPartAnnotation != null) { return extractCryptoMessageForView(message, extraParts, cryptoContentPart, cryptoContentPartAnnotation); } return extractSimpleMessageForView(message, message); }
MessageViewInfoExtractor { @WorkerThread public MessageViewInfo extractMessageForView(Message message, @Nullable MessageCryptoAnnotations cryptoAnnotations) throws MessagingException { ArrayList<Part> extraParts = new ArrayList<>(); Part cryptoContentPart = MessageCryptoStructureDetector.findPrimaryEncryptedOrSignedPart(message, extraParts); if (cryptoContentPart == null) { if (cryptoAnnotations != null && !cryptoAnnotations.isEmpty()) { Timber.e("Got crypto message cryptoContentAnnotations but no crypto root part!"); } return extractSimpleMessageForView(message, message); } boolean isOpenPgpEncrypted = (MessageCryptoStructureDetector.isPartMultipartEncrypted(cryptoContentPart) && MessageCryptoStructureDetector.isMultipartEncryptedOpenPgpProtocol(cryptoContentPart)) || MessageCryptoStructureDetector.isPartPgpInlineEncrypted(cryptoContentPart); boolean isSMimeEncrypted = (MessageCryptoStructureDetector.isPartMultipartEncrypted(cryptoContentPart) && MessageCryptoStructureDetector.isMultipartEncryptedSMimeProtocol(cryptoContentPart)); if ((!QMail.isOpenPgpProviderConfigured() && isOpenPgpEncrypted) || (!QMail.isSMimeProviderConfigured() && isSMimeEncrypted)) { CryptoResultAnnotation noProviderAnnotation = CryptoResultAnnotation.createErrorAnnotation( CryptoError.SMIME_ENCRYPTED_NO_PROVIDER, null); return MessageViewInfo.createWithErrorState(message, false) .withCryptoData(noProviderAnnotation, null, null, null); } CryptoResultAnnotation cryptoContentPartAnnotation = cryptoAnnotations != null ? cryptoAnnotations.get(cryptoContentPart) : null; if (cryptoContentPartAnnotation != null) { return extractCryptoMessageForView(message, extraParts, cryptoContentPart, cryptoContentPartAnnotation); } return extractSimpleMessageForView(message, message); } }
MessageViewInfoExtractor { @WorkerThread public MessageViewInfo extractMessageForView(Message message, @Nullable MessageCryptoAnnotations cryptoAnnotations) throws MessagingException { ArrayList<Part> extraParts = new ArrayList<>(); Part cryptoContentPart = MessageCryptoStructureDetector.findPrimaryEncryptedOrSignedPart(message, extraParts); if (cryptoContentPart == null) { if (cryptoAnnotations != null && !cryptoAnnotations.isEmpty()) { Timber.e("Got crypto message cryptoContentAnnotations but no crypto root part!"); } return extractSimpleMessageForView(message, message); } boolean isOpenPgpEncrypted = (MessageCryptoStructureDetector.isPartMultipartEncrypted(cryptoContentPart) && MessageCryptoStructureDetector.isMultipartEncryptedOpenPgpProtocol(cryptoContentPart)) || MessageCryptoStructureDetector.isPartPgpInlineEncrypted(cryptoContentPart); boolean isSMimeEncrypted = (MessageCryptoStructureDetector.isPartMultipartEncrypted(cryptoContentPart) && MessageCryptoStructureDetector.isMultipartEncryptedSMimeProtocol(cryptoContentPart)); if ((!QMail.isOpenPgpProviderConfigured() && isOpenPgpEncrypted) || (!QMail.isSMimeProviderConfigured() && isSMimeEncrypted)) { CryptoResultAnnotation noProviderAnnotation = CryptoResultAnnotation.createErrorAnnotation( CryptoError.SMIME_ENCRYPTED_NO_PROVIDER, null); return MessageViewInfo.createWithErrorState(message, false) .withCryptoData(noProviderAnnotation, null, null, null); } CryptoResultAnnotation cryptoContentPartAnnotation = cryptoAnnotations != null ? cryptoAnnotations.get(cryptoContentPart) : null; if (cryptoContentPartAnnotation != null) { return extractCryptoMessageForView(message, extraParts, cryptoContentPart, cryptoContentPartAnnotation); } return extractSimpleMessageForView(message, message); } @VisibleForTesting  MessageViewInfoExtractor(Context context, AttachmentInfoExtractor attachmentInfoExtractor,
            ICalendarInfoExtractor iCalendarInfoExtractor, HtmlProcessor htmlProcessor); }
MessageViewInfoExtractor { @WorkerThread public MessageViewInfo extractMessageForView(Message message, @Nullable MessageCryptoAnnotations cryptoAnnotations) throws MessagingException { ArrayList<Part> extraParts = new ArrayList<>(); Part cryptoContentPart = MessageCryptoStructureDetector.findPrimaryEncryptedOrSignedPart(message, extraParts); if (cryptoContentPart == null) { if (cryptoAnnotations != null && !cryptoAnnotations.isEmpty()) { Timber.e("Got crypto message cryptoContentAnnotations but no crypto root part!"); } return extractSimpleMessageForView(message, message); } boolean isOpenPgpEncrypted = (MessageCryptoStructureDetector.isPartMultipartEncrypted(cryptoContentPart) && MessageCryptoStructureDetector.isMultipartEncryptedOpenPgpProtocol(cryptoContentPart)) || MessageCryptoStructureDetector.isPartPgpInlineEncrypted(cryptoContentPart); boolean isSMimeEncrypted = (MessageCryptoStructureDetector.isPartMultipartEncrypted(cryptoContentPart) && MessageCryptoStructureDetector.isMultipartEncryptedSMimeProtocol(cryptoContentPart)); if ((!QMail.isOpenPgpProviderConfigured() && isOpenPgpEncrypted) || (!QMail.isSMimeProviderConfigured() && isSMimeEncrypted)) { CryptoResultAnnotation noProviderAnnotation = CryptoResultAnnotation.createErrorAnnotation( CryptoError.SMIME_ENCRYPTED_NO_PROVIDER, null); return MessageViewInfo.createWithErrorState(message, false) .withCryptoData(noProviderAnnotation, null, null, null); } CryptoResultAnnotation cryptoContentPartAnnotation = cryptoAnnotations != null ? cryptoAnnotations.get(cryptoContentPart) : null; if (cryptoContentPartAnnotation != null) { return extractCryptoMessageForView(message, extraParts, cryptoContentPart, cryptoContentPartAnnotation); } return extractSimpleMessageForView(message, message); } @VisibleForTesting  MessageViewInfoExtractor(Context context, AttachmentInfoExtractor attachmentInfoExtractor,
            ICalendarInfoExtractor iCalendarInfoExtractor, HtmlProcessor htmlProcessor); static MessageViewInfoExtractor getInstance(); @WorkerThread MessageViewInfo extractMessageForView(Message message, @Nullable MessageCryptoAnnotations cryptoAnnotations); }
MessageViewInfoExtractor { @WorkerThread public MessageViewInfo extractMessageForView(Message message, @Nullable MessageCryptoAnnotations cryptoAnnotations) throws MessagingException { ArrayList<Part> extraParts = new ArrayList<>(); Part cryptoContentPart = MessageCryptoStructureDetector.findPrimaryEncryptedOrSignedPart(message, extraParts); if (cryptoContentPart == null) { if (cryptoAnnotations != null && !cryptoAnnotations.isEmpty()) { Timber.e("Got crypto message cryptoContentAnnotations but no crypto root part!"); } return extractSimpleMessageForView(message, message); } boolean isOpenPgpEncrypted = (MessageCryptoStructureDetector.isPartMultipartEncrypted(cryptoContentPart) && MessageCryptoStructureDetector.isMultipartEncryptedOpenPgpProtocol(cryptoContentPart)) || MessageCryptoStructureDetector.isPartPgpInlineEncrypted(cryptoContentPart); boolean isSMimeEncrypted = (MessageCryptoStructureDetector.isPartMultipartEncrypted(cryptoContentPart) && MessageCryptoStructureDetector.isMultipartEncryptedSMimeProtocol(cryptoContentPart)); if ((!QMail.isOpenPgpProviderConfigured() && isOpenPgpEncrypted) || (!QMail.isSMimeProviderConfigured() && isSMimeEncrypted)) { CryptoResultAnnotation noProviderAnnotation = CryptoResultAnnotation.createErrorAnnotation( CryptoError.SMIME_ENCRYPTED_NO_PROVIDER, null); return MessageViewInfo.createWithErrorState(message, false) .withCryptoData(noProviderAnnotation, null, null, null); } CryptoResultAnnotation cryptoContentPartAnnotation = cryptoAnnotations != null ? cryptoAnnotations.get(cryptoContentPart) : null; if (cryptoContentPartAnnotation != null) { return extractCryptoMessageForView(message, extraParts, cryptoContentPart, cryptoContentPartAnnotation); } return extractSimpleMessageForView(message, message); } @VisibleForTesting  MessageViewInfoExtractor(Context context, AttachmentInfoExtractor attachmentInfoExtractor,
            ICalendarInfoExtractor iCalendarInfoExtractor, HtmlProcessor htmlProcessor); static MessageViewInfoExtractor getInstance(); @WorkerThread MessageViewInfo extractMessageForView(Message message, @Nullable MessageCryptoAnnotations cryptoAnnotations);  }