s365b.modules.exchange.restore ============================== .. py:module:: s365b.modules.exchange.restore .. autoapi-nested-parse:: 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 ---------- .. autoapisummary:: s365b.modules.exchange.restore.FTS s365b.modules.exchange.restore.IMMUTABLE s365b.modules.exchange.restore.FOLDER_TYPE s365b.modules.exchange.restore.FOLDER_TYPES s365b.modules.exchange.restore.IMPORT_PARALLEL s365b.modules.exchange.restore.CHUNK s365b.modules.exchange.restore.SESSION_MARGIN s365b.modules.exchange.restore.SESSION_FALLBACK s365b.modules.exchange.restore.FALLBACK_FOLDER s365b.modules.exchange.restore.PERMISSION_HINT Classes ------- .. autoapisummary:: s365b.modules.exchange.restore.Folders s365b.modules.exchange.restore.ImportSession Functions --------- .. autoapisummary:: s365b.modules.exchange.restore.split_path s365b.modules.exchange.restore.still_in_place s365b.modules.exchange.restore.default_names s365b.modules.exchange.restore.restore_mail Module Contents --------------- .. py:data:: FTS :value: 'fts' .. py:data:: IMMUTABLE .. py:data:: FOLDER_TYPE :value: 'IPF.Note' .. py:data:: FOLDER_TYPES .. py:data:: IMPORT_PARALLEL :value: 4 .. py:data:: CHUNK :value: 100 .. py:data:: SESSION_MARGIN .. py:data:: SESSION_FALLBACK .. py:data:: FALLBACK_FOLDER :value: 'Inbox' .. py:data:: PERMISSION_HINT :value: 'The Restore app may not write to this mailbox. In Microsoft 365 tenant, choose Update permissions.' .. py:function:: split_path(path: str) -> tuple[str, ...] Folder names along a backed-up path ("Inbox/Projects" → two names). .. py:class:: 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) A mailbox's folders, read as needed, created when missing. :param ctx: Module context (Restore app). :param mailbox: Mailbox ID for the import API. :param folder_type: The kind of folder: ``IPF.Note`` (mail), ``IPF.Appointment`` (calendar), ``IPF.Contact`` or ``IPF.Task``. Folders of other kinds are ignored, and new folders are of this kind. :param default_name: Returns the name of the mailbox's default folder of this kind (e.g. "Calendar", or its translation), or ``None`` if it cannot be read. .. py:attribute:: ctx .. py:attribute:: base .. py:attribute:: folder_type :value: 'IPF.Note' .. py:attribute:: default_name :value: None .. py:attribute:: created :type: list[str] :value: [] .. py:method:: default() -> str :async: 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. .. py:method:: named(name: str) -> str :async: 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. :param name: The calendar's or list's name. :returns: Its import API ID. .. py:method:: ensure(parts: tuple[str, ...], under: str = '') -> str :async: Return the ID of the folder at ``parts``, creating what is missing. :param parts: Folder names from the top of the mailbox, or from ``under``. :param under: The folder to start from (default: the top). :returns: The import API's ID of the last folder. .. py:class:: ImportSession(ctx: s365b.modules.sdk.ModuleContext, mailbox: str) An import session's pre-authenticated URL, renewed before it expires. :param ctx: Module context (Restore app). :param mailbox: Mailbox ID. .. py:attribute:: ctx .. py:attribute:: mailbox .. py:method:: url(*, renew: bool = False) -> str :async: The current import URL (a new session when needed). .. py:method:: put(folder_id: str, data: bytes) -> str :async: Import one item into a folder. :param folder_id: Import API folder ID. :param data: The item's export stream. :returns: The new item's ID. .. py:function:: still_in_place(reader: s365b.graph.client.GraphClient, user: str, item: s365b.modules.sdk.StoredItem) -> bool :async: 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. :param reader: Graph client with read access (the Backup app). :param user: The mailbox's user ID. :param item: The backed-up message, event, contact or task. :returns: True if it is still there, unchanged. .. py:function:: default_names(reader: s365b.graph.client.GraphClient | None, user: str) -> dict[str, collections.abc.Callable[[], collections.abc.Awaitable[str | None]]] 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); ``None`` if it cannot. :param reader: Graph client with read access, if any. :param user: The mailbox's user ID. :returns: A name reader by item type. .. py:function:: restore_mail(ctx: s365b.modules.sdk.ModuleContext, request: s365b.modules.sdk.RestoreRequest, mailbox_id: Any) -> s365b.modules.sdk.RestoreResult :async: Import messages', events' and contacts' restore copies into a mailbox. Options: ``destination`` is ``"original"`` (the folders they were in) or ``"folder"`` (under a new folder named ``folder_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. :param ctx: Module context with the Restore app's client (and ``reader``). :param request: Messages and where to put them. :param 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.