Skip to content

gmail +reply/+reply-all --html --draft: inline images swap when the draft is edited in Gmail (parts lack X-Attachment-Id) #988

Open

Description

@astradevkin

Summary

A draft created with gws gmail +reply --html --draft (or +reply-all) carries the quoted email's inline images as multipart/related parts with a Content-ID but no X-Attachment-Id. When that draft is then opened and edited in the Gmail web composer, Gmail re-binds those images by position on autosave, and the cid: references end up pointing at the wrong parts. The images in the quote swap places. If the draft also holds other inline images without X-Attachment-Id, those get mixed in too.

The editor keeps showing the correct pictures while this happens, so the draft looks fine until it is sent or read back.

Version

gws 0.22.5 (latest release at the time of writing), macOS. Gmail web composer in Chrome 157.

Steps to reproduce

  1. Have a message in the mailbox whose HTML body references three inline images (cid: parts with Content-Disposition: inline, as mail from Outlook typically has for signature images). Use three visibly different images.
  2. gws gmail +reply --message-id <ID> --html --body '<p>Test</p>' --draft
  3. Read the draft back: gws gmail users drafts get --params '{"userId":"me","id":"<draftId>","format":"raw"}'. The three image parts have Content-ID and no X-Attachment-Id. Each <img> in the quote points at the right part.
  4. Open the draft in Gmail on the web (it shows at the bottom of the thread), expand the quoted text, type a few characters in the body, wait for "Draft saved". Repeat the edit a few times.
  5. Read the draft back again as in step 3.

Expected

Each <img src="cid:..."> in the quote still resolves to the same image bytes as before.

Actual

After one to four edits the cid: references resolve to different image parts than before. In the stored message every image part has been rewritten to Content-Disposition: attachment; filename="noname" with an empty X-Attachment-Id: header, and the parts are in a different order.

Measured with five labelled images (A, B added to the reply body by hand as extra cid: parts; C, D, E from the quoted message), expected order A B C D E:

Draft Action in Gmail Order after
+reply-all --html --draft, plus two hand-added inline parts, nothing tagged 1 edit E A C D B
+reply-all --html --draft only 1 edit C D E (unchanged)
same draft 3 more edits E D C
same as row 1, but body parts given X-Attachment-Id, quoted parts left as the helper made them 1 edit A B E C D
same as row 1, every image part given X-Attachment-Id equal to its Content-ID 4 edits, then sent from the Gmail UI A B C D E

Sending a draft through the API without opening it in the Gmail UI is not affected; the parts go out untouched.

Likely cause

The Gmail composer loads each inline image from a URL of the form ...&attid=0.N&...&realattid=<X-Attachment-Id>. With no X-Attachment-Id, only the positional attid=0.N is available, and Gmail reorders the parts when it re-saves the draft.

finalize_message in crates/google-workspace-cli/src/helpers/gmail/mod.rs builds each multipart/related inline part as MimePart::new(...).inline().cid(cid), so the part gets a Content-ID and nothing else to identify it.

Suggested fix

When emitting an inline part, also set X-Attachment-Id to the Content-ID value (without angle brackets). That is what Gmail's own composer writes for images it inserts (Content-ID: <ii_xxxx> with X-Attachment-Id: ii_xxxx). In the test above this alone kept every image bound correctly through repeated edits and a send from the Gmail UI. The same applies to +forward with --html, which carries inline parts the same way.

Impact

Any workflow where a reply draft is prepared with the CLI and then finished by a person in Gmail. In the mild case the quoted signature images trade places. In the worse case, images placed in the reply body are replaced by images from the quoted message, and the email goes out that way.

Activity

  1. EMN-scenario commented on Nov 23, 2026

    @EMN-scenario

    Related case with regular attachments: parts added with -a/--attach carry no X-Attachment-Id and no Content-ID (gws 0.22.5; +send, +reply, +reply-all, +forward with --draft). When such a draft is sent from the Gmail web UI, every attachment leaves with an empty X-Attachment-Id: and the same empty Content-ID: <>.

    Effect on recipients, seen twice in Nov 2026 (the raw sent copy held every file both times):

    • Outlook showed only the first of 2 PDFs;
    • Apple Mail showed a PDF + a .docx as 2 copies of the .docx, and forwarded only the .docx.

    Repro:

    1. gws gmail +send --to me@example.com --subject t --html --body '<p>x</p>' --draft -a a.pdf -a b.docx
    2. Send the draft from Gmail on the web.
    3. gws gmail users messages get --params '{"userId":"me","id":"<sent id>","format":"raw"}': both attachment parts have an empty X-Attachment-Id: and Content-ID: <>.

    Gmail web writes a unique f_<10 hex> value in both headers for each attachment it composes. Giving each attachment part such an id in the helpers' MIME builder would fix this case. For the inline parts of this issue, the existing Content-ID values used by the cid: references would need to stay as they are.

    Workaround meanwhile (assign the ids, create the draft again with the same threadId, delete the first one): hervenivon/skills#1

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

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