Loading k9mail/src/main/java/com/fsck/k9/message/PgpMessageBuilder.java +4 −8 Original line number Diff line number Diff line Loading @@ -41,7 +41,6 @@ import org.openintents.openpgp.util.OpenPgpApi.OpenPgpDataSource; public class PgpMessageBuilder extends MessageBuilder { private static final int REQUEST_USER_INTERACTION = 1; private OpenPgpApi openPgpApi; private MimeMessage currentProcessedMimeMessage; Loading Loading @@ -115,16 +114,12 @@ public class PgpMessageBuilder extends MessageBuilder { throw new MessagingException("Attachments are not supported in PGP/INLINE format!"); } if (isPgpInlineMode && shouldSign && !shouldEncrypt) { throw new UnsupportedOperationException("Clearsigning is not supported!"); } if (pgpApiIntent == null) { pgpApiIntent = buildOpenPgpApiIntent(shouldSign, shouldEncrypt, isPgpInlineMode); } PendingIntent returnedPendingIntent = launchOpenPgpApiIntent( pgpApiIntent, shouldEncrypt, isPgpInlineMode); pgpApiIntent, shouldEncrypt || isPgpInlineMode, shouldEncrypt || !isPgpInlineMode, isPgpInlineMode); if (returnedPendingIntent != null) { queueMessageBuildPendingIntent(returnedPendingIntent, REQUEST_USER_INTERACTION); return; Loading Loading @@ -174,7 +169,7 @@ public class PgpMessageBuilder extends MessageBuilder { } private PendingIntent launchOpenPgpApiIntent(@NonNull Intent openPgpIntent, boolean captureOutputPart, boolean writeBodyContentOnly) throws MessagingException { boolean captureOutputPart, boolean capturedOutputPartIs7Bit, boolean writeBodyContentOnly) throws MessagingException { final MimeBodyPart bodyPart = currentProcessedMimeMessage.toBodyPart(); String[] contentType = currentProcessedMimeMessage.getHeader(MimeHeader.HEADER_CONTENT_TYPE); if (contentType.length > 0) { Loading @@ -187,7 +182,8 @@ public class PgpMessageBuilder extends MessageBuilder { OutputStream outputStream = null; if (captureOutputPart) { try { pgpResultTempBody = new BinaryTempFileBody(MimeUtil.ENC_7BIT); pgpResultTempBody = new BinaryTempFileBody( capturedOutputPartIs7Bit ? MimeUtil.ENC_7BIT : MimeUtil.ENC_8BIT); outputStream = pgpResultTempBody.getOutputStream(); // OpenKeychain/BouncyCastle at this point use the system newline for formatting, which is LF on android. // we need this to be CRLF, so we convert the data after receiving. Loading k9mail/src/test/java/com/fsck/k9/message/PgpMessageBuilderTest.java +22 −2 Original line number Diff line number Diff line Loading @@ -343,8 +343,8 @@ public class PgpMessageBuilderTest { Assert.assertEquals(MimeUtil.ENC_7BIT, ((BinaryTempFileBody) message.getBody()).getEncoding()); } @Test(expected = RuntimeException.class) // this is a wrapped UnsupportedOperationException from AsyncTask public void buildSign__withInlineEnabled__shouldFail() throws MessagingException { @Test public void buildSign__withInlineEnabled__shouldSucceed() throws MessagingException { ComposeCryptoStatus cryptoStatus = cryptoStatusBuilder .setCryptoMode(CryptoMode.SIGN_ONLY) .setRecipients(Collections.singletonList(new Recipient("test", "test@example.org", "labru", -1, "key"))) Loading @@ -352,8 +352,28 @@ public class PgpMessageBuilderTest { .build(); pgpMessageBuilder.setCryptoStatus(cryptoStatus); ArgumentCaptor<Intent> capturedApiIntent = ArgumentCaptor.forClass(Intent.class); Intent returnIntent = new Intent(); returnIntent.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_SUCCESS); when(openPgpApi.executeApi(capturedApiIntent.capture(), any(OpenPgpDataSource.class), any(OutputStream.class))) .thenReturn(returnIntent); Callback mockCallback = mock(Callback.class); pgpMessageBuilder.buildAsync(mockCallback); Intent expectedApiIntent = new Intent(OpenPgpApi.ACTION_SIGN); expectedApiIntent.putExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID, TEST_SIGN_KEY_ID); expectedApiIntent.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true); assertIntentEqualsActionAndExtras(expectedApiIntent, capturedApiIntent.getValue()); ArgumentCaptor<MimeMessage> captor = ArgumentCaptor.forClass(MimeMessage.class); verify(mockCallback).onMessageBuildSuccess(captor.capture(), eq(false)); verifyNoMoreInteractions(mockCallback); MimeMessage message = captor.getValue(); Assert.assertEquals("message must be text/plain", "text/plain", message.getMimeType()); } @Test Loading Loading
k9mail/src/main/java/com/fsck/k9/message/PgpMessageBuilder.java +4 −8 Original line number Diff line number Diff line Loading @@ -41,7 +41,6 @@ import org.openintents.openpgp.util.OpenPgpApi.OpenPgpDataSource; public class PgpMessageBuilder extends MessageBuilder { private static final int REQUEST_USER_INTERACTION = 1; private OpenPgpApi openPgpApi; private MimeMessage currentProcessedMimeMessage; Loading Loading @@ -115,16 +114,12 @@ public class PgpMessageBuilder extends MessageBuilder { throw new MessagingException("Attachments are not supported in PGP/INLINE format!"); } if (isPgpInlineMode && shouldSign && !shouldEncrypt) { throw new UnsupportedOperationException("Clearsigning is not supported!"); } if (pgpApiIntent == null) { pgpApiIntent = buildOpenPgpApiIntent(shouldSign, shouldEncrypt, isPgpInlineMode); } PendingIntent returnedPendingIntent = launchOpenPgpApiIntent( pgpApiIntent, shouldEncrypt, isPgpInlineMode); pgpApiIntent, shouldEncrypt || isPgpInlineMode, shouldEncrypt || !isPgpInlineMode, isPgpInlineMode); if (returnedPendingIntent != null) { queueMessageBuildPendingIntent(returnedPendingIntent, REQUEST_USER_INTERACTION); return; Loading Loading @@ -174,7 +169,7 @@ public class PgpMessageBuilder extends MessageBuilder { } private PendingIntent launchOpenPgpApiIntent(@NonNull Intent openPgpIntent, boolean captureOutputPart, boolean writeBodyContentOnly) throws MessagingException { boolean captureOutputPart, boolean capturedOutputPartIs7Bit, boolean writeBodyContentOnly) throws MessagingException { final MimeBodyPart bodyPart = currentProcessedMimeMessage.toBodyPart(); String[] contentType = currentProcessedMimeMessage.getHeader(MimeHeader.HEADER_CONTENT_TYPE); if (contentType.length > 0) { Loading @@ -187,7 +182,8 @@ public class PgpMessageBuilder extends MessageBuilder { OutputStream outputStream = null; if (captureOutputPart) { try { pgpResultTempBody = new BinaryTempFileBody(MimeUtil.ENC_7BIT); pgpResultTempBody = new BinaryTempFileBody( capturedOutputPartIs7Bit ? MimeUtil.ENC_7BIT : MimeUtil.ENC_8BIT); outputStream = pgpResultTempBody.getOutputStream(); // OpenKeychain/BouncyCastle at this point use the system newline for formatting, which is LF on android. // we need this to be CRLF, so we convert the data after receiving. Loading
k9mail/src/test/java/com/fsck/k9/message/PgpMessageBuilderTest.java +22 −2 Original line number Diff line number Diff line Loading @@ -343,8 +343,8 @@ public class PgpMessageBuilderTest { Assert.assertEquals(MimeUtil.ENC_7BIT, ((BinaryTempFileBody) message.getBody()).getEncoding()); } @Test(expected = RuntimeException.class) // this is a wrapped UnsupportedOperationException from AsyncTask public void buildSign__withInlineEnabled__shouldFail() throws MessagingException { @Test public void buildSign__withInlineEnabled__shouldSucceed() throws MessagingException { ComposeCryptoStatus cryptoStatus = cryptoStatusBuilder .setCryptoMode(CryptoMode.SIGN_ONLY) .setRecipients(Collections.singletonList(new Recipient("test", "test@example.org", "labru", -1, "key"))) Loading @@ -352,8 +352,28 @@ public class PgpMessageBuilderTest { .build(); pgpMessageBuilder.setCryptoStatus(cryptoStatus); ArgumentCaptor<Intent> capturedApiIntent = ArgumentCaptor.forClass(Intent.class); Intent returnIntent = new Intent(); returnIntent.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_SUCCESS); when(openPgpApi.executeApi(capturedApiIntent.capture(), any(OpenPgpDataSource.class), any(OutputStream.class))) .thenReturn(returnIntent); Callback mockCallback = mock(Callback.class); pgpMessageBuilder.buildAsync(mockCallback); Intent expectedApiIntent = new Intent(OpenPgpApi.ACTION_SIGN); expectedApiIntent.putExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID, TEST_SIGN_KEY_ID); expectedApiIntent.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true); assertIntentEqualsActionAndExtras(expectedApiIntent, capturedApiIntent.getValue()); ArgumentCaptor<MimeMessage> captor = ArgumentCaptor.forClass(MimeMessage.class); verify(mockCallback).onMessageBuildSuccess(captor.capture(), eq(false)); verifyNoMoreInteractions(mockCallback); MimeMessage message = captor.getValue(); Assert.assertEquals("message must be text/plain", "text/plain", message.getMimeType()); } @Test Loading