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

Aperta Adatta ai principianti
#2,870 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@linye157 ci sta già lavorando.

Dal 30/10/2026.

  • #2874 di @linye157 — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
80/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
go
Ambito
backend

Direzione di ricerca

Inizia in shortcuts/mail/emlbuilder/builder.go, presso selectCTE, lineWidthForCTE e writeFoldedBody, che l’issue indica come causa. Verifica come il builder gestisce i corpi text/html lunghi composti interamente da caratteri ASCII ed esegui i test esistenti pertinenti oppure aggiungi un caso di regressione per la riproduzione fornita. Il lavoro è completato quando l’HTML memorizzato mantiene intatti il testo originale e il markup se una riga supera i 998 byte.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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>.

Lingua principale
Go
Stelle
18.2k
Fork
1.4k
Merge medio
1g 3h
PR unite (30g)
18

Preparare l'ambiente

  • Nessun Dockerfile né file Docker Compose
  • Ha un modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di larksuite/cli

Tutte le issue di larksuite/cli

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.