email.parser.Parser dropping headers into payload if space between header name and colon

Abierto
#93,158 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
25/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Estancado
Stack tecnológico
python
Área
backend

Línea de trabajo

Comienza con el reproducer proporcionado de email.parser.BytesParser y compara los encabezados analizados con get_payload(). Revisa el PR vinculado gh-93176 para conocer el trabajo que ya está en marcha; se considera terminado cuando los encabezados con espacios en blanco antes de los dos puntos siguen siendo encabezados y no se mueven al payload.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

3.11 3.12 3.13 topic-email type-bug

In some cases, I have seen the standard library email message parser (invoked via email.parser.BytesParser) losing headers, in cases where a message has a header line where a space appears between the header name and the delimiting colon following.

Sample which reproduces this:

Subject: test-ignore
To: someone@somedomain.com
x-fred :dead
Date: Fri, 20 May 2022 18:13:19 +1200
From: sender@somedomain.com

Hello, this is a test message

When this is parsed in email.parser.BytesParser, the resulting EmailMessage object has these headers, as dumped by calling .items():

[('Subject', 'test-ignore'),
 ('To', ': someone@somedomain.com;')
]

Meanwhile, the dropped headers end up in the message payload, as seen from calling .get_payload():

x-fred :dead
Date: Fri, 20 May 2022 18:13:19 +1200
From: sender@somedomain.com

Hello, this is a test message

This failure to gracefully cope with a non-compliant header puts Python3's standard library email parser in breach of RFC5322, Section 4.5: ...any amount of white space is allowed [in the header] before the ":" at the end of the [header] field name...

To cope with email.parser.Parser's failure to cope with this archaic header format, I've had to implement a crude workaround of detecting if any expected headers are absent in the resulting email.message.EmailMessage object, and if so, manually 'massaging' the headers part of the raw message, then re-submitting it to the Parser.

However, I'd suggest this really does need to be fixed within Python's standard library module.

Linked PRs
  • gh-93176
Lenguaje dominante
Python
Estrellas
77.2k
Forks
36k
Merge medio
1 d 9 h
PR fusionados (30 d)
558

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de python/cpython

Todos los issues de python/cpython

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.