Commit 9a4131c
authored
feat(mail): reply-to-thread drafts (#115)
* feat(mail): reply-to-thread drafts
Extend `gro mail draft` with --reply-to and --reply-all flags, building on
the existing DraftMessage/buildMIME/CreateDraft pipeline rather than forking
a new command.
- gmail.Message: expose Cc, RFCMessageID, References, In-Reply-To from the
source message so the command layer can derive defaults.
- gmail.DraftMessage: add ThreadID, InReplyTo, References fields; buildMIME
emits the two new headers; guardHeaderInjection covers them; CreateDraft
sets Draft.Message.ThreadId.
- mail draft command: --reply-to fetches the source via existing GetMessage,
derives To/Subject/threading; --reply-all fetches the profile + reads any
--from alias to filter self out of the source To/Cc. Local validation
runs before any Gmail API call. deriveReplyDefaults is fallible and rejects
empty/malformed From or Message-Id headers, so we never silently produce a
broken reply.
- Re: prefixing is case-insensitive and locale-naive (we don't recognise
Aw/Sv/Sp variants — matches Gmail's own behaviour).
- Tests: 19 new cases across both layers (derivation, overrides, alias
filtering, missing/malformed headers, local-before-remote validation,
injection guard for the new flag and headers).
- Integration: T21-T26 verify wire-format headers via gro mail read --json
rather than UI inspection.
Closes #114
* fix(mail): address Codex PR review — lazy reply derivation + restored local guards
- deriveReplyDefaults now takes a replyNeeds struct and only parses source
headers for slots the caller actually consumes. An explicit --to override
no longer fails on a malformed source From; an explicit --cc override
no longer fails on malformed source To/Cc.
- Restore the local 'len(toAddrs) == 0' guard in non-reply mode so empty
--to fails before any Gmail API call (regression introduced by reply mode).
- Treat --reply-to "" as non-reply mode (don't call GetMessage with empty ID,
don't skip --to/--subject requirements). --reply-all --reply-to "" still
errors with the existing requires-reply-to message.
- New tests pin exact alias-filter expectations and cover the three new
edge cases above.
* test(mail): cover the most-valuable TDD review gaps
Added 4 tests for the highest-value defensive branches flagged by TDD review:
- TestDraftCommand_ReplyAll_GetProfileFails: error from GetProfile aborts before CreateDraft (without this test, a regression that swallows the error could leak the user's address into Cc).
- TestDraftCommand_ReplyAll_EmptyProfileFallsBackToFrom: empty profile + --from alias still produces correct self-filtering.
- TestDraftCommand_ReplyTo_FirstReplyEmptyReferences: source with no prior References produces a 1-element chain (just the source Message-Id).
- TestDraftCommand_ReplyTo_WithAttachment: threading headers survive the multipart path when --attach is also supplied.
Other suggestions in the TDD comment (addRePrefix edge cases, empty --subject "" override, srcReply() shared-pointer concern) are low-yield and skipped.
* fix(mail): reject empty --reply-to and empty --to override locally
Address Codex re-review: --reply-to with an empty value (a common
agentic-flow footgun when shell variables don't expand) now errors
explicitly rather than silently falling back to non-reply mode. In reply
mode, an explicit --to "" override is also rejected before any GetMessage
call.
* fix(mail): minor daemon polish — Refs dedup, T25 command, override test
- buildReferences dedupes the trailing Message-Id when the source's
References header already ends with it (some MUAs do this) and drops
the redundant empty-token guard inside strings.Fields.
- addRePrefix comment clarified to document that 're:foo' (no trailing
space) is treated as already-prefixed.
- New TestDraftCommand_ReplyAll_ExplicitToOverride pins the needs.To=false
+ needs.Cc=true combination.
- T25 integration row now has an executable command instead of prose.
* ci: gofmt + revive (ThreadId -> ThreadID)1 parent 4aebff7 commit 9a4131c
9 files changed
Lines changed: 958 additions & 13 deletions
File tree
- internal
- cmd/mail
- gmail
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
288 | 288 | | |
289 | 289 | | |
290 | 290 | | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
291 | 296 | | |
292 | 297 | | |
293 | 298 | | |
294 | 299 | | |
| 300 | + | |
| 301 | + | |
295 | 302 | | |
296 | 303 | | |
297 | 304 | | |
| |||
733 | 740 | | |
734 | 741 | | |
735 | 742 | | |
| 743 | + | |
| 744 | + | |
736 | 745 | | |
737 | 746 | | |
738 | 747 | | |
739 | 748 | | |
740 | 749 | | |
741 | 750 | | |
| 751 | + | |
| 752 | + | |
742 | 753 | | |
743 | 754 | | |
744 | 755 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
565 | 565 | | |
566 | 566 | | |
567 | 567 | | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
568 | 596 | | |
569 | 597 | | |
570 | 598 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
| 35 | + | |
34 | 36 | | |
35 | 37 | | |
36 | 38 | | |
| |||
50 | 52 | | |
51 | 53 | | |
52 | 54 | | |
53 | | - | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
54 | 58 | | |
55 | | - | |
56 | | - | |
57 | | - | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
58 | 64 | | |
59 | | - | |
60 | | - | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
61 | 79 | | |
62 | 80 | | |
63 | 81 | | |
64 | 82 | | |
65 | 83 | | |
66 | 84 | | |
| 85 | + | |
67 | 86 | | |
68 | 87 | | |
69 | 88 | | |
70 | 89 | | |
71 | 90 | | |
72 | 91 | | |
73 | | - | |
| 92 | + | |
74 | 93 | | |
75 | 94 | | |
76 | 95 | | |
77 | 96 | | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | 97 | | |
82 | 98 | | |
83 | 99 | | |
| |||
98 | 114 | | |
99 | 115 | | |
100 | 116 | | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
101 | 128 | | |
102 | 129 | | |
103 | 130 | | |
| |||
169 | 196 | | |
170 | 197 | | |
171 | 198 | | |
172 | | - | |
| 199 | + | |
173 | 200 | | |
174 | 201 | | |
175 | 202 | | |
176 | 203 | | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
177 | 256 | | |
178 | 257 | | |
179 | 258 | | |
| |||
183 | 262 | | |
184 | 263 | | |
185 | 264 | | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
186 | 268 | | |
187 | 269 | | |
188 | 270 | | |
| |||
226 | 308 | | |
227 | 309 | | |
228 | 310 | | |
| 311 | + | |
| 312 | + | |
229 | 313 | | |
230 | 314 | | |
231 | 315 | | |
232 | 316 | | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
233 | 434 | | |
234 | 435 | | |
235 | 436 | | |
| |||
0 commit comments