The email parser class returns the wrong type for the parsed message
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 77.2k
- Fork
- 36k
- Merge medio
- 1g 9h
- PR unite (30g)
- 558
Descrizione
Summary
According to the documentation,
The email package provides a standard parser that understands most email document structures, including MIME documents. You can pass the parser a bytes, string or file object, and the parser will return to you the root EmailMessage instance of the object structure.
In fact, the parser returns an object of the legacy Message class. Code which takes the documentation at face value will blow up if it attempts to invoke methods which the newer class has but the older class does not.
Environment
Python 3.11.1 (v3.11.1:a7a450f84a, Dec 6 2022, 15:24:06) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin
Repro
Here is a small program which demonstrates the problem.
Code
#!/usr/bin/env python3
import email
message_bytes = (
b'Content-type: multipart/form-data; boundary=------abracadabra\r\n'
b'\r\n'
b'------abracadabra\r\n'
b'Content-Disposition: form-data; name="f"; filename="f1"\r\n'
b'Content-Type: application/octet-stream\r\n'
b'\r\n'
b'\x01\r\n'
b'------abracadabra--\r\n'
)
message = email.message_from_bytes(message_bytes)
print(f'type of message is {type(message)}')
print('have get_content()?', hasattr(message, 'get_content'))
Output
% ./email-message-repro.py
type of message is <class 'email.message.Message'>
have get_content()? False
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Eseguire il reproducer fornito e ispezionare l’entry point email.message_from_bytes, insieme alla documentazione collegata di parser e EmailMessage. Determinare se la correzione prevista consiste nel modificare il tipo restituito o nel correggere la documentazione, quindi aggiungere una copertura per il comportamento dimostrato e verificare che l’API documentata e il risultato a runtime concordino.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- backend
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Da chiarire
- Idoneità per principianti
- 35/100