Fix "duplicate entry" errors on inserts to imap cache tables (#1489146)