How to sort the messages in JavaMail?

John Zukowski

Within the JavaMail classes there is no support for this. However, once you get the array of messages back from a folder, you can call the Arrays.sort() method in the collections framework to sort the messges. Since MimeMessage doesn't implement Comparable, you'll need to provide your own Comparator specifying how you want the messages to be sorted.