greenmail-mail-test / greenmail

Official master for the Greenmail project
http://greenmail-mail-test.github.io/greenmail/
Apache License 2.0
624 stars 179 forks source link

IMAP FETCH Bug #377

Open Uni2K opened 3 years ago

Uni2K commented 3 years ago

Hello, its me again :D

I just found a new bug, here you can see a picture of it: bug

It was recorded in TB and shows that the numbers of unseen messages changes randomly. Moreover, also the total number of messages are displayed incorrectly, despite Greenmail holding the correct number of messages in the folder. The bug can be seen most dominant in Thunderbird but also in Outlook (it just does not show some messages).

The good news is that I already found the solution: The UIDs need to be sorted while returning the FETCH response to the client.

Example:

Wrong:

Correct:

So, all you have to do is to change the getMessageUids() method in the folder implementations to sort the uids before returning: something like:

  @Override
    public long[] getMessageUids() {
        long[] uids=mailMessages.getMessageUids();
        Arrays.sort(uids);
        return uids;
    }

And then everything will work fine :)

marcelmay commented 3 years ago

Thx again for the detailed analysis!

marcelmay commented 3 years ago

@Uni2K , the GreenMail internal implementation holding messages is a list so the order should be the same. I also tried to reproduce using Thunderbird (mailbox with couple of messages 'unseen' and refreshing).

Can you provide the GreenMail verbose (eg via -Dgreenmail.verbose) output including the IMAP commands? Which client are you using?