Skip to content

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

@shashankkr9

Description

@shashankkr9

Description

When sending or creating drafts with --body or --body-file, the CLI hard-wraps plain text at ~72 characters (RFC 2822 line folding) before sending to the Gmail API. This silently destroys paragraph formatting in sent emails.

Steps to Reproduce

  1. Create a file with a single long paragraph (e.g., 200+ chars on one line):
    echo "This is a long paragraph that should reflow naturally in the recipient's email client but instead gets chopped into narrow lines by the CLI before it even reaches Gmail." > /tmp/test.txt
    
  2. Send or create a draft:
    gog gmail drafts create --to "test@example.com" --subject "Test" --body-file /tmp/test.txt -a me@example.com --client myclient
    
  3. Send the draft from Gmail

Expected Behavior

The paragraph renders as a single reflowing block in the recipient's email client.

Actual Behavior

The paragraph is chopped into ~72-char lines with hard \r\n breaks:

This is a long paragraph that should reflow naturally in the
recipient's email client but instead gets chopped into narrow lines
by the CLI before it even reaches Gmail.

This is invisible in Gmail's compose/draft view (which reflows text while editing) but appears as broken formatting once the email is actually sent and viewed by recipients.

Root Cause

The Go MIME library used to construct the text/plain MIME part applies RFC 2822 line folding at ~72 characters. While this was historically needed for SMTP transport, modern email clients and the Gmail API handle long lines fine. The wrapping is applied after reading the input file, so even perfectly formatted single-line paragraphs get wrapped.

Suggested Fix

Option A (preferred): Stop hard-wrapping text/plain bodies by default. The Gmail API and modern email infrastructure do not require 72-char folding for message bodies.

Option B: Add a --no-wrap flag to disable line folding when the user wants to preserve their original formatting.

Option C (minimum): Document this behavior so users know --body content will be reformatted, and recommend --body-html as a workaround.

Workaround

Use --body-html with <p> tags instead of --body / --body-file. HTML bodies are not subject to line folding.

Environment

  • gogcli v0.12.0 (Homebrew, macOS)
  • Sending via Gmail API

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions