Refresh folder race condition
This is trying to address #976, but is not ready to be merged.
There is indeed a problem where local folders will try to refresh as soon as the IMAP connection is established and before the folder list has been refreshed.
My "fix" basically waits until the refresh has finished before local folder become available. Obviously, this breaks offline mode but it demonstrates the problem.
Imho, each folder should have a state attached to them that states if they have been synced with the current imap connection and then we only refresh the folder contents for the synced folders. Let me know what you think and how we can address the problem better.