python / python/cpython

`email.mime.image.MIMEImage`'s `policy` argument doesn't take effect

オープン
#133,311 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

stdlib topic-email type-bug
主要言語
Python
スター
77.2k
フォーク
35.9k
PR マージ指標
PR 指標を取得中

説明

Bug report

Bug description:

I'm comparing the creation of two MIME parts, one using MIMEImage and one using MIMEPart, with the same policy object, which asks for max_line_length=35.

the MIMEImage does not respect the max_line_length when base64-encoding, but the MIMEPart does:

#!/usr/bin/python3

from io import BytesIO
from email.policy import EmailPolicy
from email.mime.image import MIMEImage
from email.message import MIMEPart
from PIL import Image, ImageDraw

img = Image.new('RGBA', (20,20))
d = ImageDraw.Draw(img)
d.regular_polygon((10,6,6), 3, fill='red')
d.line([(16,10), (10,16)], fill='blue', width=2)
d.line([(16,16), (10,10)], fill='blue', width=2)
b = BytesIO()
img.save(b, format='png', optimize=True)
imgbytes = b.getvalue()

policy = EmailPolicy(max_line_length=35)

f = MIMEImage(imgbytes, policy=policy)
print(f)

g = MIMEPart(policy=policy)
g.set_content(imgbytes, 'image', 'png')
print(g)

The output is:

Content-Type: image/png
MIME-Version: 1.0
Content-Transfer-Encoding: base64

iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAAcElEQVR42uVTOxbAMAgS739nO3Tp
Rw20dqpbfARQEjOywiwYnCtkDKnbcLk66sqlT+zt9cidkE+6KwkZsgrzfcqVMpL2jo0447gYDpeA
rk+OnJHkIhAfTPRicihAf5YJrw7vjv0ZWRWM/ulivdPf1QZ2kDD9xppd8wAAAABJRU5ErkJggg==

Content-Type: image/png
Content-Transfer-Encoding: base64

iVBORw0KGgoAAAANSUhEUgAAABQAAAAU
CAYAAACNiR0NAAAAcElEQVR42uVTOxbA
MAgS739nO3TpRw20dqpbfARQEjOywiwY
nCtkDKnbcLk66sqlT+zt9cidkE+6KwkZ
sgrzfcqVMpL2jo0447gYDpeArk+OnJHk
IhAfTPRicihAf5YJrw7vjv0ZWRWM/uli
vdPf1QZ2kDD9xppd8wAAAABJRU5ErkJg
gg==

CPython versions tested on:

3.13

Operating systems tested on:

Linux

Linked PRs
  • gh-133322

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、email.mime.image.MIMEImage と email.message.MIMEPart の実装を比較し、base64 エンコード時にそれぞれが指定された EmailPolicy をどのように使用するかに注目してください。max_line_length=35 で例を再現し、MIMEImage が policy で許可される長さを超えない行を出力することを確認してください。リンクされた PR gh-133322 は、作業がすでに進行中であることを示しています。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
backend
issue の種類
バグ
難易度
2/5
見積もり時間
1〜3時間
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
30/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。