gws-cli 1.4.0__tar.gz → 1.5.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. {gws_cli-1.4.0 → gws_cli-1.5.0}/PKG-INFO +1 -1
  2. {gws_cli-1.4.0 → gws_cli-1.5.0}/pyproject.toml +1 -1
  3. {gws_cli-1.4.0 → gws_cli-1.5.0}/reference/gmail.md +9 -1
  4. {gws_cli-1.4.0 → gws_cli-1.5.0}/src/gws/__init__.py +1 -1
  5. {gws_cli-1.4.0 → gws_cli-1.5.0}/src/gws/commands/gmail.py +20 -1
  6. {gws_cli-1.4.0 → gws_cli-1.5.0}/src/gws/services/gmail.py +96 -41
  7. {gws_cli-1.4.0 → gws_cli-1.5.0}/tests/test_gmail_mime.py +121 -0
  8. {gws_cli-1.4.0 → gws_cli-1.5.0}/.gitignore +0 -0
  9. {gws_cli-1.4.0 → gws_cli-1.5.0}/CLAUDE.md +0 -0
  10. {gws_cli-1.4.0 → gws_cli-1.5.0}/COMPARISON-REPORT.md +0 -0
  11. {gws_cli-1.4.0 → gws_cli-1.5.0}/LICENSE +0 -0
  12. {gws_cli-1.4.0 → gws_cli-1.5.0}/LIVE_TESTING.md +0 -0
  13. {gws_cli-1.4.0 → gws_cli-1.5.0}/README.md +0 -0
  14. {gws_cli-1.4.0 → gws_cli-1.5.0}/SKILL-advanced.md +0 -0
  15. {gws_cli-1.4.0 → gws_cli-1.5.0}/SKILL-typesetting.md +0 -0
  16. {gws_cli-1.4.0 → gws_cli-1.5.0}/SKILL.md +0 -0
  17. {gws_cli-1.4.0 → gws_cli-1.5.0}/TESTING.md +0 -0
  18. {gws_cli-1.4.0 → gws_cli-1.5.0}/docs/plans/2026-03-07-download-security-gate.md +0 -0
  19. {gws_cli-1.4.0 → gws_cli-1.5.0}/docs/plans/2026-03-07-security-hardening-design.md +0 -0
  20. {gws_cli-1.4.0 → gws_cli-1.5.0}/docs/plans/2026-03-07-security-hardening-plan.md +0 -0
  21. {gws_cli-1.4.0 → gws_cli-1.5.0}/reference/calendar.md +0 -0
  22. {gws_cli-1.4.0 → gws_cli-1.5.0}/reference/contacts.md +0 -0
  23. {gws_cli-1.4.0 → gws_cli-1.5.0}/reference/docs.md +0 -0
  24. {gws_cli-1.4.0 → gws_cli-1.5.0}/reference/drive.md +0 -0
  25. {gws_cli-1.4.0 → gws_cli-1.5.0}/reference/sheets.md +0 -0
  26. {gws_cli-1.4.0 → gws_cli-1.5.0}/reference/slides.md +0 -0
  27. {gws_cli-1.4.0 → gws_cli-1.5.0}/src/gws/__main__.py +0 -0
  28. {gws_cli-1.4.0 → gws_cli-1.5.0}/src/gws/auth/__init__.py +0 -0
  29. {gws_cli-1.4.0 → gws_cli-1.5.0}/src/gws/auth/oauth.py +0 -0
  30. {gws_cli-1.4.0 → gws_cli-1.5.0}/src/gws/auth/provider.py +0 -0
  31. {gws_cli-1.4.0 → gws_cli-1.5.0}/src/gws/auth/scopes.py +0 -0
  32. {gws_cli-1.4.0 → gws_cli-1.5.0}/src/gws/auth/server.py +0 -0
  33. {gws_cli-1.4.0 → gws_cli-1.5.0}/src/gws/cli.py +0 -0
  34. {gws_cli-1.4.0 → gws_cli-1.5.0}/src/gws/commands/__init__.py +0 -0
  35. {gws_cli-1.4.0 → gws_cli-1.5.0}/src/gws/commands/_account.py +0 -0
  36. {gws_cli-1.4.0 → gws_cli-1.5.0}/src/gws/commands/account.py +0 -0
  37. {gws_cli-1.4.0 → gws_cli-1.5.0}/src/gws/commands/auth.py +0 -0
  38. {gws_cli-1.4.0 → gws_cli-1.5.0}/src/gws/commands/calendar.py +0 -0
  39. {gws_cli-1.4.0 → gws_cli-1.5.0}/src/gws/commands/config.py +0 -0
  40. {gws_cli-1.4.0 → gws_cli-1.5.0}/src/gws/commands/contacts.py +0 -0
  41. {gws_cli-1.4.0 → gws_cli-1.5.0}/src/gws/commands/convert.py +0 -0
  42. {gws_cli-1.4.0 → gws_cli-1.5.0}/src/gws/commands/docs.py +0 -0
  43. {gws_cli-1.4.0 → gws_cli-1.5.0}/src/gws/commands/drive.py +0 -0
  44. {gws_cli-1.4.0 → gws_cli-1.5.0}/src/gws/commands/sheets.py +0 -0
  45. {gws_cli-1.4.0 → gws_cli-1.5.0}/src/gws/commands/slides.py +0 -0
  46. {gws_cli-1.4.0 → gws_cli-1.5.0}/src/gws/config.py +0 -0
  47. {gws_cli-1.4.0 → gws_cli-1.5.0}/src/gws/context.py +0 -0
  48. {gws_cli-1.4.0 → gws_cli-1.5.0}/src/gws/crypto.py +0 -0
  49. {gws_cli-1.4.0 → gws_cli-1.5.0}/src/gws/exceptions.py +0 -0
  50. {gws_cli-1.4.0 → gws_cli-1.5.0}/src/gws/output.py +0 -0
  51. {gws_cli-1.4.0 → gws_cli-1.5.0}/src/gws/services/__init__.py +0 -0
  52. {gws_cli-1.4.0 → gws_cli-1.5.0}/src/gws/services/base.py +0 -0
  53. {gws_cli-1.4.0 → gws_cli-1.5.0}/src/gws/services/calendar.py +0 -0
  54. {gws_cli-1.4.0 → gws_cli-1.5.0}/src/gws/services/contacts.py +0 -0
  55. {gws_cli-1.4.0 → gws_cli-1.5.0}/src/gws/services/convert.py +0 -0
  56. {gws_cli-1.4.0 → gws_cli-1.5.0}/src/gws/services/docs.py +0 -0
  57. {gws_cli-1.4.0 → gws_cli-1.5.0}/src/gws/services/drive.py +0 -0
  58. {gws_cli-1.4.0 → gws_cli-1.5.0}/src/gws/services/sheets.py +0 -0
  59. {gws_cli-1.4.0 → gws_cli-1.5.0}/src/gws/services/slides.py +0 -0
  60. {gws_cli-1.4.0 → gws_cli-1.5.0}/src/gws/utils/__init__.py +0 -0
  61. {gws_cli-1.4.0 → gws_cli-1.5.0}/src/gws/utils/colors.py +0 -0
  62. {gws_cli-1.4.0 → gws_cli-1.5.0}/src/gws/utils/diagrams.py +0 -0
  63. {gws_cli-1.4.0 → gws_cli-1.5.0}/src/gws/utils/retry.py +0 -0
  64. {gws_cli-1.4.0 → gws_cli-1.5.0}/src/gws/utils/security.py +0 -0
  65. {gws_cli-1.4.0 → gws_cli-1.5.0}/tests/__init__.py +0 -0
  66. {gws_cli-1.4.0 → gws_cli-1.5.0}/tests/conftest.py +0 -0
  67. {gws_cli-1.4.0 → gws_cli-1.5.0}/tests/test_account_commands.py +0 -0
  68. {gws_cli-1.4.0 → gws_cli-1.5.0}/tests/test_account_enforcement.py +0 -0
  69. {gws_cli-1.4.0 → gws_cli-1.5.0}/tests/test_auth_accounts.py +0 -0
  70. {gws_cli-1.4.0 → gws_cli-1.5.0}/tests/test_auth_provider.py +0 -0
  71. {gws_cli-1.4.0 → gws_cli-1.5.0}/tests/test_config_accounts.py +0 -0
  72. {gws_cli-1.4.0 → gws_cli-1.5.0}/tests/test_crypto.py +0 -0
  73. {gws_cli-1.4.0 → gws_cli-1.5.0}/tests/test_docs.py +0 -0
  74. {gws_cli-1.4.0 → gws_cli-1.5.0}/tests/test_download_screening.py +0 -0
  75. {gws_cli-1.4.0 → gws_cli-1.5.0}/tests/test_output.py +0 -0
  76. {gws_cli-1.4.0 → gws_cli-1.5.0}/tests/test_server_auth.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gws-cli
