Repository navigation
Description
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
- Have a message in the mailbox whose HTML body references three inline images (
cid:parts withContent-Disposition: inline, as mail from Outlook typically has for signature images). Use three visibly different images. gws gmail +reply --message-id <ID> --html --body '<p>Test</p>' --draft- Read the draft back:
gws gmail users drafts get --params '{"userId":"me","id":"<draftId>","format":"raw"}'. The three image parts haveContent-IDand noX-Attachment-Id. Each<img>in the quote points at the right part. - 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.
- 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
EMN-scenario commentedon Nov 23, 2026
Related case with regular attachments: parts added with
-a/--attachcarry noX-Attachment-Idand noContent-ID(gws 0.22.5;+send,+reply,+reply-all,+forwardwith--draft). When such a draft is sent from the Gmail web UI, every attachment leaves with an emptyX-Attachment-Id:and the same emptyContent-ID: <>.Effect on recipients, seen twice in Nov 2026 (the raw sent copy held every file both times):
Repro:
gws gmail +send --to me@example.com --subject t --html --body '<p>x</p>' --draft -a a.pdf -a b.docxgws gmail users messages get --params '{"userId":"me","id":"<sent id>","format":"raw"}': both attachment parts have an emptyX-Attachment-Id:andContent-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 existingContent-IDvalues used by thecid: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