We have observed in Sentry that sometimes fetch_imap_emails_jobs fails with a validation error when creating a contact. This happens when the original_sender isn't in a format supported by the Chatwoot contact model schema. Chatwoot validates contacts email with Device.email_regexp.
This PR will skip processing such emails. It also adds a log for each email processed in the email fetch job and an error for the ones we skip.
We have observed in Sentry that sometimes
fetch_imap_emails_jobs
fails with a validation error when creating a contact. This happens when theoriginal_sender
isn't in a format supported by the Chatwoot contact model schema. Chatwoot validates contacts email withDevice.email_regexp
.This PR will skip processing such emails. It also adds a log for each email processed in the email fetch job and an error for the ones we skip.
Fixes: https://linear.app/chatwoot/issue/CW-3295/activerecordrecordinvalid-validation-failed-email-invalid-email