﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
36752	SMTP backend crashes on invalid email addresses such as “to@”	Kwadwo Owusu Ansah		"While running the Django test suite on the current development version
(6.1.dev), the SMTP backend crashes when preparing invalid email
addresses such as ""to@"".

This failure is triggered by the test:
tests/mail/tests.py::test_avoids_sending_to_invalid_addresses

Expected behavior:
Invalid email addresses should be rejected early with a ValueError and
must not reach the low-level email header parser used by
AddressHeader.value_parser().

Actual behavior:
The following exception occurs when attempting to parse the invalid
address:

IndexError: string index out of range

Traceback (excerpt):
  File django/core/mail/backends/smtp.py, in prep_address
    parsed = AddressHeader.value_parser(address)
  File .../email/_header_value_parser.py
    if value[0] in CFWS_LEADER:
IndexError: string index out of range

This indicates that the backend attempts to parse malformed email
addresses too deeply instead of validating them first.

Environment:
- Django version: 6.1.dev
- Python 3.12
- Command: python tests/runtests.py mail

Steps to reproduce:
1. Clone Django main
2. Install test dependencies
3. Run: python tests/runtests.py mail
4. Observe the failure in test_avoids_sending_to_invalid_addresses

The failure is reproducible and appears to be a regression in the SMTP
backend’s handling of invalid recipient addresses."	Bug	closed	Core (Mail)	dev	Normal	duplicate	smtp invalid email parser regression		Unreviewed	0	0	0	0	0	0
