mailbox.mbox malformed 'From ' lines not being detected/handled
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 77.2k
- Forks
- 36k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
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
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit mailbox.py, insbesondere mit mbox.init und _generate_toc(), und prüfe den verknüpften PR gh-131415, bevor du Änderungen vornimmst. Als erledigt gilt die Aufgabe, wenn fehlerhafte „From “-Trennzeichen verarbeitet werden können und das bestehende Standardverhalten unverändert bleibt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- backend
- Issue-Typ
- Bug
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Aktivitätsstatus
- Veraltet
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 30/100