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

Commit e42e0fa8 authored by cketti's avatar cketti
Browse files

IMAP: Support negative responses to APPEND command

parent 93b26ece
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -1013,7 +1013,9 @@ class ImapFolder internal constructor(
                    }
                } while (response.tag == null)

                if (response.size > 1) {
                if (response.size < 1 || !ImapResponseParser.equalsIgnoreCase(response[0], Responses.OK)) {
                    throw NegativeImapResponseException("APPEND failed", listOf(response))
                } else if (response.size > 1) {
                    /*
                     * If the server supports UIDPLUS, then along with the APPEND response it
                     * will return an APPENDUID response code, e.g.
+34 −0
Original line number Diff line number Diff line
@@ -869,6 +869,40 @@ class ImapFolderTest {
        verify(imapConnection).sendCommand("APPEND \"Folder\" () {0}", false)
    }

    @Test
    fun appendMessages_withNegativeResponse_shouldThrow() {
        val folder = createFolder("Folder")
        prepareImapFolderForOpen(ImapFolder.OPEN_MODE_RW)
        folder.open(ImapFolder.OPEN_MODE_RW)
        val messages = listOf(createImapMessage("1"))
        whenever(imapConnection.readResponse()).thenReturn(createImapResponse("x NO Can't append to this folder"))

        try {
            folder.appendMessages(messages)
            fail("Expected exception")
        } catch (e: NegativeImapResponseException) {
            assertEquals("APPEND failed", e.message)
            assertEquals("NO", e.lastResponse[0])
        }
    }

    @Test
    fun appendMessages_withBadResponse_shouldThrow() {
        val folder = createFolder("Folder")
        prepareImapFolderForOpen(ImapFolder.OPEN_MODE_RW)
        folder.open(ImapFolder.OPEN_MODE_RW)
        val messages = listOf(createImapMessage("1"))
        whenever(imapConnection.readResponse()).thenReturn(createImapResponse("x BAD [TOOBIG] Message too large."))

        try {
            folder.appendMessages(messages)
            fail("Expected exception")
        } catch (e: NegativeImapResponseException) {
            assertEquals("APPEND failed", e.message)
            assertEquals("BAD", e.lastResponse[0])
        }
    }

    @Test
    fun getUidFromMessageId_withMessageIdHeader_shouldIssueUidSearchCommand() {
        val folder = createFolder("Folder")