Refactoring
IMAP: MemoryCache: remove cached threading information and UID mapping when the UIDVALIDITY etc changes

Commit af199615ca124cdbb5b84fce82dc7b6cf36f8262 shuold have fixed the
MemoryCache as well, obviously...
IMAP: speed up the search processing when filtering messages

The old algorithm was rather dumb -- finding a first element of a QHash is not
O(1), but O(n), leading to quadratic time complexity, and the excess memory
traffic doesn't help either. On my laptop, this change changes cuts runtime of
the newly added test to ~280ms from the original 15+ seconds.