s365b.modules.exchange.restore¶
Restoring mail, calendar events, contacts and tasks with Exchange’s import API.
Each item’s restore copy (Exchange’s own export, see the module) is imported into a folder of the target mailbox, so it comes back as it was: read state, dates, flags and attachments, and not as a draft. Imported meetings send no invitations.
Folders are found by name along the item’s backed-up path and created when
missing, either where they were (“original folders”) or under a new folder
named by the person restoring. Mail goes into mail folders, events into
calendars, contacts into contact folders and tasks into task folders (To Do
lists). Calendars and task lists other than the default ones are looked for
at the top of the mailbox and under the default calendar or task folder,
and created under it (as Outlook does). A “new folder” restore puts events
in a new calendar under the default calendar, tasks in a new list under the
default task folder, and contacts in a new folder under the default contacts
folder, so they do not clash with the new mail folder of the same name.
The import API identifies folders by its own IDs
(/admin/exchange/mailboxes/{id}/folders), not by the Outlook API’s.
Attributes¶
Classes¶
A mailbox's folders, read as needed, created when missing. |
|
An import session's pre-authenticated URL, renewed before it expires. |
Functions¶
|
Folder names along a backed-up path ("Inbox/Projects" → two names). |
|
Whether an item is still in the mailbox as it was backed up. |
|
How to learn the names of a mailbox's default calendar, contacts and tasks folders. |
|
Import messages', events' and contacts' restore copies into a mailbox. |
Module Contents¶
- s365b.modules.exchange.restore.PERMISSION_HINT = 'The Restore app may not write to this mailbox. In Microsoft 365 tenant, choose Update permissions.'[source]¶
- s365b.modules.exchange.restore.split_path(path: str) tuple[str, ...][source]¶
Folder names along a backed-up path (“Inbox/Projects” → two names).
- class s365b.modules.exchange.restore.Folders(ctx: s365b.modules.sdk.ModuleContext, mailbox: str, folder_type: str = FOLDER_TYPE, default_name: collections.abc.Callable[[], collections.abc.Awaitable[str | None]] | None = None)[source]¶
A mailbox’s folders, read as needed, created when missing.
- Parameters:
ctx – Module context (Restore app).
mailbox – Mailbox ID for the import API.
folder_type – The kind of folder:
IPF.Note(mail),IPF.Appointment(calendar),IPF.ContactorIPF.Task. Folders of other kinds are ignored, and new folders are of this kind.default_name – Returns the name of the mailbox’s default folder of this kind (e.g. “Calendar”, or its translation), or
Noneif it cannot be read.
- async default() str[source]¶
The default folder of this kind, e.g. Calendar.
The folder at the top with the default folder’s name; without that name, the first one at the top.
- Returns:
Its import API ID.
- Raises:
ModuleError – If the mailbox has none.
- async named(name: str) str[source]¶
A calendar or task list by name: at the top, else under the default one.
One that is missing is created under the default folder.
- Parameters:
name – The calendar’s or list’s name.
- Returns:
Its import API ID.
- async ensure(parts: tuple[str, ...], under: str = '') str[source]¶
Return the ID of the folder at
parts, creating what is missing.- Parameters:
parts – Folder names from the top of the mailbox, or from
under.under – The folder to start from (default: the top).
- Returns:
The import API’s ID of the last folder.
- class s365b.modules.exchange.restore.ImportSession(ctx: s365b.modules.sdk.ModuleContext, mailbox: str)[source]¶
An import session’s pre-authenticated URL, renewed before it expires.
- Parameters:
ctx – Module context (Restore app).
mailbox – Mailbox ID.
- async s365b.modules.exchange.restore.still_in_place(reader: s365b.graph.client.GraphClient, user: str, item: s365b.modules.sdk.StoredItem) bool[source]¶
Whether an item is still in the mailbox as it was backed up.
A message counts as still there in the folder it was backed up in. An event, contact or task must also be unchanged: restoring last week’s version of an event edited since adds that version back.
An item that was moved (e.g. to Deleted Items) or deleted is restored.
- Parameters:
reader – Graph client with read access (the Backup app).
user – The mailbox’s user ID.
item – The backed-up message, event, contact or task.
- Returns:
True if it is still there, unchanged.
- s365b.modules.exchange.restore.default_names(reader: s365b.graph.client.GraphClient | None, user: str) dict[str, collections.abc.Callable[[], collections.abc.Awaitable[str | None]]][source]¶
How to learn the names of a mailbox’s default calendar, contacts and tasks folders.
Read with the Backup app (the import API does not mark them);
Noneif it cannot.- Parameters:
reader – Graph client with read access, if any.
user – The mailbox’s user ID.
- Returns:
A name reader by item type.
- async s365b.modules.exchange.restore.restore_mail(ctx: s365b.modules.sdk.ModuleContext, request: s365b.modules.sdk.RestoreRequest, mailbox_id: Any) s365b.modules.sdk.RestoreResult[source]¶
Import messages’, events’ and contacts’ restore copies into a mailbox.
Options:
destinationis"original"(the folders they were in) or"folder"(under a new folder namedfolder_name, keeping the folder structure; see the module for events and contacts). Restoring to the original folders of the same mailbox skips items that are still where they were.- Parameters:
ctx – Module context with the Restore app’s client (and
reader).request – Messages and where to put them.
mailbox_id – Coroutine function returning a user’s mailbox ID.
- Returns:
The outcome.
- Raises:
ModuleError – If the options are wrong or the Restore app lacks permissions.