mail: all-ASCII draft bodies are hard-wrapped every 998 bytes, inserting newlines inside words and tags

オープン 初心者向け
#2,870 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@linye157 がすでに取り組んでいます。

2026年10月30日 から。

  • #2874 @linye157 による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
80/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
go
領域
backend

調査の方向性

shortcuts/mail/emlbuilder/builder.go の selectCTE、lineWidthForCTE、writeFoldedBody から調べてください。issue ではこれらが原因として挙げられています。builder が ASCII のみで構成された長い text/html ボディをどのように処理するか確認し、関連する既存テストを実行するか、提示された再現例の回帰テストを追加してください。行が 998 バイトを超えても、保存された HTML の元のテキストとマークアップがそのまま保たれることが完了条件です。

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

説明

domain/mail
Summary

mail +draft-create, +reply, +reply-all, and +forward send the HTML part with Content-Transfer-Encoding: 7bit when the body is pure ASCII, and then split every line longer than 998 bytes by inserting a raw newline at byte 998, wherever that falls. A raw newline in a 7bit part is not a soft line break, so it is stored as part of the HTML:

  • Text gets a stray space in the middle of a word (word262 comes back as word2 + newline + 62, shown as "word2 62").
  • When the cut lands inside a tag, markup is lost. The signature and the quoted original are appended on the same long line, so their markup is damaged even when the body itself is short (we see style attributes such as font-family and margin-top dropped from signature lines).

A body that contains any non-ASCII byte is sent as base64 and is stored intact. +draft-edit does not seem to be affected.

Version

lark-cli 1.0.98 (Linux, installed from npm)

Steps to reproduce
BODY="<div>$(python3 -c "print(' '.join(f'word{i}' for i in range(300)))")</div>"
lark-cli mail +draft-create --to [email protected] --subject "fold test" --body "$BODY" --no-signature --as user
# Read the stored body back (use the draft_id printed above):
lark-cli mail user_mailbox.drafts get --as user \
  --params '{"user_mailbox_id":"me","draft_id":"<draft_id>"}' \
  | python3 -c "import json,sys,base64; h=json.load(sys.stdin)['data']['draft']['message']['body_html']; html=base64.urlsafe_b64decode(h+'='*(-len(h)%4)).decode(); print([i for i,c in enumerate(html) if c=='\n'])"

Observed: newlines at offsets 998 and 1997 of the stored body_html; the second one splits word262.

Expected: the body is stored exactly as given.

Running the same commands with one non-ASCII character anywhere in the body (for example é) stores it with no inserted newlines.

Cause

RFC 5322 does limit lines to 998 characters, but 7bit has no soft line break, so splitting a line changes the content.

Suggested fix

When a text part has a line longer than 998 bytes (or simply for every text/html part), encode it as quoted-printable, whose soft line breaks are removed on decoding, or as base64, as is already done for non-ASCII bodies, instead of folding a 7bit body.

Workaround

Any non-ASCII byte in the body makes the part base64, for example a non-rendering attribute on a wrapper element: <div data-x="✓">...</div>.

主要言語
Go
スター
18.2k
フォーク
1.4k
平均マージ
1日 3時間
マージ済み PR(30日)
18

環境構築

  • Dockerfile・Docker Compose ファイルなし
  • プルリクエストのテンプレートあり
  • コントリビューションガイドなし

はじめの一歩

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

larksuite/cli のほかの issue

larksuite/cli の issue をすべて見る

似ている issue

Go の issue をもっと見る

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

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