-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7403 from thunderbird/move_copyuid_response
IMAP: Add support for untagged COPYUID responses
- Loading branch information
Showing
6 changed files
with
228 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 0 additions & 59 deletions
59
mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/UidCopyResponse.java
This file was deleted.
Oops, something went wrong.
54 changes: 54 additions & 0 deletions
54
mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/UidCopyResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.fsck.k9.mail.store.imap | ||
|
||
internal class UidCopyResponse private constructor(val uidMapping: Map<String, String>) { | ||
|
||
companion object { | ||
fun parse(imapResponses: List<ImapResponse>, allowUntaggedResponse: Boolean = false): UidCopyResponse? { | ||
val uidMapping = mutableMapOf<String, String>() | ||
for (imapResponse in imapResponses) { | ||
parseUidCopyResponse(imapResponse, allowUntaggedResponse, uidMapping) | ||
} | ||
|
||
return if (uidMapping.isNotEmpty()) { | ||
UidCopyResponse(uidMapping) | ||
} else { | ||
null | ||
} | ||
} | ||
|
||
@Suppress("ReturnCount", "ComplexCondition", "MagicNumber") | ||
private fun parseUidCopyResponse( | ||
response: ImapResponse, | ||
allowUntaggedResponse: Boolean, | ||
uidMappingOutput: MutableMap<String, String>, | ||
) { | ||
if (!(allowUntaggedResponse || response.isTagged) || response.size < 2 || | ||
!ImapResponseParser.equalsIgnoreCase(response[0], Responses.OK) || !response.isList(1) | ||
) { | ||
return | ||
} | ||
|
||
val responseTextList = response.getList(1) | ||
if (responseTextList.size < 4 || | ||
!ImapResponseParser.equalsIgnoreCase(responseTextList[0], Responses.COPYUID) || | ||
!responseTextList.isString(1) || !responseTextList.isString(2) || !responseTextList.isString(3) | ||
) { | ||
return | ||
} | ||
|
||
val sourceUids = ImapUtility.getImapSequenceValues(responseTextList.getString(2)) | ||
val destinationUids = ImapUtility.getImapSequenceValues(responseTextList.getString(3)) | ||
|
||
val size = sourceUids.size | ||
if (size == 0 || size != destinationUids.size) { | ||
return | ||
} | ||
|
||
for (i in 0 until size) { | ||
val sourceUid = sourceUids[i] | ||
val destinationUid = destinationUids[i] | ||
uidMappingOutput[sourceUid] = destinationUid | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
139 changes: 0 additions & 139 deletions
139
mail/protocols/imap/src/test/java/com/fsck/k9/mail/store/imap/UidCopyResponseTest.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.