Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f9527b9e authored by Vincent Breitmoser's avatar Vincent Breitmoser
Browse files

allow building drafts with no recipients in PgpMessageBuilder

parent 6a19eb3d
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -159,7 +159,7 @@ public class PgpMessageBuilder extends MessageBuilder {
                throw new MessagingException("Attachments are not supported in PGP/INLINE format!");
            }

            if (shouldEncrypt && !cryptoStatus.hasRecipients()) {
            if (shouldEncrypt && !isDraft() && !cryptoStatus.hasRecipients()) {
                throw new MessagingException("Must have recipients to build message!");
            }

+19 −0
Original line number Diff line number Diff line
@@ -299,6 +299,25 @@ class PgpMessageBuilderTest : RobolectricTest() {
        verifyNoMoreInteractions(mockCallback)
    }

    @Test
    @Throws(MessagingException::class)
    fun buildEncrypt__draftWithoutRecipients() {
        val cryptoStatus = defaultCryptoStatus.copy(cryptoMode = CryptoMode.CHOICE_ENABLED)
        pgpMessageBuilder.setCryptoStatus(cryptoStatus)
        pgpMessageBuilder.isDraft = true

        val returnIntent = spy(Intent())
        returnIntent.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_SUCCESS)
        `when`(openPgpApi.executeApi(any(Intent::class.java), any(OpenPgpDataSource::class.java), any(OutputStream::class.java)))
                .thenReturn(returnIntent)

        val mockCallback = mock(Callback::class.java)
        pgpMessageBuilder.buildAsync(mockCallback)

        verify(mockCallback).onMessageBuildSuccess(any<MimeMessage>(), eq(true))
        verifyNoMoreInteractions(mockCallback)
    }

    @Test
    @Throws(MessagingException::class)
    fun buildEncrypt__checkGossip() {
+1 −3
Original line number Diff line number Diff line
@@ -130,9 +130,7 @@ data class ComposeCryptoStatus(private val openPgpProviderState: OpenPgpProvider

    fun hasAutocryptPendingIntent() = recipientAutocryptStatus?.hasPendingIntent() == true

    override fun hasRecipients(): Boolean {
        return recipientAddresses.isNotEmpty()
    }
    override fun hasRecipients() = recipientAddresses.isNotEmpty()

    override fun getRecipientAddresses() = recipientAddresses.toTypedArray()