Flush IMAP data to disk when stopping. Closes #5095.