3
- Version: 1.4.0
3
+ Version: 1.5.0
4
4
  Summary: Google Workspace CLI - Unified management for Docs, Sheets, Slides, Drive, Gmail, Calendar, and Contacts
5
5
  Project-URL: Homepage, https://github.com/andmarios/google-workspace-skill
6
6
  Project-URL: Repository, https://github.com/andmarios/google-workspace-skill
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "gws-cli"
7
- version = "1.4.0"
7
+ version = "1.5.0"
8
8
  description = "Google Workspace CLI - Unified management for Docs, Sheets, Slides, Drive, Gmail, Calendar, and Contacts"
9
9
  readme = "README.md"
10
10
  license = "MIT"
@@ -48,9 +48,17 @@ EOF
48
48
  uvx gws-cli gmail send "recipient@example.com" "Subject" "Body" \
49
49
  --from-name "John Doe" --signature "Best regards,\nJohn"
50
50
 
51
- # Reply to message
51
+ # Reply to message (stays in-thread via In-Reply-To/References)
52
52
  uvx gws-cli gmail reply <message_id> "Reply body"
53
53
 
54
+ # Reply with Cc/Bcc
55
+ uvx gws-cli gmail reply <message_id> "Reply body" --cc "a@x.com,b@y.com" --bcc "c@z.com"
56
+
57
+ # Reply-all: also address the original To + Cc (excluding yourself).
58
+ # Combine with --cc to add extra recipients on top.
59
+ uvx gws-cli gmail reply <message_id> "Reply body" --all
60
+ uvx gws-cli gmail reply <message_id> "Reply body" --all --cc "extra@x.com"
61
+
54
62
  # Mark as read/unread
55
63
  uvx gws-cli gmail mark-read <message_id>
56
64
  uvx gws-cli gmail mark-unread <message_id>
@@ -1,3 +1,3 @@
1
1
  """Google Workspace CLI - Unified management for Google services."""
2
2
 
3
- __version__ = "1.4.0"
3
+ __version__ = "1.5.0"
@@ -138,8 +138,24 @@ def reply_to_message(
138
138
  Optional[str],
139
139
  typer.Option("--signature", "-s", help="Email signature to append."),
140
140
  ] = None,
141
+ cc: Annotated[
142
+ Optional[str],
143
+ typer.Option("--cc", help="Cc recipients (comma-separated)."),
144
+ ] = None,
145
+ bcc: Annotated[
146
+ Optional[str],
147
+ typer.Option("--bcc", help="Bcc recipients (comma-separated)."),
148
+ ] = None,
149
+ reply_all: Annotated[
150
+ bool,
151
+ typer.Option("--all", help="Reply to all: include original To/Cc (minus yourself)."),
152
+ ] = False,
141
153
  ) -> None:
142
- """Reply to an existing message (HTML by default)."""
154
+ """Reply to an existing message (HTML by default, stays in-thread).
155
+
156
+ Use --all to reply to everyone (original To + Cc, excluding yourself);
157
+ --cc/--bcc add recipients and are unioned with --all.
158
+ """
143
159
  if stdin:
144
160
  body = sys.stdin.read()
145
161
  elif body is None:
@@ -157,6 +173,9 @@ def reply_to_message(
157
173
  html=not plain_text,
158
174
  from_name=from_name,
159
175
  signature=signature,
176
+ cc=cc,
177
+ bcc=bcc,
178
+ reply_all=reply_all,
160
179
  )
161
180
 
162
181
 
@@ -8,6 +8,7 @@ from email import encoders
8
8
  from email.mime.base import MIMEBase
9
9
  from email.mime.multipart import MIMEMultipart
10
10
  from email.mime.text import MIMEText
11
+ from email.utils import formataddr, getaddresses
11
12
  from typing import Any
12
13
 
13
14
  from googleapiclient.errors import HttpError
@@ -176,6 +177,37 @@ class GmailService(BaseService):
176
177
  )
177
178
  raise SystemExit(ExitCode.API_ERROR)
178
179
 
180
+ def _header_map(self, payload: dict) -> dict[str, str]:
181
+ """Return a case-insensitive header map keyed by lowercase name.
182
+
183
+ Gmail returns header names with the case they were written in. Messages
184
+ built locally via MIMEText use lowercase names ('to', 'cc', 'subject'),
185
+ so any read of draft/self-built headers MUST look them up case-
186
+ insensitively or they come back empty.
187
+ """
188
+ return {
189
+ h["name"].lower(): h["value"]
190
+ for h in payload.get("headers", [])
191
+ }
192
+
193
+ @staticmethod
194
+ def _merge_addresses(values: list[str], exclude: list[str] | None = None) -> str:
195
+ """Parse address header strings, drop excluded emails (case-insensitive)
196
+ and duplicates while preserving order, and return a comma-joined string.
197
+ """
198
+ exclude_l = {e.lower() for e in (exclude or []) if e}
199
+ seen: set[str] = set()
200
+ out: list[str] = []
201
+ for name, addr in getaddresses([v for v in values if v]):
202
+ if not addr:
203
+ continue
204
+ key = addr.lower()
205
+ if key in exclude_l or key in seen:
206
+ continue
207
+ seen.add(key)
208
+ out.append(formataddr((name, addr)) if name else addr)
209
+ return ", ".join(out)
210
+
179
211
  def _extract_body(self, payload: dict) -> str:
180
212
  """Extract message body from payload."""
181
213
  if "body" in payload and payload["body"].get("data"):
@@ -309,8 +341,16 @@ class GmailService(BaseService):
309
341
  html: bool = False,
310
342
  from_name: str | None = None,
311
343
  signature: str | None = None,
344
+ cc: str | None = None,
345
+ bcc: str | None = None,
346
+ reply_all: bool = False,
312
347
  ) -> dict[str, Any]:
313
- """Reply to an existing message."""
348
+ """Reply to an existing message (stays threaded via In-Reply-To/References).
349
+
350
+ By default replies only to the sender. With reply_all=True, also
351
+ addresses the original To recipients and Cc's the original Cc list,
352
+ excluding your own address. Explicit cc/bcc are unioned in.
353
+ """
314
354
  try:
315
355
  # Unescape shell-escaped characters
316
356
  body = self._unescape_text(body)
@@ -325,36 +365,60 @@ class GmailService(BaseService):
325
365
  )
326
366
 
327
367
  thread_id = original["threadId"]
328
- headers = {
329
- h["name"]: h["value"]
330
- for h in original.get("payload", {}).get("headers", [])
331
- }
368
+ # Case-insensitive: sent/self-built messages may use lowercase names.
369
+ ci_headers = self._header_map(original.get("payload", {}))
332
370
 
333
371
  # Append signature if provided
334
372
  full_body = body
335
373
  if signature:
336
374
  full_body = f"{body}\n\n--\n{signature}"
337
375
 
338
- # Build reply - use MIMEText directly
339
376
  subtype = "html" if html else "plain"
340
377
  message = MIMEText(full_body, subtype, "utf-8")
341
378
 
342
- # Set From with display name if provided
343
- if from_name:
344
- profile = self.get_profile()
345
- email_address = profile.get("emailAddress", "")
346
- if email_address:
347
- message["from"] = f'"{from_name}" <{email_address}>'
348
-
349
- # Reply to the sender — use case-insensitive header lookup
350
- # Gmail API may return lowercase header names (from, to) for sent messages
351
- ci_headers = {k.lower(): v for k, v in headers.items()}
352
- reply_to = ci_headers.get("reply-to", ci_headers.get("from", ""))
353
- if not reply_to:
354
- reply_to = ci_headers.get("to", "")
355
- message["to"] = reply_to
379
+ # Our own address — needed to set a named From and to exclude
380
+ # ourselves from reply-all recipients.
381
+ self_email = ""
382
+ if from_name or reply_all:
383
+ self_email = self.get_profile().get("emailAddress", "")
384
+ if from_name and self_email:
385
+ message["from"] = f'"{from_name}" <{self_email}>'
386
+
387
+ # Primary recipient: original sender (Reply-To > From > To).
388
+ reply_to = (
389
+ ci_headers.get("reply-to")
390
+ or ci_headers.get("from")
391
+ or ci_headers.get("to", "")
392
+ )
393
+ if reply_all:
394
+ to_value = self._merge_addresses(
395
+ [reply_to, ci_headers.get("to", "")], exclude=[self_email]
396
+ )
397
+ else:
398
+ to_value = reply_to
399
+ message["to"] = to_value
356
400
  message["subject"] = f"Re: {ci_headers.get('subject', '')}"
357
401
 
402
+ # Cc: original Cc (reply-all only) unioned with an explicit --cc,
403
+ # minus ourselves and anyone already addressed in To.
404
+ cc_sources = []
405
+ if reply_all:
406
+ cc_sources.append(ci_headers.get("cc", ""))
407
+ if cc:
408
+ cc_sources.append(cc)
409
+ if cc_sources:
410
+ to_emails = [addr for _, addr in getaddresses([to_value])]
411
+ combined_cc = self._merge_addresses(
412
+ cc_sources, exclude=[self_email, *to_emails]
413
+ )
414
+ if combined_cc:
415
+ message["cc"] = combined_cc
416
+
417
+ if bcc:
418
+ bcc_value = self._merge_addresses([bcc], exclude=[self_email])
419
+ if bcc_value:
420
+ message["bcc"] = bcc_value
421
+
358
422
  # Set references for threading
359
423
  message_id_header = ci_headers.get("message-id", "")
360
424
  if message_id_header:
@@ -694,16 +758,13 @@ class GmailService(BaseService):
694
758
  continue
695
759
 
696
760
  msg = draft.get("message", {})
697
- headers = {
698
- h["name"]: h["value"]
699
- for h in msg.get("payload", {}).get("headers", [])
700
- }
761
+ headers = self._header_map(msg.get("payload", {}))
701
762
 
702
763
  drafts.append({
703
764
  "id": draft["id"],
704
765
  "message_id": msg.get("id"),
705
- "subject": headers.get("Subject", "(no subject)"),
706
- "to": headers.get("To", ""),
766
+ "subject": headers.get("subject", "(no subject)"),
767
+ "to": headers.get("to", ""),
707
768
  "snippet": msg.get("snippet", "")[:100],
708
769
  })
709
770
 
@@ -737,10 +798,7 @@ class GmailService(BaseService):
737
798
  )
738
799
 
739
800
  msg = draft.get("message", {})
740
- headers = {
741
- h["name"]: h["value"]
742
- for h in msg.get("payload", {}).get("headers", [])
743
- }
801
+ headers = self._header_map(msg.get("payload", {}))
744
802
 
745
803
  body = self._extract_body(msg.get("payload", {}))
746
804
 
@@ -749,13 +807,13 @@ class GmailService(BaseService):
749
807
  source_type="email",
750
808
  source_id=draft["id"],
751
809
  content_fields={
752
- "subject": headers.get("Subject", "(no subject)"),
810
+ "subject": headers.get("subject", "(no subject)"),
753
811
  "body": body,
754
812
  },
755
813
  draft_id=draft["id"],
756
814
  message_id=msg.get("id"),
757
- to=headers.get("To", ""),
758
- cc=headers.get("Cc", ""),
815
+ to=headers.get("to", ""),
816
+ cc=headers.get("cc", ""),
759
817
  )
760
818
  return draft
761
819
  except HttpError as e:
@@ -854,18 +912,15 @@ class GmailService(BaseService):
854
912
  )
855
913
 
856
914
  current_msg = current_draft.get("message", {})
857
- current_headers = {
858
- h["name"]: h["value"]
859
- for h in current_msg.get("payload", {}).get("headers", [])
860
- }
915
+ current_headers = self._header_map(current_msg.get("payload", {}))
861
916
  current_body = self._extract_body(current_msg.get("payload", {}))
862
917
 
863
918
  # Use new values or preserve existing
864
- final_to = to if to is not None else current_headers.get("To", "")
865
- final_subject = subject if subject is not None else current_headers.get("Subject", "")
919
+ final_to = to if to is not None else current_headers.get("to", "")
920
+ final_subject = subject if subject is not None else current_headers.get("subject", "")
866
921
  final_body = body if body is not None else current_body
867
- final_cc = cc if cc is not None else current_headers.get("Cc")
868
- final_bcc = bcc if bcc is not None else current_headers.get("Bcc")
922
+ final_cc = cc if cc is not None else current_headers.get("cc")
923
+ final_bcc = bcc if bcc is not None else current_headers.get("bcc")
869
924
 
870
925
  # Unescape shell-escaped characters
871
926
  final_subject = self._unescape_text(final_subject)
@@ -351,3 +351,124 @@ class TestGetProfile:
351
351
  with patch.object(BaseService, "execute", side_effect=http_error):
352
352
  result = gmail_service.get_profile()
353
353
  assert result == {}
