Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.2k
Open
Description
Bug report
Bug description:
# Add a code block here, if required
# test_subject_encoding.pyfromemail.messageimportEmailMessagefromemail.policyimportSMTPUTF8importsys# Use one of the subject strings that caused issues# Make sure this is the exact string causing Mojibakesubject='Vectorsentinel与Drone Volt合作共赢,探索无人机安防新机遇'print(f"Python Version:{sys.version}")print(f"Testing subject:{repr(subject)}")msg=EmailMessage(policy=SMTPUTF8)msg['From']='sender@example.com'msg['To']='recipient@example.com'# Use standard assignmentmsg['Subject']=subjectmsg.set_content('Test body content.')print("\n--- Message As String ---")try:# Use as_string() which should also trigger encodingprint(msg.as_string())exceptExceptionase:print(f"Error during as_string():{e}\n")print("\n--- Message As Bytes (Decoded) ---")try:# Use as_bytes() and decode for printing# We are primarily interested in the Subject: line formatmessage_bytes=msg.as_bytes()print(message_bytes.decode('utf-8','replace'))# Use utf-8 decodeexceptExceptionase:print(f"Error during as_bytes():{e}\n")
Python Version: 3.12.0 (main, Jan 4 2025, 13:42:56) [Clang 16.0.0 (clang-1600.0.26.6)]Testing subject: 'Vectorsentinel与Drone Volt合作共赢,探索无人机安防新机遇'--- Message As String ---From: sender@example.comTo: recipient@example.comSubject: Vectorsentinel与Drone Volt合作共赢,探索无人机安防新机遇Content-Type: text/plain; charset="utf-8"Content-Transfer-Encoding: 7bitMIME-Version: 1.0Test body content.--- Message As Bytes (Decoded) ---From: sender@example.comTo: recipient@example.comSubject: Vectorsentinel与Drone Volt合作共赢,探索无人机安防新机遇Content-Type: text/plain; charset="utf-8"Content-Transfer-Encoding: 7bitMIME-Version: 1.0Test body content.
CPython versions tested on:
3.12
Operating systems tested on:
macOS