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

Open Beginner friendly
#2,870 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@linye157 is already working on this.

Since Oct 30, 2026.

  • #2874 by @linye157 — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
80/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
go
Domain
backend

Research direction

Start in shortcuts/mail/emlbuilder/builder.go at selectCTE, lineWidthForCTE, and writeFoldedBody, which the issue identifies as the cause. Check how the builder handles long all-ASCII text/html bodies and run the relevant existing tests or add a regression case for the provided reproduction. Done means stored HTML keeps the original text and markup intact when a line exceeds 998 bytes.

Written by the indexing model from the issue text.

Description

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

Dominant language
Go
Stars
18.2k
Forks
1.4k
Avg merge
1d 3h
Merged PRs (30d)
18

Getting set up

  • No Dockerfile or Docker Compose file
  • Has a pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from larksuite/cli

All issues in larksuite/cli

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.