354
+
355
+
356
+ # =============================================================================
357
+ # DRAFT HEADER CASE-INSENSITIVITY TESTS
358
+ # =============================================================================
359
+
360
+
361
+ class TestDraftHeaderCase:
362
+ """Drafts built via MIMEText store lowercase header names ('to','cc',
363
+ 'subject'); reads must be case-insensitive or they come back empty."""
364
+
365
+ def _lowercase_draft(self):
366
+ return {
367
+ "id": "draft-1",
368
+ "message": {
369
+ "id": "msg-1",
370
+ "payload": {
371
+ "headers": [
372
+ {"name": "to", "value": "a@x.com"},
373
+ {"name": "cc", "value": "c@x.com"},
374
+ {"name": "subject", "value": "Hello there"},
375
+ ],
376
+ "body": {},
377
+ },
378
+ },
379
+ }
380
+
381
+ def test_get_draft_reads_lowercase_headers(self, gmail_service):
382
+ gmail_service._mock_gmail_api.users().drafts().get().execute.return_value = (
383
+ self._lowercase_draft()
384
+ )
385
+ with patch("gws.services.gmail.output_external_content") as mock_out:
386
+ gmail_service.get_draft("draft-1")
387
+ kwargs = mock_out.call_args.kwargs
388
+ assert kwargs["to"] == "a@x.com"
389
+ assert kwargs["cc"] == "c@x.com"
390
+ assert kwargs["content_fields"]["subject"] == "Hello there"
391
+
392
+ def test_update_draft_body_only_preserves_recipients(self, gmail_service):
393
+ """Updating only the body must not wipe to/cc/subject (lowercase headers)."""
394
+ gmail_service._mock_gmail_api.users().drafts().get().execute.return_value = (
395
+ self._lowercase_draft()
396
+ )
397
+ gmail_service._mock_gmail_api.users().drafts().update().execute.return_value = {
398
+ "id": "draft-1"
399
+ }
400
+ gmail_service.update_draft("draft-1", body="brand new body")
401
+
402
+ update_call = gmail_service._mock_gmail_api.users().drafts().update
403
+ raw_b64 = update_call.call_args.kwargs["body"]["message"]["raw"]
404
+ mime = email.message_from_bytes(base64.urlsafe_b64decode(raw_b64))
405
+ assert mime["to"] == "a@x.com"
406
+ assert mime["subject"] == "Hello there"
407
+ assert mime["cc"] == "c@x.com"
408
+
409
+
410
+ # =============================================================================
411
+ # REPLY CC/BCC + REPLY-ALL TESTS
412
+ # =============================================================================
413
+
414
+
415
+ class TestReplyRecipients:
416
+ """reply must support --cc/--bcc and --all (reply-all), while still
417
+ threading (In-Reply-To/References)."""
418
+
419
+ def _setup(self, gmail_service, orig_headers):
420
+ gmail_service._mock_gmail_api.users().messages().get().execute.return_value = {
421
+ "id": "m1",
422
+ "threadId": "t1",
423
+ "payload": {
424
+ "headers": [{"name": k, "value": v} for k, v in orig_headers.items()]
425
+ },
426
+ }
427
+ gmail_service._mock_gmail_api.users().messages().send().execute.return_value = {
428
+ "id": "r1",
429
+ "threadId": "t1",
430
+ }
431
+
432
+ def test_reply_with_cc_and_bcc(self, gmail_service, capsys):
433
+ self._setup(gmail_service, {
434
+ "from": "alice@x.com", "subject": "Hi", "message-id": "<m1@x>",
435
+ })
436
+ gmail_service.reply_to_message("m1", "body", cc="c@x.com", bcc="b@x.com")
437
+ capsys.readouterr()
438
+ mime = decode_raw_message(gmail_service._mock_gmail_api)
439
+ assert mime["to"] == "alice@x.com"
440
+ assert mime["cc"] == "c@x.com"
441
+ assert mime["bcc"] == "b@x.com"
442
+ assert mime["In-Reply-To"] == "<m1@x>" # still threads
443
+
444
+ def test_reply_all_gathers_recipients_minus_self(self, gmail_service, capsys):
445
+ with patch.object(GmailService, "get_profile",
446
+ return_value={"emailAddress": "me@x.com"}):
447
+ self._setup(gmail_service, {
448
+ "from": "alice@x.com",
449
+ "to": "me@x.com, bob@x.com",
450
+ "cc": "carol@x.com, me@x.com",
451
+ "subject": "Hi", "message-id": "<m1@x>",
452
+ })
453
+ gmail_service.reply_to_message("m1", "body", reply_all=True)
454
+ capsys.readouterr()
455
+ mime = decode_raw_message(gmail_service._mock_gmail_api)
456
+ to = mime["to"]
457
+ assert "alice@x.com" in to and "bob@x.com" in to
458
+ assert "me@x.com" not in to # self excluded
459
+ cc = mime["cc"] or ""
460
+ assert "carol@x.com" in cc
461
+ assert "me@x.com" not in cc # self excluded from cc too
462
+
463
+ def test_reply_all_unions_explicit_cc(self, gmail_service, capsys):
464
+ with patch.object(GmailService, "get_profile",
465
+ return_value={"emailAddress": "me@x.com"}):
466
+ self._setup(gmail_service, {
467
+ "from": "alice@x.com", "cc": "carol@x.com",
468
+ "subject": "Hi", "message-id": "<m1@x>",
469
+ })
470
+ gmail_service.reply_to_message("m1", "body", reply_all=True, cc="dan@x.com")
471
+ capsys.readouterr()
472
+ mime = decode_raw_message(gmail_service._mock_gmail_api)
473
+ cc = mime["cc"] or ""
474
+ assert "carol@x.com" in cc and "dan@x.com" in cc
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes