mailbox.mbox malformed 'From ' lines not being detected/handled
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 77.2k
- Forks
- 36k
- Métricas de merge de PR
- Métricas de PR pendientes
Descripción
Bug report
mailbox.mbox (class mbox) builds the table of contents (_generate_toc() ) by matching on lines starting with b'From '.
This is RFC compliant, however, malicious emails/senders will sometimes intentionally break this causing unexpected behavior.
I suggest this be considered a bug as :
- In these cases it is not possible to ask the sender to fix their MTA but we still need to parse the message
- There are cases where good senders do this by mistake - e.g. poor line wrapping in quoted-printable content
- Many common end-user email programs gracefully handle this scenario already
I propose exposing a custom 'From ' line delimiter with existing behavior maintained as a default :
diff of mailbox.py :
847c847
< def __init__(self, path, factory=None, create=True, fromline=b'From '):
---
> def __init__(self, path, factory=None, create=True):
850d849
< self._fromline = fromline
865c864
< if line.startswith(self._fromline):
---
> if line.startswith(b'From '):
There are more sophisticated methods which could be explored; for example is_from() function in mutt, or a regex over a byte array.
Your environment
python 3.9.13
Linked PRs
- gh-131415
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Empieza por mailbox.py, especialmente por mbox.init y _generate_toc(), y revisa el PR vinculado gh-131415 antes de hacer cambios. La tarea estará terminada cuando se puedan gestionar delimitadores «From » mal formados y el comportamiento predeterminado existente permanezca sin cambios.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- backend
- Tipo de issue
- Error
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Estado de actividad
- Estancado
- Claridad
- Bien especificado
- Aptitud para principiantes
- 30/100