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

Đang mở
#93,158 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
25/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
python
Lĩnh vực
backend

Hướng nghiên cứu

Bắt đầu với reproducer email.parser.BytesParser được cung cấp và so sánh các header đã được phân tích với get_payload(). Xem lại PR gh-93176 được liên kết để biết công việc đã được triển khai; hoàn tất khi các header có khoảng trắng trước dấu hai chấm vẫn là header và không bị chuyển vào payload.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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
Ngôn ngữ chính
Python
Star
77.2k
Fork
36k
Merge trung bình
1 ngày 9 giờ
Pull request đã merge (30 ngày)
558

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của python/cpython

Tất cả issue của python/cpython

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.