Don't check for existence of a folder before performing an operation

This commit is contained in:
cketti 2024-04-22 19:31:45 +02:00
parent 08a37f3d85
commit e716383120
6 changed files with 1 additions and 45 deletions

View file

@ -10,12 +10,9 @@ internal class CommandDeleteAll(private val imapStore: ImapStore) {
@Throws(MessagingException::class)
fun deleteAll(folderServerId: String) {
val remoteFolder = imapStore.getFolder(folderServerId)
if (!remoteFolder.exists()) {
return
}
try {
remoteFolder.open(OpenMode.READ_WRITE)
remoteFolder.setFlags(setOf(Flag.DELETED), true)
} finally {
remoteFolder.close()

View file

@ -11,8 +11,6 @@ internal class CommandExpunge(private val imapStore: ImapStore) {
val remoteFolder = imapStore.getFolder(folderServerId)
try {
if (!remoteFolder.exists()) return
remoteFolder.open(OpenMode.READ_WRITE)
if (remoteFolder.mode != OpenMode.READ_WRITE) return
@ -27,8 +25,6 @@ internal class CommandExpunge(private val imapStore: ImapStore) {
fun expungeMessages(folderServerId: String, messageServerIds: List<String>) {
val remoteFolder = imapStore.getFolder(folderServerId)
try {
if (!remoteFolder.exists()) return
remoteFolder.open(OpenMode.READ_WRITE)
if (remoteFolder.mode != OpenMode.READ_WRITE) return

View file

@ -8,8 +8,6 @@ internal class CommandMarkAllAsRead(private val imapStore: ImapStore) {
fun markAllAsRead(folderServerId: String) {
val remoteFolder = imapStore.getFolder(folderServerId)
if (!remoteFolder.exists()) return
try {
remoteFolder.open(OpenMode.READ_WRITE)
if (remoteFolder.mode != OpenMode.READ_WRITE) return

View file

@ -41,10 +41,6 @@ internal class CommandMoveOrCopyMessages(private val imapStore: ImapStore) {
return null
}
if (!remoteSrcFolder.exists()) {
throw MessagingException("moveOrCopyMessages: remoteFolder $srcFolder does not exist", true)
}
remoteSrcFolder.open(OpenMode.READ_WRITE)
if (remoteSrcFolder.mode != OpenMode.READ_WRITE) {
throw MessagingException(

View file

@ -10,8 +10,6 @@ internal class CommandSetFlag(private val imapStore: ImapStore) {
if (messageServerIds.isEmpty()) return
val remoteFolder = imapStore.getFolder(folderServerId)
if (!remoteFolder.exists()) return
try {
remoteFolder.open(OpenMode.READ_WRITE)
if (remoteFolder.mode != OpenMode.READ_WRITE) return

View file

@ -184,22 +184,6 @@ internal class RealImapFolder(
}
}
@Throws(MessagingException::class)
private fun exists(escapedFolderName: String): Boolean {
return try {
// Since we don't care about RECENT, we'll use that for the check, because we're checking
// a folder other than ourself, and don't want any untagged responses to cause a change
// in our own fields
connection!!.executeSimpleCommand(String.format("STATUS %s (RECENT)", escapedFolderName))
true
} catch (ioe: IOException) {
throw ioExceptionHandler(connection, ioe)
} catch (e: NegativeImapResponseException) {
false
}
}
@Throws(MessagingException::class)
override fun exists(): Boolean {
if (exists) {
@ -288,19 +272,6 @@ internal class RealImapFolder(
val encodedDestinationFolderName = folderNameCodec.encode(folder.prefixedName)
val escapedDestinationFolderName = ImapUtility.encodeString(encodedDestinationFolderName)
// TODO: Just perform the operation and only check for existence of the folder if the operation fails.
if (!exists(escapedDestinationFolderName)) {
if (K9MailLib.isDebug()) {
Timber.i(
"ImapFolder.copyMessages: couldn't find remote folder '%s' for %s",
escapedDestinationFolderName,
logId,
)
}
throw FolderNotFoundException(folder.serverId)
}
return try {
val imapResponses = connection!!.executeCommandWithIdSet(
Commands.UID_COPY,