python / python/cpython

multipart/related mail generated with EmailMessage() class lacks mandatory MIME-Version header

Aperta
#120,946 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

topic-email type-bug
Lingua principale
Python
Stelle
77.2k
Fork
35.9k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

Bug report

Bug description:

When creating an email with EmailMessage() that contains an HTML part with images using a multipart/related structure as the outter MIME structure, the resulting mail contains non MIME-Version header. While the only valid value for the MIME-Version header is "1.0", this is a required header field for MIME structures, see https://datatracker.ietf.org/doc/html/rfc2045#section-4

Here is a simple example code:

#!/usr/bin/python3

import email.message

svgimg='<svg xmlns="http://www.w3.org/2000/svg"><circle cx="100" cy="100" r="50" fill="green"/></svg>'

outer = email.message.EmailMessage()

outer.make_related()

inner = email.message.EmailMessage()
inner.set_content("Hello")
inner.add_alternative("<img src='cid:imgid'>", subtype="html")

outer.attach(inner)
outer.add_related(svgimg.encode(), "image", "svg", cid="imgid")

print(outer.as_string())

The output starts like this:

From: test@example.com
To: test@example.org
Subject: Hello
Content-Type: multipart/related;
 boundary="===============4597207535328563093=="

[...]

It needs a "MIME-Version: 1.0" header in the main part. This will also cause some spam rating in e.g. spamassassin.

(Note: The example code uses multipart/related as the outer structure and multipart/alternative as the inner structure. While counterintuitive, this is how it is usually done by almost all mail clients. The example given in the python docs here https://docs.python.org/3/library/email.examples.html does it the other way round.)

CPython versions tested on:

3.12

Operating systems tested on:

Linux

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Riproduci il problema con email.message.EmailMessage(), make_related(), attach(), add_related() e as_string() utilizzando l’esempio riportato. Traccia la serializzazione del messaggio multipart/related esterno, quindi verifica che l’output generato includa MIME-Version: 1.0 e preservi la struttura MIME esistente.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
backend
Tipo di issue
Bug
Difficoltà
2/5
Tempo stimato
1-3 ore
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.