Skip to content

Commit

Permalink
IMAP COPY response contains COPYUID UIDVALIDITY of source instead of …
Browse files Browse the repository at this point in the history
…target folder (fixes #423)

- Fix UIDVALIDITY to return destination value instead of source value
- Refactor MoveCommand to re-use CopyCommand COPYUID response
  generation
  • Loading branch information
marcelmay committed Feb 13, 2022
1 parent c46dfee commit 3c42de2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 31 deletions.
Expand Up @@ -34,7 +34,7 @@ class CopyCommand extends SelectedStateCommand implements UidEnabledCommand {
protected void doProcess(ImapRequestLineReader request,
ImapResponse response,
ImapSession session)
throws ProtocolException, FolderException {
throws ProtocolException, FolderException {
doProcess(request, response, session, false);
}

Expand All @@ -43,7 +43,7 @@ public void doProcess(ImapRequestLineReader request,
ImapResponse response,
ImapSession session,
boolean useUids)
throws ProtocolException, FolderException {
throws ProtocolException, FolderException {
IdRange[] idSet = parser.parseIdRange(request);
String mailboxName = parser.mailbox(request);
parser.endLine(request);
Expand Down Expand Up @@ -78,25 +78,25 @@ public void doProcess(ImapRequestLineReader request,
}

session.unsolicitedResponses(response);
response.commandComplete(this, generateCopyUidResponseCode(currentMailbox, copiedUidsOld, copiedUidsNew));
response.commandComplete(this, generateCopyUidResponseCode(toFolder, copiedUidsOld, copiedUidsNew));
}

/**
* Generates <b>COPYUID</b> response code
* (see <a href="http://tools.ietf.org/html/rfc2359#page-4">http://tools.ietf.org/html/rfc2359</a>)
* using format : <i>COPYUID UIDVALIDITY SOURCE-UIDS TARGET-UIDS</i>.
*
* <p>
* For example <i>COPYUID 38505 304,319,320 3956,3957,3958</i>
*
* @param currentMailbox imap folder which is target of copy command
* @param copiedUidsFrom List of source uids which was successfully copied
* @param copiedUidsTo List of message uids which was successfully copied
* @param destinationFolder imap folder which is target of copy command
* @param copiedUidsFrom List of source uids which was successfully copied
* @param copiedUidsTo List of message uids which was successfully copied
* @return response code
*/
private String generateCopyUidResponseCode(ImapSessionFolder currentMailbox,
List<Long> copiedUidsFrom, List<Long> copiedUidsTo) {
static String generateCopyUidResponseCode(MailFolder destinationFolder,
List<Long> copiedUidsFrom, List<Long> copiedUidsTo) {
return "COPYUID" + SP +
currentMailbox.getUidValidity() + SP +
destinationFolder.getUidValidity() + SP +
IdRange.uidsToRangeString(copiedUidsFrom) + SP +
IdRange.uidsToRangeString(copiedUidsTo);
}
Expand Down
Expand Up @@ -84,29 +84,9 @@ public void doProcess(ImapRequestLineReader request,
}

if (useUids) {
response.okResponse(generateCopyUidResponseCode(toFolder, copiedUidsOld, copiedUidsNew), "");
response.okResponse(CopyCommand.generateCopyUidResponseCode(toFolder, copiedUidsOld, copiedUidsNew), "");
}
session.unsolicitedResponses(response); // EXPUNGE responses
response.commandComplete(this);
}

/**
* Generates <b>COPYUID</b> response code
* (see <a href="http://tools.ietf.org/html/rfc2359#page-4">http://tools.ietf.org/html/rfc2359</a>)
* using format : <i>COPYUID UIDVALIDITY SOURCE-UIDS TARGET-UIDS</i>.
* <p>
* For example <i>COPYUID 38505 304,319,320 3956,3957,3958</i>
*
* @param destinationFolder imap folder which is target of copy command
* @param copiedUidsFrom List of source uids which was successfully copied
* @param copiedUidsTo List of message uids which was successfully copied
* @return response code
*/
private String generateCopyUidResponseCode(MailFolder destinationFolder,
List<Long> copiedUidsFrom, List<Long> copiedUidsTo) {
return "COPYUID" + SP +
destinationFolder.getUidValidity() + SP +
IdRange.uidsToRangeString(copiedUidsFrom) + SP +
IdRange.uidsToRangeString(copiedUidsTo);
}
}

0 comments on commit 3c42de2

Please sign in to comment.