mailbox.mbox malformed 'From ' lines not being detected/handled
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 77.2k
- Fork
- 36k
- Chỉ số merge pull request
- Chỉ số pull request đang chờ
Mô tả
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
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu với mailbox.py, đặc biệt là mbox.init và _generate_toc(), đồng thời xem xét PR được liên kết gh-131415 trước khi thực hiện thay đổi. Công việc được hoàn tất khi có thể xử lý các dấu phân cách 'From ' không đúng định dạng mà vẫn giữ nguyên hành vi mặc định hiện có.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- backend
- Loại issue
- Lỗi
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 30/100