Skip to content

fix(gmail): stop hard-wrapping plain text email bodies at ~72 chars#476

Merged
steipete merged 1 commit intoopenclaw:mainfrom
shashankkr9:fix/issue-475-body-wrapping
Apr 20, 2026
Merged

fix(gmail): stop hard-wrapping plain text email bodies at ~72 chars#476
steipete merged 1 commit intoopenclaw:mainfrom
shashankkr9:fix/issue-475-body-wrapping

Conversation

@shashankkr9
Copy link
Copy Markdown
Contributor

Summary

  • Fixes bug(gmail): --body and --body-file silently hard-wrap text at ~72 chars, breaking email formatting #475 — plain text bodies sent via gog gmail send --body / --body-file were hard-wrapped at ~72 characters, destroying paragraph formatting
  • Root cause: text/plain MIME parts used Content-Transfer-Encoding: 7bit, so long lines violated RFC 5322 limits and Gmail's SMTP transport hard-wrapped them
  • Fix: Switch text/plain parts to quoted-printable encoding — the QP encoder inserts soft line breaks (=\r\n) that mail clients strip, preserving original paragraph structure
  • HTML bodies remain 7bit (unaffected since HTML ignores whitespace)

Changes

  • internal/cmd/gmail_mime.go — use mime/quotedprintable.Writer for all plain text body paths (standalone, multipart/alternative, multipart/mixed)
  • internal/cmd/gmail_mime_test.go — 3 new tests: long line QP round-trip, multi-paragraph round-trip, HTML stays 7bit

Test plan

  • All existing tests pass (go test ./...)
  • go vet ./... clean
  • Live test: 325-char single paragraph arrives as 1 line (no wrapping)
  • Live test: 3 paragraphs with blank lines — structure preserved
  • Live test: HTML body still works (regression check)

🤖 Generated with Claude Code

…event hard-wrapping

Plain text email bodies were encoded with Content-Transfer-Encoding: 7bit,
which meant long lines (>78 chars) violated RFC 5322 line length limits.
Gmail's SMTP transport would then hard-wrap lines at ~72 characters,
inserting literal CRLF breaks mid-paragraph and destroying formatting.

Switch text/plain parts to quoted-printable encoding. The QP encoder
inserts soft line breaks (=CRLF) that recipients' mail clients strip,
preserving the original paragraph structure. HTML bodies remain 7bit
since HTML rendering is unaffected by line breaks.

Fixes openclaw#475
@steipete steipete merged commit e787894 into openclaw:main Apr 20, 2026
1 check passed
@steipete
Copy link
Copy Markdown
Collaborator

Landed on main.

  • Local gate: make ci
  • CI: run 24666775462 green
  • Merge commit: e787894
  • Final main after changelog/lint cleanup: 4247608

Thanks @shashankkr9!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(gmail): --body and --body-file silently hard-wrap text at ~72 chars, breaking email formatting

2 participants