@bitefoundry/outlook 0.2.0 → 0.3.1

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.
package/docs/API.md CHANGED
@@ -1,365 +1,394 @@
1
- # `outlook` HTTP JSON API
2
-
3
- Local HTTP/JSON server for AI agents, scripts, and integrations. Exposed by `outlook serve` (alias `api`), backed by Microsoft Graph v1.0, local SQLite WAL/FTS5 caching, and the background sync engine (`sync::spawn_sync_engine`).
4
-
5
- ## Starting the server
6
-
7
- ```bash
8
- outlook serve # http://127.0.0.1:3939
9
- outlook serve --port 9000 # custom port
10
- outlook serve --bind 127.0.0.1 --port 3939
11
- outlook serve --api-key secret123 # require Bearer secret123 or x-api-key: secret123
12
- outlook serve --token secret123 # --token is an alias for --api-key
13
- outlook api # alias for `serve`
14
- ```
15
-
16
- - `--bind` defaults to `127.0.0.1` (loopback only). Binding to a non-loopback address (e.g. `0.0.0.0`) requires `--api-key <KEY>` (or `--token <KEY>`) unless `OUTLOOK_ALLOW_INSECURE_SERVE=1` is explicitly set.
17
- - `--port` defaults to `3939`.
18
- - `--api-key` (alias `--token`) is optional; when set, every endpoint except `GET /health` requires either `Authorization: Bearer <key>` or `x-api-key: <key>`.
19
- - Requires an existing login (`outlook login`), `OUTLOOK_ACCESS_TOKEN`, `OUTLOOK_TOKEN_FILE`, or a shared M365 session (`teams-cli` / `TEAMS_TOKEN_FILE` when `OUTLOOK_SHARE_M365_AUTH=true`).
20
- - On startup, `outlook serve` spawns the background sync engine so the local SQLite cache stays warm while serving requests.
21
-
22
- ## Conventions
23
-
24
- - All responses are JSON (`Content-Type: application/json`).
25
- - Errors use `{"error": "<message>"}` with HTTP `400`, `401`, `403`, `404`, or `500`.
26
- - `limit` is clamped to `1..=1000`.
27
- - Mail folder parameters accept a folder ID, display name/prefix, or well-known alias (`inbox`, `sent`, `drafts`, `archive`, `trash`, `junk`).
28
- - To Do list parameters default to `"tasks"` and accept a list ID, display name, or `"default"` / `"tasks"` / `"defaultList"`.
29
- - CORS is restricted to loopback (`localhost` / `127.0.0.1` / `[::1]`) origins when `--api-key` is unset, and permissive when `--api-key` is configured.
30
-
31
- ## Endpoints
32
-
33
- ### System & Auth
34
-
35
- #### `GET /health`
36
-
37
- Always public, even when `--api-key` is configured.
38
-
39
- ```bash
40
- curl http://127.0.0.1:3939/health
41
- ```
42
-
43
- ```json
44
- {
45
- "ok": true,
46
- "user_id": "00000000-0000-0000-0000-000000000000",
47
- "version": "0.1.5"
48
- }
49
- ```
50
-
51
- #### `GET /openapi.json`
52
-
53
- Returns the OpenAPI 3.1.0 specification JSON generated by the running server.
54
-
55
- ```bash
56
- curl http://127.0.0.1:3939/openapi.json
57
- ```
58
-
59
- #### `GET /v1/whoami`
60
-
61
- Returns the active user profile, auth mode/source (`outlook-cli` vs shared `teams-cli` session), token expiry, and JWT `scp` / `roles` diagnostics.
62
-
63
- ```bash
64
- curl http://127.0.0.1:3939/v1/whoami -H "Authorization: Bearer secret123"
65
- ```
66
-
67
- ```json
68
- {
69
- "authenticated": true,
70
- "user_id": "00000000-0000-0000-0000-000000000000",
71
- "display_name": "Alice Kim",
72
- "email": "alice@contoso.com",
73
- "client_id": "14d82eec-204b-4c2f-b7e8-296a70dab67e",
74
- "tenant_id": "common",
75
- "auth_mode": "pkce",
76
- "auth_source": "keyring",
77
- "expires_at": 1795023600,
78
- "expired": false,
79
- "scopes": ["Mail.ReadWrite", "Mail.Send", "Calendars.ReadWrite", "Tasks.ReadWrite", "Contacts.Read"],
80
- "roles": []
81
- }
82
- ```
83
-
84
- ### Mail
85
-
86
- #### `GET /v1/mail/folders?refresh=false&offline=false`
87
-
88
- Lists Outlook mail folders with unread and total item counts.
89
-
90
- ```bash
91
- curl "http://127.0.0.1:3939/v1/mail/folders?refresh=true"
92
- ```
93
-
94
- ```json
95
- {
96
- "folders": [
97
- {
98
- "id": "AAMkAGI2...",
99
- "display_name": "Inbox",
100
- "well_known_name": "inbox",
101
- "parent_folder_id": null,
102
- "child_folder_count": 0,
103
- "unread_item_count": 4,
104
- "total_item_count": 128
105
- }
106
- ]
107
- }
108
- ```
109
-
110
- #### `GET /v1/mail/messages?folder=inbox&limit=30&unread=false&flagged=false&focused=false&refresh=false&offline=false`
111
-
112
- Lists messages in a mail folder (`inbox`, `sent`, `drafts`, `archive`, `trash`, `junk`, folder name, or folder ID).
113
-
114
- ```bash
115
- curl "http://127.0.0.1:3939/v1/mail/messages?folder=inbox&limit=20&unread=true"
116
- ```
117
-
118
- ```json
119
- {
120
- "folder": { "id": "AAMkAGI2...", "display_name": "Inbox", "well_known_name": "inbox" },
121
- "messages": [
122
- {
123
- "id": "AAMkAGI2...",
124
- "conversation_id": "AAQkAGI2...",
125
- "folder_id": "AAMkAGI2...",
126
- "subject": "Quarterly Review",
127
- "from": { "name": "Bob Smith", "address": "bob@contoso.com" },
128
- "received_at": "2026-11-18T09:30:00Z",
129
- "is_read": false,
130
- "flagged": false,
131
- "importance": "normal",
132
- "inference_classification": "focused",
133
- "has_attachments": true,
134
- "body_loaded": false,
135
- "preview": "Attached are the Q4 numbers..."
136
- }
137
- ]
138
- }
139
- ```
140
-
141
- #### `GET /v1/mail/messages/{id}?offline=false`
142
-
143
- Fetches full headers, HTML/plain body, and attachment metadata for a single message (and caches it in SQLite).
144
-
145
- ```bash
146
- curl "http://127.0.0.1:3939/v1/mail/messages/AAMkAGI2..."
147
- ```
148
-
149
- #### `POST /v1/mail/send`
150
-
151
- Composes and sends a new email (Markdown compiled to HTML) with optional `cc`, `bcc`, `importance` (`low` | `normal` | `high`), host file `attachments`, and `save_to_sent_items` (default `true`). `markdown` also accepts alias `body`.
152
-
153
- ```bash
154
- curl -X POST http://127.0.0.1:3939/v1/mail/send \
155
- -H "Content-Type: application/json" \
156
- -d '{"to":["bob@contoso.com"],"subject":"Release v0.1.0","markdown":"Build **passed**!","importance":"high"}'
157
- ```
158
-
159
- ```json
160
- {
161
- "ok": true,
162
- "to": ["bob@contoso.com"],
163
- "subject": "Release v0.1.0"
164
- }
165
- ```
166
-
167
- #### `POST /v1/mail/messages/{id}/reply`
168
-
169
- Replies (`reply_all: false`) or replies-all (`reply_all: true`) to an email message. `markdown` also accepts alias `body`.
170
-
171
- ```bash
172
- curl -X POST http://127.0.0.1:3939/v1/mail/messages/AAMkAGI2.../reply \
173
- -H "Content-Type: application/json" \
174
- -d '{"markdown":"Looks good, approved.","reply_all":true}'
175
- ```
176
-
177
- #### `POST /v1/mail/messages/{id}/forward`
178
-
179
- Forwards an email message to one or more recipients (`to`) with an optional Markdown `markdown` (alias `comment`) preface.
180
-
181
- ```bash
182
- curl -X POST http://127.0.0.1:3939/v1/mail/messages/AAMkAGI2.../forward \
183
- -H "Content-Type: application/json" \
184
- -d '{"to":["carol@contoso.com"],"markdown":"FYI — see thread below."}'
185
- ```
186
-
187
- #### `PATCH /v1/mail/messages/{id}`
188
-
189
- Updates read status (`is_read`), flag status (`flagged`), and/or moves the message to `destination_folder_id` (alias `destination_folder`, accepting folder name, alias such as `"archive"`, or folder ID). At least one field must be provided.
190
-
191
- To edit an existing draft's subject or body, use `outlook edit-draft` or MCP `update_draft`. To edit an active composition, use the TUI.
192
-
193
- ```bash
194
- curl -X PATCH http://127.0.0.1:3939/v1/mail/messages/AAMkAGI2... \
195
- -H "Content-Type: application/json" \
196
- -d '{"is_read":true,"flagged":false,"destination_folder_id":"archive"}'
197
- ```
198
-
199
- ```json
200
- {
201
- "ok": true,
202
- "message_id": "AAMkAGI2...",
203
- "is_read": true,
204
- "flagged": false,
205
- "moved": { "id": "AAMkAGI2..." }
206
- }
207
- ```
208
-
209
- #### `DELETE /v1/mail/messages/{id}`
210
-
211
- Deletes a mail message and removes it from the local SQLite cache.
212
-
213
- ```bash
214
- curl -X DELETE http://127.0.0.1:3939/v1/mail/messages/AAMkAGI2...
215
- ```
216
-
217
- #### `POST /v1/mail/messages/{id}/attachments/{att_id}/download`
218
-
219
- Downloads an attachment to disk on the host running `outlook serve` (defaults to `download_dir`, usually `Downloads/outlook`). Optional body: `{"out_dir": "/path/to/dir"}` (alias `dir`).
220
-
221
- ```bash
222
- curl -X POST http://127.0.0.1:3939/v1/mail/messages/AAMkAGI2.../attachments/ATT_ID/download \
223
- -H "Content-Type: application/json" \
224
- -d '{"out_dir":"./downloads"}'
225
- ```
226
-
227
- ```json
228
- {
229
- "ok": true,
230
- "path": "./downloads/report.pdf",
231
- "file_name": "report.pdf",
232
- "bytes_written": 48120
233
- }
234
- ```
235
-
236
- #### `GET /v1/mail/search?q=...&folder=&remote=false&limit=30`
237
-
238
- Searches local SQLite FTS5 + `LIKE` (`hits`) and, when `remote=true`, queries Microsoft Graph KQL `$search` (`remote`) while caching returned messages.
239
-
240
- ```bash
241
- curl "http://127.0.0.1:3939/v1/mail/search?q=quarterly&remote=true&limit=20"
242
- ```
243
-
244
- ### Calendar
245
-
246
- #### `GET /v1/calendar/events?from=&to=&days=7&limit=50&offline=false`
247
-
248
- Lists calendar events within a time window (`from` / `to` accept aliases `start` / `end` as ISO-8601 or `YYYY-MM-DD`; defaults to now through `+7` days).
249
-
250
- ```bash
251
- curl "http://127.0.0.1:3939/v1/calendar/events?days=14"
252
- ```
253
-
254
- ```json
255
- {
256
- "start": "2026-11-18T00:00:00Z",
257
- "end": "2026-12-02T00:00:00Z",
258
- "events": [
259
- {
260
- "id": "AAMkAGI2...",
261
- "subject": "Architecture Review",
262
- "start_iso": "2026-11-20T09:00:00Z",
263
- "end_iso": "2026-11-20T10:00:00Z",
264
- "time_zone": "UTC",
265
- "is_all_day": false,
266
- "location": "Room 4B",
267
- "response_status": "accepted",
268
- "is_online_meeting": true,
269
- "online_meeting_url": "https://teams.microsoft.com/l/meetup-join/..."
270
- }
271
- ]
272
- }
273
- ```
274
-
275
- #### `POST /v1/calendar/events`
276
-
277
- Creates a new calendar event. `start_iso` / `end_iso` accept aliases `start` / `end`; `markdown` accepts alias `body`; `is_online_meeting` accepts alias `online`.
278
-
279
- ```bash
280
- curl -X POST http://127.0.0.1:3939/v1/calendar/events \
281
- -H "Content-Type: application/json" \
282
- -d '{"subject":"Sprint Planning","start_iso":"2026-11-20T14:00:00Z","end_iso":"2026-11-20T15:00:00Z","attendees":["bob@contoso.com"],"is_online_meeting":true}'
283
- ```
284
-
285
- #### `GET /v1/calendar/events/{id}?offline=false`
286
-
287
- Reads full details and attendees for a calendar event.
288
-
289
- ```bash
290
- curl "http://127.0.0.1:3939/v1/calendar/events/AAMkAGI2..."
291
- ```
292
-
293
- #### `POST /v1/calendar/events/{id}/rsvp`
294
-
295
- Responds to a meeting invitation (`response`: `"accept"` | `"tentative"` | `"decline"`, optional `comment`).
296
-
297
- ```bash
298
- curl -X POST http://127.0.0.1:3939/v1/calendar/events/AAMkAGI2.../rsvp \
299
- -H "Content-Type: application/json" \
300
- -d '{"response":"accept","comment":"See you there."}'
301
- ```
302
-
303
- #### `DELETE /v1/calendar/events/{id}`
304
-
305
- Cancels/deletes a calendar event and removes it from the local cache.
306
-
307
- ```bash
308
- curl -X DELETE http://127.0.0.1:3939/v1/calendar/events/AAMkAGI2...
309
- ```
310
-
311
- ### Microsoft To Do
312
-
313
- #### `GET /v1/todo/lists?refresh=false&offline=false`
314
-
315
- Lists Microsoft To Do task lists.
316
-
317
- ```bash
318
- curl "http://127.0.0.1:3939/v1/todo/lists"
319
- ```
320
-
321
- #### `GET /v1/todo/tasks?list=tasks&all=false&limit=50&refresh=false&offline=false`
322
-
323
- Lists tasks in a To Do list (`all` accepts alias `include_completed`).
324
-
325
- ```bash
326
- curl "http://127.0.0.1:3939/v1/todo/tasks?list=tasks&all=true"
327
- ```
328
-
329
- #### `POST /v1/todo/tasks`
330
-
331
- Creates a To Do task (`body_plain` accepts alias `notes`; `due_date_iso` accepts alias `due`; `importance`: `low` | `normal` | `high`).
332
-
333
- ```bash
334
- curl -X POST http://127.0.0.1:3939/v1/todo/tasks \
335
- -H "Content-Type: application/json" \
336
- -d '{"title":"Publish outlook v0.1.0","due_date_iso":"2026-11-20","importance":"high"}'
337
- ```
338
-
339
- #### `PATCH /v1/todo/tasks/{id}`
340
-
341
- Marks a To Do task completed or incomplete (`{ "list"?: "tasks", "completed": true }`).
342
-
343
- ```bash
344
- curl -X PATCH http://127.0.0.1:3939/v1/todo/tasks/TASK_ID \
345
- -H "Content-Type: application/json" \
346
- -d '{"completed":true}'
347
- ```
348
-
349
- #### `DELETE /v1/todo/tasks/{id}?list=tasks`
350
-
351
- Deletes a To Do task.
352
-
353
- ```bash
354
- curl -X DELETE "http://127.0.0.1:3939/v1/todo/tasks/TASK_ID?list=tasks"
355
- ```
356
-
357
- ### Contacts & Directory
358
-
359
- #### `GET /v1/contacts?q=&limit=50&offline=false`
360
-
361
- Lists personal Outlook contacts (`/me/contacts`) or, when `q` (alias `query`) is provided, searches both personal contacts and the Entra ID organization directory (`/users`).
362
-
363
- ```bash
364
- curl "http://127.0.0.1:3939/v1/contacts?q=alice&limit=20"
365
- ```
1
+ # `outlook` HTTP JSON API
2
+
3
+ Local HTTP/JSON server for AI agents, scripts, and integrations. Exposed by `outlook serve` (alias `api`), backed by Microsoft Graph v1.0, local SQLite WAL/FTS5 caching, and the background sync engine (`sync::spawn_sync_engine`).
4
+
5
+ ## Starting the server
6
+
7
+ ```bash
8
+ outlook serve # http://127.0.0.1:3939, prints a generated Bearer token to stderr
9
+ outlook serve --port 9000 # custom port
10
+ outlook serve --bind 127.0.0.1 --port 3939
11
+ outlook serve --api-key secret123 # require Bearer secret123 or x-api-key: secret123
12
+ outlook serve --token secret123 # --token is an alias for --api-key
13
+ outlook serve --allow-keyless # loopback only, no authentication
14
+ outlook serve --cors-origin http://localhost:5173 # let one browser app call the API
15
+ outlook api # alias for `serve`
16
+ ```
17
+
18
+ - `--bind` defaults to `127.0.0.1` (loopback only). Binding to a non-loopback address (e.g. `0.0.0.0`) requires `--api-key <KEY>` (or `--token <KEY>`) unless `OUTLOOK_ALLOW_INSECURE_SERVE=1` is explicitly set.
19
+ - `--port` defaults to `3939`.
20
+ - `--api-key` (alias `--token`) sets the key. Every endpoint except `GET /health` requires either `Authorization: Bearer <key>` or `x-api-key: <key>`.
21
+ - Without `--api-key`, a loopback server generates a random 32-byte token (64 hex characters) for that run and prints it once to stderr. It is not written to disk, and a new one is generated on every start; pass `--api-key` when clients need a stable key.
22
+ - `--allow-keyless` turns authentication off for a loopback server instead of generating a token. It cannot be combined with `--api-key`.
23
+ - `--cors-origin <ORIGIN>` (repeatable) allows one browser origin, written as `scheme://host[:port]`. No origin is allowed by default.
24
+ - Requires an existing login (`outlook login`), `OUTLOOK_ACCESS_TOKEN`, `OUTLOOK_TOKEN_FILE`, or a shared M365 session (`teams-cli` / `TEAMS_TOKEN_FILE` when `OUTLOOK_SHARE_M365_AUTH=true`).
25
+ - On startup, `outlook serve` spawns the background sync engine so the local SQLite cache stays warm while serving requests.
26
+
27
+ ## Conventions
28
+
29
+ - All responses are JSON (`Content-Type: application/json`).
30
+ - Errors use `{"error": "<message>"}` with HTTP `400`, `401`, `403`, `404`, or `500`.
31
+ - `limit` is clamped to `1..=1000`.
32
+ - Mail folder parameters accept a folder ID, display name/prefix, or well-known alias (`inbox`, `sent`, `drafts`, `archive`, `trash`, `junk`).
33
+ - To Do list parameters default to `"tasks"` and accept a list ID, display name, or `"default"` / `"tasks"` / `"defaultList"`.
34
+ - The `curl` examples below leave out the key. Add `-H "Authorization: Bearer <key>"`, or start the server with `--allow-keyless`.
35
+
36
+ ## Security
37
+
38
+ The API can read and send mail as the signed-in user, so it refuses callers it cannot place:
39
+
40
+ - **Authentication** is on by default (see `--api-key` and the generated token above). `GET /health` stays public.
41
+ - **Browser origins**: a request with an `Origin` header is answered only when that origin was passed with `--cors-origin`, compared exactly. Every other origin gets `403`, preflight included, with or without a valid key. This applies to pages served from `localhost` too. Clients that send no `Origin` header (curl, scripts, agents) are unaffected.
42
+ - **`Host` header** (keyless servers only): the request must be addressed to `localhost`, a loopback address (`127.0.0.1`, `[::1]`), or a name listed in `OUTLOOK_SERVE_ALLOWED_HOSTS` (comma-separated). Any other host gets `403`, `/health` included. This stops a web page that points its own domain at `127.0.0.1` (DNS rebinding) from reaching the API. A server with a key skips this check, so a reverse proxy can forward its own host name.
43
+ - **Non-loopback binds** need `--api-key`. `OUTLOOK_ALLOW_INSECURE_SERVE=1` overrides that and serves without authentication; the bind address is then accepted as a `Host`, and `0.0.0.0` needs `OUTLOOK_SERVE_ALLOWED_HOSTS` for any non-loopback name.
44
+
45
+ ## Endpoints
46
+
47
+ ### System & Auth
48
+
49
+ #### `GET /health`
50
+
51
+ No key needed. The `Origin` and `Host` checks in [Security](#security) still apply.
52
+
53
+ ```bash
54
+ curl http://127.0.0.1:3939/health
55
+ ```
56
+
57
+ ```json
58
+ {
59
+ "ok": true,
60
+ "user_id": "00000000-0000-0000-0000-000000000000",
61
+ "version": "0.1.5"
62
+ }
63
+ ```
64
+
65
+ #### `GET /openapi.json`
66
+
67
+ Returns the OpenAPI 3.1.0 specification JSON generated by the running server.
68
+
69
+ ```bash
70
+ curl http://127.0.0.1:3939/openapi.json
71
+ ```
72
+
73
+ #### `GET /v1/whoami`
74
+
75
+ Returns the active user profile, auth mode/source (`outlook-cli` vs shared `teams-cli` session), token expiry, and JWT `scp` / `roles` diagnostics.
76
+
77
+ ```bash
78
+ curl http://127.0.0.1:3939/v1/whoami -H "Authorization: Bearer secret123"
79
+ ```
80
+
81
+ ```json
82
+ {
83
+ "authenticated": true,
84
+ "user_id": "00000000-0000-0000-0000-000000000000",
85
+ "display_name": "Alice Kim",
86
+ "email": "alice@contoso.com",
87
+ "client_id": "14d82eec-204b-4c2f-b7e8-296a70dab67e",
88
+ "tenant_id": "common",
89
+ "auth_mode": "pkce",
90
+ "auth_source": "keyring",
91
+ "expires_at": 1795023600,
92
+ "expired": false,
93
+ "scopes": ["User.Read", "User.ReadBasic.All", "Mail.ReadWrite", "Mail.Send", "Calendars.ReadWrite", "Contacts.Read", "Tasks.ReadWrite"],
94
+ "roles": []
95
+ }
96
+ ```
97
+
98
+ ### Mail
99
+
100
+ #### `GET /v1/mail/folders?refresh=false&offline=false`
101
+
102
+ Lists Outlook mail folders with unread and total item counts.
103
+
104
+ ```bash
105
+ curl "http://127.0.0.1:3939/v1/mail/folders?refresh=true"
106
+ ```
107
+
108
+ ```json
109
+ {
110
+ "folders": [
111
+ {
112
+ "id": "AAMkAGI2...",
113
+ "display_name": "Inbox",
114
+ "well_known_name": "inbox",
115
+ "parent_folder_id": null,
116
+ "child_folder_count": 0,
117
+ "unread_item_count": 4,
118
+ "total_item_count": 128
119
+ }
120
+ ]
121
+ }
122
+ ```
123
+
124
+ #### `GET /v1/mail/messages?folder=inbox&limit=30&unread=false&flagged=false&focused=false&refresh=false&offline=false`
125
+
126
+ Lists messages in a mail folder (`inbox`, `sent`, `drafts`, `archive`, `trash`, `junk`, folder name, or folder ID).
127
+
128
+ Live requests are bounded:
129
+
130
+ - With `unread`, `flagged` or `focused`, the scan reads at most 20 Graph pages. `has_more` is `true` or `false` when the scan could tell, and `null` when it stopped at the page cap (or the response came from the cache) and more matches may exist further back.
131
+ - Without a filter, the first sync of a folder reads at most 40 delta pages (about 2,000 messages) per request. A larger folder answers with the newest messages and `"sync_complete": false`; later requests and the background sync continue from where it stopped. The key is absent once the folder is fully synced.
132
+
133
+ ```bash
134
+ curl "http://127.0.0.1:3939/v1/mail/messages?folder=inbox&limit=20&unread=true"
135
+ ```
136
+
137
+ ```json
138
+ {
139
+ "folder": { "id": "AAMkAGI2...", "display_name": "Inbox", "well_known_name": "inbox" },
140
+ "messages": [
141
+ {
142
+ "id": "AAMkAGI2...",
143
+ "conversation_id": "AAQkAGI2...",
144
+ "folder_id": "AAMkAGI2...",
145
+ "subject": "Quarterly Review",
146
+ "from": { "name": "Bob Smith", "address": "bob@contoso.com" },
147
+ "received_at": "2026-11-18T09:30:00Z",
148
+ "is_read": false,
149
+ "flagged": false,
150
+ "importance": "normal",
151
+ "inference_classification": "focused",
152
+ "has_attachments": true,
153
+ "body_loaded": false,
154
+ "preview": "Attached are the Q4 numbers..."
155
+ }
156
+ ],
157
+ "has_more": false
158
+ }
159
+ ```
160
+
161
+ #### `GET /v1/mail/messages/{id}?offline=false`
162
+
163
+ Fetches full headers, HTML/plain body, and attachment metadata for a single message (and caches it in SQLite). Messages fetched with expanded attachments include `attachments[].content_bytes_b64`.
164
+
165
+ ```bash
166
+ curl "http://127.0.0.1:3939/v1/mail/messages/AAMkAGI2..."
167
+ ```
168
+
169
+ #### `POST /v1/mail/send`
170
+
171
+ Composes and sends a new email (Markdown compiled to HTML) with optional `cc`, `bcc`, `importance` (`low` | `normal` | `high`), host file `attachments`, and `save_to_sent_items` (default `true`). `markdown` also accepts alias `body`.
172
+
173
+ ```bash
174
+ curl -X POST http://127.0.0.1:3939/v1/mail/send \
175
+ -H "Content-Type: application/json" \
176
+ -d '{"to":["bob@contoso.com"],"subject":"Release v0.1.0","markdown":"Build **passed**!","importance":"high"}'
177
+ ```
178
+
179
+ ```json
180
+ {
181
+ "ok": true,
182
+ "to": ["bob@contoso.com"],
183
+ "subject": "Release v0.1.0"
184
+ }
185
+ ```
186
+
187
+ #### `POST /v1/mail/messages/{id}/reply`
188
+
189
+ Replies (`reply_all: false`) or replies-all (`reply_all: true`) to an email message. `markdown` also accepts alias `body`.
190
+
191
+ ```bash
192
+ curl -X POST http://127.0.0.1:3939/v1/mail/messages/AAMkAGI2.../reply \
193
+ -H "Content-Type: application/json" \
194
+ -d '{"markdown":"Looks good, approved.","reply_all":true}'
195
+ ```
196
+
197
+ #### `POST /v1/mail/messages/{id}/forward`
198
+
199
+ Forwards an email message to one or more recipients (`to`) with an optional Markdown `markdown` (alias `comment`) preface.
200
+
201
+ ```bash
202
+ curl -X POST http://127.0.0.1:3939/v1/mail/messages/AAMkAGI2.../forward \
203
+ -H "Content-Type: application/json" \
204
+ -d '{"to":["carol@contoso.com"],"markdown":"FYI — see thread below."}'
205
+ ```
206
+
207
+ #### `PATCH /v1/mail/messages/{id}`
208
+
209
+ Updates read status (`is_read`), flag status (`flagged`), and/or moves the message to `destination_folder_id` (alias `destination_folder`, accepting folder name, alias such as `"archive"`, or folder ID). At least one field must be provided.
210
+
211
+ To edit an existing draft's subject or body, use `outlook edit-draft` or MCP `update_draft`. To edit an active composition, use the TUI.
212
+
213
+ ```bash
214
+ curl -X PATCH http://127.0.0.1:3939/v1/mail/messages/AAMkAGI2... \
215
+ -H "Content-Type: application/json" \
216
+ -d '{"is_read":true,"flagged":false,"destination_folder_id":"archive"}'
217
+ ```
218
+
219
+ ```json
220
+ {
221
+ "ok": true,
222
+ "message_id": "AAMkAGI2...",
223
+ "is_read": true,
224
+ "flagged": false,
225
+ "moved": { "id": "AAMkAGI2...", "folder_id": "AAMkAGI2..." }
226
+ }
227
+ ```
228
+
229
+ #### `DELETE /v1/mail/messages/{id}`
230
+
231
+ Deletes a mail message and removes it from the local SQLite cache.
232
+
233
+ ```bash
234
+ curl -X DELETE http://127.0.0.1:3939/v1/mail/messages/AAMkAGI2...
235
+ ```
236
+
237
+ #### `POST /v1/mail/messages/{id}/attachments/{att_id}/download`
238
+
239
+ Downloads an attachment to disk on the host running `outlook serve` (defaults to `download_dir`, usually `Downloads/outlook`). Optional body: `{"out_dir": "/path/to/dir"}` (alias `dir`).
240
+
241
+ ```bash
242
+ curl -X POST http://127.0.0.1:3939/v1/mail/messages/AAMkAGI2.../attachments/ATT_ID/download \
243
+ -H "Content-Type: application/json" \
244
+ -d '{"out_dir":"./downloads"}'
245
+ ```
246
+
247
+ ```json
248
+ {
249
+ "ok": true,
250
+ "path": "./downloads/report.pdf",
251
+ "file_name": "report.pdf",
252
+ "bytes_written": 48120
253
+ }
254
+ ```
255
+
256
+ #### `GET /v1/mail/search?q=...&folder=&remote=false&limit=30`
257
+
258
+ Searches local SQLite FTS5 + `LIKE` (`hits`) and, when `remote=true`, queries Microsoft Graph KQL `$search` (`remote`) while caching returned messages.
259
+
260
+ ```bash
261
+ curl "http://127.0.0.1:3939/v1/mail/search?q=quarterly&remote=true&limit=20"
262
+ ```
263
+
264
+ ### Calendar
265
+
266
+ #### `GET /v1/calendar/events?from=&to=&days=7&limit=50&offline=false`
267
+
268
+ Lists calendar events within a time window (`from` / `to` accept aliases `start` / `end` as ISO-8601 or `YYYY-MM-DD`; defaults to now through `+7` days).
269
+
270
+ ```bash
271
+ curl "http://127.0.0.1:3939/v1/calendar/events?days=14"
272
+ ```
273
+
274
+ ```json
275
+ {
276
+ "start": "2026-11-18T00:00:00Z",
277
+ "end": "2026-12-02T00:00:00Z",
278
+ "events": [
279
+ {
280
+ "id": "AAMkAGI2...",
281
+ "subject": "Architecture Review",
282
+ "start_iso": "2026-11-20T09:00:00Z",
283
+ "end_iso": "2026-11-20T10:00:00Z",
284
+ "time_zone": "UTC",
285
+ "is_all_day": false,
286
+ "location": "Room 4B",
287
+ "response_status": "accepted",
288
+ "is_online_meeting": true,
289
+ "online_meeting_url": "https://teams.microsoft.com/l/meetup-join/..."
290
+ }
291
+ ]
292
+ }
293
+ ```
294
+
295
+ #### `POST /v1/calendar/events`
296
+
297
+ Creates a new calendar event. `start_iso` / `end_iso` accept aliases `start` / `end`; `markdown` accepts alias `body`; `is_online_meeting` accepts alias `online`.
298
+
299
+ | Input | `time_zone` | Result |
300
+ |---|---|---|
301
+ | RFC3339 (`2026-11-20T14:00:00Z`, `...+09:00`) | any | Exact instant, stored in UTC. |
302
+ | Wall clock (`2026-11-20 14:00`) | omitted | Read in the server machine's time zone. |
303
+ | Wall clock (`2026-11-20 14:00`) | `Asia/Seoul` | Read in that zone (IANA or Windows name). |
304
+ | `is_all_day: true` | optional | `start_iso` and `end_iso` must be `YYYY-MM-DD`; the end date is exclusive. |
305
+
306
+ Invalid all-day input (a time of day, or an end date that is not after the start date) returns `400` without calling Microsoft Graph.
307
+
308
+ ```bash
309
+ curl -X POST http://127.0.0.1:3939/v1/calendar/events \
310
+ -H "Content-Type: application/json" \
311
+ -d '{"subject":"Sprint Planning","start_iso":"2026-11-20T14:00:00Z","end_iso":"2026-11-20T15:00:00Z","attendees":["bob@contoso.com"],"is_online_meeting":true}'
312
+ ```
313
+
314
+ #### `GET /v1/calendar/events/{id}?offline=false`
315
+
316
+ Reads full details and attendees for a calendar event.
317
+
318
+ ```bash
319
+ curl "http://127.0.0.1:3939/v1/calendar/events/AAMkAGI2..."
320
+ ```
321
+
322
+ #### `POST /v1/calendar/events/{id}/rsvp`
323
+
324
+ Responds to a meeting invitation (`response`: `"accept"` | `"tentative"` | `"decline"`, optional `comment`).
325
+
326
+ ```bash
327
+ curl -X POST http://127.0.0.1:3939/v1/calendar/events/AAMkAGI2.../rsvp \
328
+ -H "Content-Type: application/json" \
329
+ -d '{"response":"accept","comment":"See you there."}'
330
+ ```
331
+
332
+ #### `DELETE /v1/calendar/events/{id}`
333
+
334
+ Cancels/deletes a calendar event and removes it from the local cache.
335
+
336
+ ```bash
337
+ curl -X DELETE http://127.0.0.1:3939/v1/calendar/events/AAMkAGI2...
338
+ ```
339
+
340
+ ### Microsoft To Do
341
+
342
+ #### `GET /v1/todo/lists?refresh=false&offline=false`
343
+
344
+ Lists Microsoft To Do task lists.
345
+
346
+ ```bash
347
+ curl "http://127.0.0.1:3939/v1/todo/lists"
348
+ ```
349
+
350
+ #### `GET /v1/todo/tasks?list=tasks&all=false&limit=50&refresh=false&offline=false`
351
+
352
+ Lists tasks in a To Do list (`all` accepts alias `include_completed`).
353
+
354
+ ```bash
355
+ curl "http://127.0.0.1:3939/v1/todo/tasks?list=tasks&all=true"
356
+ ```
357
+
358
+ #### `POST /v1/todo/tasks`
359
+
360
+ Creates a To Do task (`body_plain` accepts alias `notes`; `due_date_iso` accepts alias `due`; `importance`: `low` | `normal` | `high`).
361
+
362
+ ```bash
363
+ curl -X POST http://127.0.0.1:3939/v1/todo/tasks \
364
+ -H "Content-Type: application/json" \
365
+ -d '{"title":"Publish outlook v0.1.0","due_date_iso":"2026-11-20","importance":"high"}'
366
+ ```
367
+
368
+ #### `PATCH /v1/todo/tasks/{id}`
369
+
370
+ Marks a To Do task completed or incomplete (`{ "list"?: "tasks", "completed": true }`).
371
+
372
+ ```bash
373
+ curl -X PATCH http://127.0.0.1:3939/v1/todo/tasks/TASK_ID \
374
+ -H "Content-Type: application/json" \
375
+ -d '{"completed":true}'
376
+ ```
377
+
378
+ #### `DELETE /v1/todo/tasks/{id}?list=tasks`
379
+
380
+ Deletes a To Do task.
381
+
382
+ ```bash
383
+ curl -X DELETE "http://127.0.0.1:3939/v1/todo/tasks/TASK_ID?list=tasks"
384
+ ```
385
+
386
+ ### Contacts & Directory
387
+
388
+ #### `GET /v1/contacts?q=&limit=50&offline=false`
389
+
390
+ Lists personal Outlook contacts (`/me/contacts`) or, when `q` (alias `query`) is provided, searches both personal contacts and the Entra ID organization directory (`/users`).
391
+
392
+ ```bash
393
+ curl "http://127.0.0.1:3939/v1/contacts?q=alice&limit=20"
394
+ ```