Fix unbounded recursion in IMAPFolder

When processing message flags, we were recursing once per 100 messages.
This causes RuntimeError("maximum recursion depth ...") when there are a
lot of messages in a folder that need to be updated.  Instead of
recursing, iterate as the XXX comment suggests.