fix: validate support_email format and handle parse errors in mailer (#13958)

## Description

ConversationReplyMailer#parse_email calls
Mail::Address.new(email_string).address without error handling. When an
account's support_email contains a non-email string (e.g., "Smith
Smith"), the mail gem raises Mail::Field::IncompleteParseError, crashing
conversation transcript emails.

This has caused 1,056 errors on Sentry (EXTERNAL-CHATINC-JX) since Feb
25, all from a single account that has a name stored in the
support_email field instead of a valid email address.

Closes
https://linear.app/chatwoot/issue/CW-6687/mailfieldincompleteparseerror-mailaddresslist-can-not-parse-orsmith

## Type of change

Please delete options that are not relevant.

- [ ] Bug fix (non-breaking change which fixes an issue)


## Checklist:

- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my code
- [ ] I have commented on my code, particularly in hard-to-understand
areas
- [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged and published in downstream
modules

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: Vishnu Narayanan <iamwishnu@gmail.com>
This commit is contained in:
Tanmay Deep Sharma
2026-04-13 19:06:06 +07:00
committed by GitHub
parent 0592cccca9
commit 722e68eecb
7 changed files with 102 additions and 52 deletions

View File

@@ -256,6 +256,29 @@ RSpec.describe Account do
end
end
context 'when support_email is set' do
it 'allows a plain email address' do
account.support_email = 'support@example.com'
expect(account).to be_valid
end
it 'allows display-name format' do
account.support_email = 'Support Team <support@example.com>'
expect(account).to be_valid
end
it 'allows blank values' do
account.support_email = ''
expect(account).to be_valid
end
it 'rejects malformed strings with no email part' do
account.support_email = 'Smith Smith'
expect(account).not_to be_valid
expect(account.errors[:support_email]).to include(I18n.t('errors.account.support_email.invalid'))
end
end
context 'when reporting_timezone is set' do
it 'allows valid timezone names' do
account.reporting_timezone = 'America/New_York'