DEV: IMAP log to database (PR #10435)

Convert all IMAP logging to write to a database table for easier inspection. These logs are cleaned up daily if they are > 5 days old.

GitHub

This pull request has been mentioned on Discourse Meta. There might be relevant details there: