Skip to content

Gmail draft update: non-ASCII CC/From/BCC headers not RFC 2047 encoded (mojibake) #404

@HaseU-git

Description

@HaseU-git

Description

When updating a Gmail draft via gws gmail users drafts update, non-ASCII characters in CC, From, and BCC header display names result in mojibake. For example, Japanese display names are garbled when viewed in Gmail.

Steps to Reproduce

  1. Create or update a Gmail draft with a CC recipient that has a non-ASCII display name:
    gws gmail users drafts update --params '{"userId": "me", "id": "<draft_id>"}' \
      --json '{"message": {"raw": "<base64_encoded_message>"}}'
  2. The raw MIME message includes a CC header like:
    Cc: "日本語名前" <user@example.com>
    
  3. Open the draft in Gmail — the display name is garbled (e.g., 日本語å instead of 日本語名前).

Expected Behavior

Non-ASCII display names in CC/From/BCC headers should be RFC 2047 encoded, e.g.:

Cc: =?UTF-8?B?5pel5pys6Kqe5ZCN5YmN?= <user@example.com>

Root Cause

In src/helpers/gmail/mod.rs, the MessageBuilder::build() method correctly applies encode_header_value() (RFC 2047 encoding) to the Subject header (line ~308), but the CC, From, and BCC headers (lines ~321-332) only use sanitize_header_value(), which strips CRLF characters but does not encode non-ASCII characters:

// Subject — correctly encoded
format!("Subject: {}", encode_header_value(&sanitize_header_value(self.subject)))

// CC — missing encode_header_value()
format!("\r\nCc: {}", sanitize_header_value(cc))

Suggested Fix

Apply encode_header_value() to CC, From, and BCC headers, same as Subject:

if let Some(cc) = self.cc {
    headers.push_str(&format!("\r\nCc: {}", encode_header_value(&sanitize_header_value(cc))));
}

Same for from and bcc.

Environment

  • gws installed via Homebrew on macOS (Apple Silicon)
  • Affected version: latest as of 2026-03-11

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions