Loading mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/ImapFolder.kt +3 −1 Original line number Diff line number Diff line Loading @@ -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. Loading mail/protocols/imap/src/test/java/com/fsck/k9/mail/store/imap/ImapFolderTest.kt +34 −0 Original line number Diff line number Diff line Loading @@ -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") Loading Loading
mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/ImapFolder.kt +3 −1 Original line number Diff line number Diff line Loading @@ -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. Loading
mail/protocols/imap/src/test/java/com/fsck/k9/mail/store/imap/ImapFolderTest.kt +34 −0 Original line number Diff line number Diff line Loading @@ -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") Loading