> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mirage.strukto.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Outlook in Python

> Virtualize an Outlook mailbox from Python.

`OutlookVFS` mounts an Outlook mailbox read only through Microsoft Graph:
each mail folder becomes a folder of days, each message Graph's own message
JSON and its attachments a folder beside it. Set up a token as in
[Outlook setup](https://docs.mirage.strukto.ai/home/setup/outlook.md).

## Install

```bash theme={null}
pip install mirage-ai
```

## Configure

```python theme={null}
import os

from mirage import MountMode, Workspace
from mirage.vfs.outlook import OutlookConfig, OutlookVFS

config = OutlookConfig(access_token=os.environ["MS_GRAPH_MAIL_TOKEN"])
ws = Workspace({"/outlook": OutlookVFS(config)}, mode=MountMode.READ)

result = await ws.shell("ls /outlook && ls /outlook/Inbox | head -n 3")
print(await result.stdout_str())
await ws.close()
```

With no `user_id`, the mount is the signed-in user's mailbox (`/me`).

### Fields

**access\_token** `str | callable` *required*

Microsoft Graph bearer token, or a callable that returns one; it is called for each request and again after a `401`.

**graph\_base\_url** `str`

Full Graph service root, version segment included, for any deployment but the worldwide one: a sovereign cloud, a private endpoint or a test server. Unset uses `https://graph.microsoft.com/v1.0`.

**timeout** `float` (default: 30)

Seconds a Graph request may wait to connect, or between two reads of its answer, before it fails; also how long a server-side copy is polled before it fails as unconfirmed.

**max\_retries** `int` (default: 5)

Times a request is retried after a `429`, `503` or `504` response. Each retry waits what `Retry-After` asks or an exponential backoff, at most 30 seconds.

**user\_id** `str`

User ID or UPN whose mailbox the mount reads, under app-only auth; unset reads the signed-in user's.

**max\_messages** `int` (default: 1000)

How many of a folder's newest messages the mount lists and `grep` searches; a day directory or a glob over days lists at most this many of its own.

Fields marked secret are redacted in snapshots.

## Authentication

`access_token` is a Microsoft Graph bearer token, or a callable that returns
one. A callable is called for each request and again after a `401`, so a
long-running mount outlives one token; a plain string lasts about an hour.

A delegated token reads the signed-in user's mailbox. An app-only token
cannot use `/me`, so it sets `user_id` to the user's id or UPN. Either needs
`Mail.Read`, or `Mail.Read.Shared` for another user's mailbox under a
delegated token.

## Layout

```text theme={null}
/outlook/
  Inbox/
    Projects/
      Q3 Close/
        2026-11-03/
          Close_checklist__AAkALgAAAAAAHYQDEapmEc2byACqAC-EWg0A.outlook.json
    2026-11-16/
      Q3_close_numbers__AAkALgAAAAAAHYQDEapmEc2byACqAC-EWg0B.outlook.json
      Q3_close_numbers__AAkALgAAAAAAHYQDEapmEc2byACqAC-EWg0B/
        close.xlsx
  Sent Items/
  Archive/
```

* A mail folder is named by its display name, with `/` shown as `∕`. Child
  folders nest inside their parent, beside its day folders, to any depth; a
  child folder whose name reads as a date carries `__<folder-id>`, so a date
  always names a day.
* Inside a folder, one folder per day: the UTC date each message was
  received.
* A message file is named `<subject>__<message-id>.outlook.json`, the subject
  sanitized and cut short when needed. `ls` the day rather than build the
  name. The id is the message's immutable Graph id, which stays the same
  when the message moves folders.
* A message with file attachments has a folder of the same name without
  `.outlook.json`, holding them by their Outlook names. A name two
  attachments share takes the later one's position, as `scan__2.txt`.

## Behavior

* **Read only:** no command changes the mailbox.
* **Graph's JSON:** a `.outlook.json` is the message as Microsoft Graph
  answers it, cut to the fields a message keeps once delivered: `id`,
  `subject`, `from`, `toRecipients`, `ccRecipients`, `bccRecipients`,
  `replyTo`, `receivedDateTime`, `sentDateTime`, `importance`, `isDraft`,
  `hasAttachments`, `conversationId`, `internetMessageId`, `bodyPreview` and
  `body`. The body is plain text. Read state, flags and categories change
  after delivery and are left out.
* **Recent window:** `ls` of a folder lists its child folders and the days of
  its `max_messages` most recent messages, 1000 unless set. A glob over the day
  names (`ls /outlook/Inbox/2026-03-*`) or a day folder named directly
  reaches older days, each listing at most `max_messages` of its own.
* **Stable names:** the id in a name is Graph's immutable id, so a message
  keeps its name when it moves to another folder.
* **Dates:** a message, its attachment folder and its attachments are dated
  when the message was received (`receivedDateTime`).
* **Attachments:** a message's file attachments are listed with no size,
  since Graph's attachment size counts more than the content; `cat` reads the
  bytes. Attached Outlook items and links are not listed.
* **Service root:** mounts address `https://graph.microsoft.com/v1.0` unless
  `graph_base_url` names another root, given in full with its version
  segment.

## Integration

Outlook answers these commands from what its listing already fetched, so
fewer messages are read. See [Integration](https://docs.mirage.strukto.ai/home/integration/overview.md).

* `grep -r` and `rg`: listing a folder fetches its messages in full, and the
  listing keeps each message's text. Only the messages whose text holds the
  pattern's text, in any case, are read, and the output is what reading every
  message prints. Outlook's own search is not used, since it matches whole
  words and stops at 1,000 messages. Attachments are always read, and so is
  every message for a text that is not ASCII. With `walk_limit: -1` in the
  mount's `"@all"` [command limit](https://docs.mirage.strukto.ai/home/limits.md#command-output), the listing
  keeps no text and every message is read.

## VFS.md

The [VFS.md](https://docs.mirage.strukto.ai/home/setup/vfs-md.md) an agent reads with Outlook mounted at
`/<path>`.

> [tab] Rendered
>
> **Virtual Filesystem**
>
> | Path | Description |
> | - | - |
> | `/<path>` | `outlook`, read |
>
> **VFS Layout**
>
> **`/<path>`**
>
> ```text theme={null}
> /<path>
>   <folder>/                                  # Inbox, Sent Items, ...
>     <child folder>/                          # nested to any depth
>     <yyyy-mm-dd>/
>       <subject>__<message-id>.outlook.json   # the email, body included
>       <subject>__<message-id>/               # its attachments, if any
>         <attachment-name>
> ```
>
> * `<folder>` is an Outlook mail folder by its display name; a child
>   folder sits inside its parent beside the day directories, and one
>   named like a date carries `__<folder-id>`.
> * `<yyyy-mm-dd>` is the UTC day the message was received. A folder
>   lists its most recent messages; listing a day, or globbing one such
>   as `2026-03-*`, queries only those days.
> * `ls` a day directory for the names rather than building `<subject>`.
> * A `.outlook.json` is Microsoft Graph's own message JSON: `.subject`,
>   `.from.emailAddress`, `.toRecipients[]`, `.ccRecipients[]`,
>   `.receivedDateTime`, `.body.content` (plain text), `.hasAttachments`,
>   `.conversationId`. Read state, flags and categories are not in it.
> * The sibling directory holds attachments only (`cat` one for its bytes)
>   and is absent when there are none.
> * The mount is read-only.
>
> **Supported Unix Commands for VFS**
>
> Unix commands work on each path as on a local filesystem, as far as the path supports them:
>
> | Path | Supported |
> | - | - |
> | `/<path>` | Commands that read files (`ls`, `cat`, `grep`, `find`, `jq` and the rest). `grep -r` and `rg` ask `outlook` which files may match. |
>
> **Limitations of Unix Commands for VFS**
>
> Where a path differs from a local filesystem:
>
> | Path | Limitations |
> | - | - |
> | `/<path>` | Read only: no command changes files. `outlook` answers only for `*/*/*.outlook.json`, `*/*/*/*.outlook.json` and `*/*/*/*/*.outlook.json`; `grep -r` and `rg` read every other file. `grep -r`, `find` and `du` stop after 1000 files; a glob matching more, `tar -c`, `cp -r` and `rm -r` are refused. |
>
> Run `man <cmd>` or `<cmd> --help` for one command's usage.

> [tab] Raw
>
> ````markdown theme={null}
> ---
> name: workspace-filesystem
> description: The virtual filesystem layout of this workspace.
> ---
>
> # Virtual Filesystem
>
> | Path | Description |
> | --- | --- |
> | `/<path>` | `outlook`, read |
>
> ## VFS Layout
>
> ### `/<path>`
>
> ```text
> /<path>
>   <folder>/                                  # Inbox, Sent Items, ...
>     <child folder>/                          # nested to any depth
>     <yyyy-mm-dd>/
>       <subject>__<message-id>.outlook.json   # the email, body included
>       <subject>__<message-id>/               # its attachments, if any
>         <attachment-name>
> ```
>
> - `<folder>` is an Outlook mail folder by its display name; a child
>   folder sits inside its parent beside the day directories, and one
>   named like a date carries `__<folder-id>`.
> - `<yyyy-mm-dd>` is the UTC day the message was received. A folder
>   lists its most recent messages; listing a day, or globbing one such
>   as `2026-03-*`, queries only those days.
> - `ls` a day directory for the names rather than building `<subject>`.
> - A `.outlook.json` is Microsoft Graph's own message JSON: `.subject`,
>   `.from.emailAddress`, `.toRecipients[]`, `.ccRecipients[]`,
>   `.receivedDateTime`, `.body.content` (plain text), `.hasAttachments`,
>   `.conversationId`. Read state, flags and categories are not in it.
> - The sibling directory holds attachments only (`cat` one for its bytes)
>   and is absent when there are none.
> - The mount is read-only.
>
> ## Supported Unix Commands for VFS
>
> Unix commands work on each path as on a local filesystem, as far as the path supports them:
>
> | Path | Supported |
> | --- | --- |
> | `/<path>` | Commands that read files (`ls`, `cat`, `grep`, `find`, `jq` and the rest). `grep -r` and `rg` ask `outlook` which files may match. |
>
> ## Limitations of Unix Commands for VFS
>
> Where a path differs from a local filesystem:
>
> | Path | Limitations |
> | --- | --- |
> | `/<path>` | Read only: no command changes files. `outlook` answers only for `*/*/*.outlook.json`, `*/*/*/*.outlook.json` and `*/*/*/*/*.outlook.json`; `grep -r` and `rg` read every other file. `grep -r`, `find` and `du` stop after 1000 files; a glob matching more, `tar -c`, `cp -r` and `rm -r` are refused. |
>
> Run `man <cmd>` or `<cmd> --help` for one command's usage.
> ````


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.