dex-connector-google-gmail 0.1.0__py3-none-any.whl

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.
@@ -0,0 +1,94 @@
1
+ Metadata-Version: 2.5
2
+ Name: dex-connector-google-gmail
3
+ Version: 0.1.0
4
+ Summary: Dex-native Python connector for Gmail
5
+ License-Expression: MIT
6
+ Requires-Python: >=3.11
7
+ Requires-Dist: dex-connectors-sdk==0.1.0
8
+ Requires-Dist: dex-python-sdk>=1.28.0
9
+ Requires-Dist: httpx>=0.27
10
+ Description-Content-Type: text/markdown
11
+
12
+ # Gmail connector for Python
13
+
14
+ `dex-connector-google-gmail` provides typed Gmail reads, sends, and replies for
15
+ Dex Python Flows. The package imports as `dex_connectors.google_gmail`.
16
+ Version 0.1.0 includes `getMessage`, `sendMessage`, and `replyToMessage` only;
17
+ the Go `messageReceived` and `replyReceived` Triggers are not available in Python.
18
+
19
+ ## Install
20
+
21
+ After release, install `dex-connector-google-gmail==0.1.0`. The package requires
22
+ `dex-connectors-sdk==0.1.0` and `dex-python-sdk>=1.28.0`; the latter provides
23
+ Go-compatible JSON field metadata and the Flow start and attempt deadline
24
+ needed for Gmail's duplicate-send fence.
25
+
26
+ ## Configure a connection
27
+
28
+ Use one static connection name in the Flow and in Dex Web **Connections**.
29
+ Select Google OAuth for a personal Gmail or ordinary Workspace mailbox. In
30
+ [Google Cloud Console](https://console.cloud.google.com/apis/credentials),
31
+ enable Gmail API, configure the consent screen, register the exact Dex redirect
32
+ URI on a Web application, then grant `openid`, UserInfo email, Gmail read-only,
33
+ and Gmail send scopes. Dex derives the verified primary email and stores the
34
+ access and refresh tokens in encrypted project storage. Its connection provider
35
+ coordinates token refresh and persists rotated refresh tokens. A service-account
36
+ key with Workspace domain-wide delegation is the administrator-only alternative.
37
+
38
+ The Python connector uses the same manifest authorization guide and safe
39
+ defaults as the Go connector. Dex CLI/Web 1.28.0 supports Python Flow
40
+ analysis, and the package includes generated `dex-connector.json` for Dex Web
41
+ connection discovery. Dex Web authorization has not been live-verified with
42
+ this package. Do not put access tokens, refresh tokens, or service-account
43
+ keys in Flow input, results, Attributes, Streams, logs, or mock reports.
44
+
45
+ ## Run the example
46
+
47
+ [`examples/thread_reply`](examples/thread_reply/main.py) reads one received
48
+ message, replies in its existing thread, and completes with the accepted reply
49
+ IDs. Its Worker loads the `gmail-inbox` connection from the Dex Web project
50
+ configuration. Factory calls keep their connection name and annotation fields
51
+ inline so Dex CLI can read the Flow definition; the factories also accept
52
+ `StepAnnotations` for programmatic construction. Dex CLI 1.28.1 is needed for
53
+ strict FDG analysis of this example's local Steps routing into connector Steps
54
+ (tracked in Dex issue #362). The entrypoint uses the public connection and Step
55
+ APIs:
56
+
57
+ ```python
58
+ connection = new_project_connection(project, CONNECTION_NAME)
59
+ await run_thread_reply_worker(
60
+ ThreadReplyFlow(connection),
61
+ os.environ.get("DEX_BLOB_CACHE_DIRECTORY", "/tmp/dex-gmail-thread-reply-cache"),
62
+ os.environ.get("DEX_SERVER_ADDRESS", "localhost:8801"),
63
+ )
64
+ ```
65
+
66
+ Run `dexcli dev`, then from this `python/` directory run
67
+ `DEX_CONNECTOR_CONFIG_FILE=/path/to/connections.json python -m examples.thread_reply.main`.
68
+ The Flow type is `ThreadReplyFlow`; its input JSON contains `messageId` and
69
+ `replyText`. Use a real mailbox message ID and a reply body with no secrets.
70
+ The [integration test](examples/thread_reply/tests/test_integration.py) runs
71
+ the same Flow on a real Dex Worker and Client with a local fake Gmail HTTP
72
+ boundary and manifest mocks.
73
+
74
+ ## Send confirmation
75
+
76
+ Gmail does not deduplicate messages by `Message-ID`. The connector derives a
77
+ stable run-specific RFC Message-ID from the Dex Call key, run ID, and Flow start
78
+ second. Its Python Mutation Steps use the manifest's asynchronous Execute
79
+ durability and persist the single-dispatch heartbeat before a POST. On a
80
+ numbered retry it searches Sent Mail first. A prior claimed send can only be
81
+ read back; a second POST requires a persisted `notSent` or `canResend` marker.
82
+ After a possibly accepted POST loses its answer or returns 5xx, the connector
83
+ polls Sent Mail before returning Retry. A successful 2xx is already accepted
84
+ even if its response is malformed, oversized, or unreadable; a Sent Mail miss
85
+ then returns `sent` with an empty message ID. A search miss after a claimed
86
+ POST remains Retry without another dispatch; the Flow fails when its retry
87
+ budget is exhausted. A definite 429 or 503 refusal, or a transport failure
88
+ proven to precede dispatch, permits a later send. The manifest limits sends
89
+ and replies to five attempts within two minutes.
90
+
91
+ Live provider authorization and these Gmail behaviors remain unverified without
92
+ a user-controlled account: retention of the client-set Message-ID header,
93
+ `rfc822msgid` search matching, and Sent Mail indexing latency. No live provider
94
+ credentials are included in this package.
@@ -0,0 +1,17 @@
1
+ dex_connectors/google_gmail/__init__.py,sha256=qsgiPcf4lqMt9YchUA8xjGyWDhimSMGeRnGRW0bKU8A,1553
2
+ dex_connectors/google_gmail/connection.py,sha256=P41zEGHyw66z0hT31WTYLz5eE9gR4M2MB_aF-9XnfLM,2264
3
+ dex_connectors/google_gmail/definitions.py,sha256=AJ2Wnl7shOrxa47kV_pkw_M9A0-E_ufOoWu-hZ8SBrE,2717
4
+ dex_connectors/google_gmail/dex-connector.json,sha256=YIm5qkAESErRbmZOaONi-aiZKC84lrpsu6uzNNm5PGI,2536
5
+ dex_connectors/google_gmail/models.py,sha256=LkZDAGTHAtU1Ai73a57cApPFHrXZ2ABXFJg-TYxhuvk,7964
6
+ dex_connectors/google_gmail/operations.py,sha256=i_QK8Z64yDF5BMRN3T2kQFF8fvSZ4tdJDgqiI-DiZI0,9643
7
+ dex_connectors/google_gmail/project.py,sha256=F8yQ_a5UlwVAAQK2vrSdcS8SI1TIfiLnojC5wgyqGWE,2198
8
+ dex_connectors/google_gmail/project_credentials.py,sha256=8CXAFxsqUYbKOs0tKpN4UcOFnv9hJcnw2oWwoEaywwY,3113
9
+ dex_connectors/google_gmail/provider.py,sha256=OjKkblnnXJxZmQm-Zo_boqpQQavbCGt2Hm7QiE82Upw,19228
10
+ dex_connectors/google_gmail/py.typed,sha256=ShfMsAGzSt4xuhCaf20ibgtfXl4pXomZb00ovUw6CeI,66
11
+ dex_connectors/google_gmail/refresh.py,sha256=RtjE0xF1rS9mBrxxulWtklukFIPbjYxR6cwbCFtmncA,5735
12
+ dex_connectors/google_gmail/send.py,sha256=rr8jx0pxVVHHVKo4KVo--flsVHBH7QbkQc1F9g-HOo8,26902
13
+ dex_connectors/google_gmail/steps.py,sha256=RQVHlDmsEIVJrF5dOwg_JypX17Qr9cJGKwEMhWcBNrQ,6896
14
+ dex_connectors/google_gmail/gmailmock/__init__.py,sha256=VNGjNwampPO1rJ75gh9j33UhLde6UFYrhFRvmjBeBF8,7984
15
+ dex_connector_google_gmail-0.1.0.dist-info/METADATA,sha256=CuB7Rx_c7sagYhNmK1H-hmTT28GnoB4KJX73mXmfbOU,4885
16
+ dex_connector_google_gmail-0.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
17
+ dex_connector_google_gmail-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.33.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,60 @@
1
+ # Copyright (c) 2026 Super Durable
2
+ # SPDX-License-Identifier: MIT
3
+ """Gmail operations for Dex Flows."""
4
+
5
+ from .connection import Connection, new_connection
6
+ from .definitions import (
7
+ CONNECTOR_ID,
8
+ GET_MESSAGE_DEFINITION,
9
+ PROVIDER,
10
+ REPLY_TO_MESSAGE_DEFINITION,
11
+ SEND_MESSAGE_DEFINITION,
12
+ )
13
+ from .models import (
14
+ Config,
15
+ Credentials,
16
+ GetMessageInput,
17
+ Message,
18
+ ReplyToMessageInput,
19
+ SendMessageInput,
20
+ SendMessageOutput,
21
+ )
22
+ from .operations import GetMessageOperation, ReplyToMessageOperation, SendMessageOperation
23
+ from .project import new_project_connection, new_project_provider
24
+ from .project_credentials import decode_credentials, encode_credentials
25
+ from .provider import GmailProvider
26
+ from .refresh import CredentialRefreshDriver
27
+ from .steps import (
28
+ new_get_message_step,
29
+ new_reply_to_message_step,
30
+ new_send_message_step,
31
+ )
32
+
33
+ __all__ = [
34
+ "CONNECTOR_ID",
35
+ "PROVIDER",
36
+ "Config",
37
+ "Connection",
38
+ "Credentials",
39
+ "CredentialRefreshDriver",
40
+ "GetMessageInput",
41
+ "GetMessageOperation",
42
+ "GmailProvider",
43
+ "Message",
44
+ "ReplyToMessageInput",
45
+ "ReplyToMessageOperation",
46
+ "SendMessageInput",
47
+ "SendMessageOperation",
48
+ "SendMessageOutput",
49
+ "GET_MESSAGE_DEFINITION",
50
+ "SEND_MESSAGE_DEFINITION",
51
+ "REPLY_TO_MESSAGE_DEFINITION",
52
+ "decode_credentials",
53
+ "encode_credentials",
54
+ "new_connection",
55
+ "new_get_message_step",
56
+ "new_project_connection",
57
+ "new_project_provider",
58
+ "new_reply_to_message_step",
59
+ "new_send_message_step",
60
+ ]
@@ -0,0 +1,56 @@
1
+ # Copyright (c) 2026 Super Durable
2
+ # SPDX-License-Identifier: MIT
3
+ """Typed Gmail operation set bound to one logical Dex connection."""
4
+
5
+ from dataclasses import dataclass
6
+
7
+ from dex_connectors.sdk import ConnectionRef, Mutation, Query
8
+
9
+ from .models import GetMessageInput, Message, ReplyToMessageInput, SendMessageInput, SendMessageOutput
10
+ from .operations import GetMessageOperation, ReplyToMessageOperation, SendMessageOperation
11
+ from .provider import GmailProvider
12
+
13
+
14
+ @dataclass(frozen=True, slots=True)
15
+ class Connection:
16
+ """Logical connection, provider client, and three operations for Step factories."""
17
+
18
+ # Stable provider and name used by Dex Web Connections.
19
+ reference: ConnectionRef
20
+ # Full-message read operation.
21
+ get_message: Query[GetMessageInput, Message]
22
+ # New-message send operation.
23
+ send_message: Mutation[SendMessageInput, SendMessageOutput]
24
+ # Source-thread reply operation.
25
+ reply_to_message: Mutation[ReplyToMessageInput, SendMessageOutput]
26
+ # Provider client retained for closing project-owned HTTP resources; mocks omit it.
27
+ client: GmailProvider | None = None
28
+
29
+ def __post_init__(self) -> None:
30
+ """Require the Gmail provider and a static nonempty connection name."""
31
+ self.reference.validate()
32
+ if self.reference.provider != "google":
33
+ raise ValueError("Gmail connection provider must be google")
34
+ if self.get_message is None or self.send_message is None or self.reply_to_message is None:
35
+ raise ValueError("all Gmail operations are required")
36
+
37
+ async def close(self) -> None:
38
+ """Close the provider's owned HTTP client, if this connection has one."""
39
+ if self.client is not None:
40
+ await self.client.close()
41
+
42
+
43
+ def new_connection(client: GmailProvider, reference: ConnectionRef) -> Connection:
44
+ """Bind one provider client and explicit Dex ConnectionRef to all operations."""
45
+ if client is None or reference is None:
46
+ raise ValueError("Gmail client and connection reference are required")
47
+ return Connection(
48
+ reference,
49
+ GetMessageOperation(client),
50
+ SendMessageOperation(client),
51
+ ReplyToMessageOperation(client),
52
+ client,
53
+ )
54
+
55
+
56
+ __all__ = ["Connection", "new_connection"]
@@ -0,0 +1,71 @@
1
+ # Copyright (c) 2026 Super Durable
2
+ # SPDX-License-Identifier: MIT
3
+ """Stable operation identities and branch contracts from connector.yaml."""
4
+
5
+ from datetime import timedelta
6
+
7
+ from dex_connectors.sdk import (
8
+ BranchDefinition,
9
+ MutationDefinition,
10
+ OperationRef,
11
+ QueryDefinition,
12
+ RetryPolicy,
13
+ StepDefaults,
14
+ default_connector_step_execute_retry_policy,
15
+ )
16
+
17
+ CONNECTOR_ID = "gmail"
18
+ PROVIDER = "google"
19
+
20
+ GET_MESSAGE_DEFINITION = QueryDefinition(
21
+ OperationRef(CONNECTOR_ID, "getMessage"),
22
+ (
23
+ BranchDefinition("read", "The Gmail message was read."),
24
+ BranchDefinition("notFound", "The Gmail message does not exist.", True),
25
+ BranchDefinition("providerRejected", "Gmail conclusively rejected the message query.", True),
26
+ BranchDefinition("invalidResponse", "Gmail returned an invalid or oversized message response.", True),
27
+ BranchDefinition(
28
+ "defect", "Local input, connection configuration, or connector definition is invalid.", True
29
+ ),
30
+ ),
31
+ StepDefaults(timedelta(seconds=30), 2, execute_retry=default_connector_step_execute_retry_policy()),
32
+ )
33
+
34
+ _SEND_RETRY = RetryPolicy(timedelta(seconds=1), 2, timedelta(seconds=30), 5, timedelta(minutes=2))
35
+
36
+ SEND_MESSAGE_DEFINITION = MutationDefinition(
37
+ OperationRef(CONNECTOR_ID, "sendMessage"),
38
+ (
39
+ BranchDefinition(
40
+ "sent",
41
+ "Gmail accepted the message; its message and thread IDs can be empty when an unusable "
42
+ "accepted response has no Sent Mail match.",
43
+ ),
44
+ BranchDefinition("providerRejected", "Gmail conclusively rejected the message.", True),
45
+ BranchDefinition(
46
+ "defect", "Local input, connection configuration, or connector definition is invalid.", True
47
+ ),
48
+ ),
49
+ StepDefaults(timedelta(seconds=30), 2, execute_retry=_SEND_RETRY),
50
+ )
51
+
52
+ REPLY_TO_MESSAGE_DEFINITION = MutationDefinition(
53
+ OperationRef(CONNECTOR_ID, "replyToMessage"),
54
+ (
55
+ BranchDefinition(
56
+ "sent",
57
+ "Gmail accepted the reply; its message ID can be empty when an unusable accepted "
58
+ "response has no Sent Mail match, while the requested thread ID remains.",
59
+ ),
60
+ BranchDefinition("providerRejected", "Gmail conclusively rejected the reply.", True),
61
+ BranchDefinition(
62
+ "invalidResponse",
63
+ "Gmail returned an invalid or oversized source message response before sending the reply.",
64
+ True,
65
+ ),
66
+ BranchDefinition(
67
+ "defect", "Local input, connection configuration, or connector definition is invalid.", True
68
+ ),
69
+ ),
70
+ StepDefaults(timedelta(seconds=30), 2, execute_retry=_SEND_RETRY),
71
+ )
@@ -0,0 +1,110 @@
1
+ {
2
+ "connectorId": "gmail",
3
+ "releaseTag": "connectors/google/gmail/v0.24.1",
4
+ "package": {
5
+ "ecosystem": "pypi",
6
+ "name": "dex-connector-google-gmail",
7
+ "version": "0.1.0"
8
+ },
9
+ "factories": [
10
+ {
11
+ "name": "new_get_message_step",
12
+ "kind": "query",
13
+ "operationId": "getMessage",
14
+ "fields": {
15
+ "stepType": "step_type",
16
+ "annotations": "annotations",
17
+ "connectionName": "connection_name",
18
+ "resultAttribute": "result_attribute"
19
+ },
20
+ "branches": [
21
+ {
22
+ "id": "read",
23
+ "field": "read",
24
+ "optional": false
25
+ },
26
+ {
27
+ "id": "notFound",
28
+ "field": "not_found",
29
+ "optional": true
30
+ },
31
+ {
32
+ "id": "providerRejected",
33
+ "field": "provider_rejected",
34
+ "optional": true
35
+ },
36
+ {
37
+ "id": "invalidResponse",
38
+ "field": "invalid_response",
39
+ "optional": true
40
+ },
41
+ {
42
+ "id": "defect",
43
+ "field": "defect",
44
+ "optional": true
45
+ }
46
+ ]
47
+ },
48
+ {
49
+ "name": "new_send_message_step",
50
+ "kind": "mutation",
51
+ "operationId": "sendMessage",
52
+ "fields": {
53
+ "stepType": "step_type",
54
+ "annotations": "annotations",
55
+ "connectionName": "connection_name",
56
+ "resultAttribute": "result_attribute"
57
+ },
58
+ "branches": [
59
+ {
60
+ "id": "sent",
61
+ "field": "sent",
62
+ "optional": false
63
+ },
64
+ {
65
+ "id": "providerRejected",
66
+ "field": "provider_rejected",
67
+ "optional": true
68
+ },
69
+ {
70
+ "id": "defect",
71
+ "field": "defect",
72
+ "optional": true
73
+ }
74
+ ]
75
+ },
76
+ {
77
+ "name": "new_reply_to_message_step",
78
+ "kind": "mutation",
79
+ "operationId": "replyToMessage",
80
+ "fields": {
81
+ "stepType": "step_type",
82
+ "annotations": "annotations",
83
+ "connectionName": "connection_name",
84
+ "resultAttribute": "result_attribute"
85
+ },
86
+ "branches": [
87
+ {
88
+ "id": "sent",
89
+ "field": "sent",
90
+ "optional": false
91
+ },
92
+ {
93
+ "id": "providerRejected",
94
+ "field": "provider_rejected",
95
+ "optional": true
96
+ },
97
+ {
98
+ "id": "invalidResponse",
99
+ "field": "invalid_response",
100
+ "optional": true
101
+ },
102
+ {
103
+ "id": "defect",
104
+ "field": "defect",
105
+ "optional": true
106
+ }
107
+ ]
108
+ }
109
+ ]
110
+ }
@@ -0,0 +1,218 @@
1
+ # Copyright (c) 2026 Super Durable
2
+ # SPDX-License-Identifier: MIT
3
+ """Manifest-equivalent scripted Gmail outcomes for application tests."""
4
+
5
+ from datetime import UTC, datetime
6
+
7
+ from dex_connectors.sdk import ConnectionRef, Failure, FailureKind
8
+ from dex_connectors.sdk.connectormock import Case, Mutation, Query
9
+
10
+ from ..connection import Connection
11
+ from ..definitions import (
12
+ GET_MESSAGE_DEFINITION,
13
+ PROVIDER,
14
+ REPLY_TO_MESSAGE_DEFINITION,
15
+ SEND_MESSAGE_DEFINITION,
16
+ )
17
+ from ..models import GetMessageInput, Message, ReplyToMessageInput, SendMessageInput, SendMessageOutput
18
+
19
+
20
+ def _failure(operation: str, kind: FailureKind, message: str) -> Failure:
21
+ return Failure(kind, "gmail", operation, message)
22
+
23
+
24
+ class Mock:
25
+ """Three scripted Gmail operations with the manifest's happy-path defaults."""
26
+
27
+ def __init__(self, connection_name: str) -> None:
28
+ if not connection_name.strip():
29
+ raise ValueError("Gmail mock connection name is required")
30
+ self.reference = ConnectionRef(PROVIDER, connection_name)
31
+ self.get_message: Query[GetMessageInput, Message] = Query(GET_MESSAGE_DEFINITION)
32
+ self.send_message: Mutation[SendMessageInput, SendMessageOutput] = Mutation(SEND_MESSAGE_DEFINITION)
33
+ self.reply_to_message: Mutation[ReplyToMessageInput, SendMessageOutput] = Mutation(
34
+ REPLY_TO_MESSAGE_DEFINITION
35
+ )
36
+ self.get_message.default(get_message_customer_question())
37
+ self.send_message.default(send_message_sent_to_customer())
38
+ self.reply_to_message.default(reply_to_message_replied_in_thread())
39
+ self.connection = Connection(
40
+ self.reference, self.get_message, self.send_message, self.reply_to_message
41
+ )
42
+
43
+
44
+ def get_message_customer_question() -> Case[Message]:
45
+ """Return the manifest's plain-text and HTML customer question."""
46
+ return Case.branch_result(
47
+ "read",
48
+ Message(
49
+ message_id="18c0a1b2c3d4e5f6",
50
+ thread_id="18c0a1b2c3d4e5f0",
51
+ rfc_message_id="<question-1@mail.example.com>",
52
+ in_reply_to="<welcome-1@mail.example.com>",
53
+ references="<welcome-1@mail.example.com>",
54
+ from_address="Ada Customer <ada@example.com>",
55
+ reply_to="ada.support@example.com",
56
+ to=["support@example.org"],
57
+ subject="Re: Order 1042 has not arrived",
58
+ text_body="Hello, my order 1042 has not arrived yet. Can you check?",
59
+ html_body="<p>Hello, my order 1042 has not arrived yet. Can you check?</p>",
60
+ snippet="Hello, my order 1042 has not arrived yet.",
61
+ received_at=datetime(2026, 3, 4, 9, 15, tzinfo=UTC),
62
+ label_ids=["INBOX", "UNREAD"],
63
+ ),
64
+ )
65
+
66
+
67
+ def get_message_deleted_message() -> Case[Message]:
68
+ """Select notFound for a deleted or missing Gmail message."""
69
+ return Case.branch_result(
70
+ "notFound",
71
+ Message(),
72
+ _failure("getMessage", FailureKind.NOT_FOUND, "The Gmail message does not exist."),
73
+ )
74
+
75
+
76
+ def get_message_revoked_grant() -> Case[Message]:
77
+ """Select providerRejected for a grant missing the required read scope."""
78
+ return Case.branch_result(
79
+ "providerRejected",
80
+ Message(),
81
+ _failure(
82
+ "getMessage",
83
+ FailureKind.AUTHORIZATION,
84
+ "Gmail rejected the message query for the granted scopes.",
85
+ ),
86
+ )
87
+
88
+
89
+ def get_message_malformed_payload() -> Case[Message]:
90
+ """Select invalidResponse for a malformed Gmail payload."""
91
+ return Case.branch_result(
92
+ "invalidResponse",
93
+ Message(),
94
+ _failure("getMessage", FailureKind.PROTOCOL, "Gmail returned an invalid message payload."),
95
+ )
96
+
97
+
98
+ def get_message_empty_message_id() -> Case[Message]:
99
+ """Select defect before a provider request for an empty message ID."""
100
+ return Case.branch_result(
101
+ "defect", Message(), _failure("getMessage", FailureKind.VALIDATION, "The message ID is required.")
102
+ )
103
+
104
+
105
+ def get_message_rate_limited() -> Case[Message]:
106
+ """Retry once after Gmail throttles the read."""
107
+ return Case.retry(_failure("getMessage", FailureKind.RATE_LIMIT, "Gmail rate limit was reached."), 1)
108
+
109
+
110
+ def send_message_sent_to_customer() -> Case[SendMessageOutput]:
111
+ """Return the manifest's accepted new message identity."""
112
+ return Case.branch_result(
113
+ "sent",
114
+ SendMessageOutput(
115
+ sender="support@example.org",
116
+ recipients=["ada@example.com"],
117
+ message_id="18c0a1b2c3d4e600",
118
+ thread_id="18c0a1b2c3d4e600",
119
+ ),
120
+ )
121
+
122
+
123
+ def send_message_invalid_recipient() -> Case[SendMessageOutput]:
124
+ """Select providerRejected for Gmail's invalid-recipient response."""
125
+ return Case.branch_result(
126
+ "providerRejected",
127
+ SendMessageOutput(),
128
+ _failure("sendMessage", FailureKind.PROVIDER_REJECTION, "Gmail rejected the message recipients."),
129
+ )
130
+
131
+
132
+ def send_message_connection_lost() -> Case[SendMessageOutput]:
133
+ """Retry an ambiguous send after Sent Mail did not confirm it."""
134
+ return Case.retry(
135
+ _failure("sendMessage", FailureKind.TRANSPORT, "The connection closed before Gmail answered.")
136
+ )
137
+
138
+
139
+ def send_message_no_recipients() -> Case[SendMessageOutput]:
140
+ """Select defect for a message with no recipients."""
141
+ return Case.branch_result(
142
+ "defect",
143
+ SendMessageOutput(),
144
+ _failure("sendMessage", FailureKind.VALIDATION, "At least one recipient is required."),
145
+ )
146
+
147
+
148
+ def send_message_unavailable() -> Case[SendMessageOutput]:
149
+ """Retry a temporarily unavailable Gmail send."""
150
+ return Case.retry(_failure("sendMessage", FailureKind.AVAILABILITY, "Gmail is temporarily unavailable."))
151
+
152
+
153
+ def reply_to_message_replied_in_thread() -> Case[SendMessageOutput]:
154
+ """Return the manifest's accepted reply identity."""
155
+ return Case.branch_result(
156
+ "sent",
157
+ SendMessageOutput(
158
+ sender="support@example.org",
159
+ recipients=["ada.support@example.com"],
160
+ message_id="18c0a1b2c3d4e700",
161
+ thread_id="18c0a1b2c3d4e5f0",
162
+ ),
163
+ )
164
+
165
+
166
+ def reply_to_message_source_missing() -> Case[SendMessageOutput]:
167
+ """Select providerRejected when the source Gmail message disappeared."""
168
+ return Case.branch_result(
169
+ "providerRejected",
170
+ SendMessageOutput(),
171
+ _failure("replyToMessage", FailureKind.NOT_FOUND, "The source Gmail message does not exist."),
172
+ )
173
+
174
+
175
+ def reply_to_message_malformed_source() -> Case[SendMessageOutput]:
176
+ """Select invalidResponse before sending from malformed source metadata."""
177
+ return Case.branch_result(
178
+ "invalidResponse",
179
+ SendMessageOutput(),
180
+ _failure("replyToMessage", FailureKind.PROTOCOL, "Gmail returned an invalid source message."),
181
+ )
182
+
183
+
184
+ def reply_to_message_connection_lost() -> Case[SendMessageOutput]:
185
+ """Retry an ambiguous reply after Sent Mail did not confirm it."""
186
+ return Case.retry(
187
+ _failure("replyToMessage", FailureKind.TRANSPORT, "The connection closed before Gmail answered.")
188
+ )
189
+
190
+
191
+ def reply_to_message_empty_body() -> Case[SendMessageOutput]:
192
+ """Select defect for a reply without a body."""
193
+ return Case.branch_result(
194
+ "defect",
195
+ SendMessageOutput(),
196
+ _failure("replyToMessage", FailureKind.VALIDATION, "The reply body is required."),
197
+ )
198
+
199
+
200
+ __all__ = [
201
+ "Mock",
202
+ "get_message_customer_question",
203
+ "get_message_deleted_message",
204
+ "get_message_revoked_grant",
205
+ "get_message_malformed_payload",
206
+ "get_message_empty_message_id",
207
+ "get_message_rate_limited",
208
+ "send_message_sent_to_customer",
209
+ "send_message_invalid_recipient",
210
+ "send_message_connection_lost",
211
+ "send_message_no_recipients",
212
+ "send_message_unavailable",
213
+ "reply_to_message_replied_in_thread",
214
+ "reply_to_message_source_missing",
215
+ "reply_to_message_malformed_source",
216
+ "reply_to_message_connection_lost",
217
+ "reply_to_message_empty_body",
218
+ ]