Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

EmailMessage(policy=SMTPUTF8).as_bytes() fails to encode non-ASCII Subject in 3.12 #133442

Open
Labels
pendingThe issue will be closed if no feedback is providedstdlibPython modules in the Lib dirtopic-emailtype-bugAn unexpected behavior, bug, or error
@JimmyLuojun

Description

@JimmyLuojun

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    pendingThe issue will be closed if no feedback is providedstdlibPython modules in the Lib dirtopic-emailtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp