Client code usually generates the ImapSet by simply passing it a vector of
IDs or just by calling ImapSet::add() in a for loop for individual IDs. This
creates potentially massive amount of intervals. This change ads a method
that will optimize the ImapSet by merging adjacent or overlapping intervals.
I ran into this trying to move about 28'000 emails to Trash in KMail. The IMAP
resource calls ImapSet::add() in a for loop to add each Item to be moved into
the set. This just created 28'000 single-UID intervals and the resulting request
string was so long that my Courier IMAP server just dropped the connection, so
the IMAP resource reconnected and tried to send the same massive request again
and again and again...
By optimizing the set the string size is reduced from nearly 156 kilobytes
down to less than 4 kilobytes.