Details
Description
When a COPY command is issued for a message two added events are dispatched from StoreMessageManager (mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java). The first event (row 712) use the message UID from the source mailbox and the second event (row 743) use a new UID from the target mailbox. If the source UID is "available" in the target mailbox a new entry will be added to the target mailbox UidMsnConverter which will mess up the sequence numbers.
In the example below two connection A and B are used. A selects the Inbox and B selects the Trash mailbox. Inbox and Trash contains one message each.
* OK JAMES IMAP4rev1 Server Server imapsrv is ready.
A1 LOGIN "user@test.com" "1234"
A1 OK LOGIN completed.
A2 SELECT inbox
* FLAGS (\Answered \Deleted \Draft \Flagged \Seen)
* 1 EXISTS
* 0 RECENT
* OK [UIDVALIDITY 1892339292] UIDs valid
* OK [UNSEEN 1] MailboxMessage 1 is first unseen
* OK [PERMANENTFLAGS (\Answered \Deleted \Draft \Flagged \Seen)] Limited
* OK [HIGHESTMODSEQ 1538993301626] Highest
* OK [UIDNEXT 2] Predicted next UID
A2 OK [READ-WRITE] SELECT completed.
A3 FETCH 1:* (FLAGS)
* 1 FETCH (FLAGS ())
A3 OK FETCH completed.
* OK JAMES IMAP4rev1 Server Server imapsrv is ready.
B1 LOGIN "user@test.com" "1234"
B1 OK LOGIN completed.
B3 SELECT Trash
* FLAGS (\Answered \Deleted \Draft \Flagged \Seen)
* 1 EXISTS
* 1 RECENT
* OK [UIDVALIDITY 286991256] UIDs valid
* OK [UNSEEN 1] MailboxMessage 1 is first unseen
* OK [PERMANENTFLAGS (\Answered \Deleted \Draft \Flagged \Seen)] Limited
* OK [HIGHESTMODSEQ 1538993663429] Highest
* OK [UIDNEXT 3] Predicted next UID
B3 OK [READ-WRITE] SELECT completed.
Clear Trash
B4 STORE 1 +FLAGS (\Deleted)
* 1 FETCH (FLAGS (\Deleted \Recent))
B4 OK STORE completed.
B5 EXPUNGE
* 1 EXPUNGE
* 0 RECENT
B5 OK EXPUNGE completed.
B6 FETCH 1:* (FLAGS)
B6 BAD FETCH failed. Invalid messageset.
Copy message from Inbox to Trash
A4 COPY 1 Trash
A4 OK [COPYUID 286991256 1 3] COPY completed.
Check messages in Trash
B7 FETCH 1:* (FLAGS)
* 2 FETCH (FLAGS (\Recent))
* 2 EXISTS <-- SHOULD ONLY BE ONE!
* 2 RECENT
B7 OK FETCH completed.
Removing the first event seems to fix the problem.
(BTW: Is it correct to allow reuse of UIDs in UidMsnConverter?)