Edits history of script submission #23347 for ' List Folders (outlook)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * List Folders
     * List mail folders with their unread and total counts: the top level, or the children of `parent_folder` (a folder id or well-known name such as `inbox`). Requires Mail.Read (covered by the default Mail.ReadWrite) (a shared mailbox needs Mail.Read.Shared, not a default).
     */
    export async function main(
      auth: RT.Outlook,
      parent_folder: string | undefined,
      top: number = 100,
      next_link: string | undefined,
      mailbox: string | undefined
    ) {
      const base = `https://graph.microsoft.com/v1.0/${
        mailbox != null && mailbox !== ""
          ? `users/${encodeURIComponent(mailbox)}`
          : "me"
      }`
      if (
        next_link != null &&
        next_link !== "" &&
        !next_link.startsWith("https://graph.microsoft.com/")
      ) {
        throw new Error(
          "next_link must be an @odata.nextLink returned by Microsoft Graph"
        )
      }
      let url: URL
      if (next_link != null && next_link !== "") {
        url = new URL(next_link)
      } else {
        url = new URL(
          parent_folder != null && parent_folder !== ""
            ? `${base}/mailFolders/${encodeURIComponent(parent_folder)}/childFolders`
            : `${base}/mailFolders`
        )
        url.searchParams.append("$top", String(top))
      }
    
      const response = await fetch(url, {
        headers: {
          Authorization: `Bearer ${auth.token}`,
          Accept: "application/json",
        },
      })
    
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
    
      return await response.json()
    }
    

    Submitted by hugo989 6 hours ago

  • bunnative
    //native
    
    /**
     * List Folders
     * List mail folders with their unread and total counts: the top level, or the children of `parent_folder` (a folder id or well-known name such as `inbox`). Requires Mail.Read on the connection (Mail.Read.Shared for a shared mailbox).
     */
    export async function main(
      auth: RT.Outlook,
      parent_folder: string | undefined,
      top: number = 100,
      next_link: string | undefined,
      mailbox: string | undefined
    ) {
      const base = `https://graph.microsoft.com/v1.0/${
        mailbox != null && mailbox !== ""
          ? `users/${encodeURIComponent(mailbox)}`
          : "me"
      }`
      if (
        next_link != null &&
        next_link !== "" &&
        !next_link.startsWith("https://graph.microsoft.com/")
      ) {
        throw new Error(
          "next_link must be an @odata.nextLink returned by Microsoft Graph"
        )
      }
      let url: URL
      if (next_link != null && next_link !== "") {
        url = new URL(next_link)
      } else {
        url = new URL(
          parent_folder != null && parent_folder !== ""
            ? `${base}/mailFolders/${encodeURIComponent(parent_folder)}/childFolders`
            : `${base}/mailFolders`
        )
        url.searchParams.append("$top", String(top))
      }
    
      const response = await fetch(url, {
        headers: {
          Authorization: `Bearer ${auth.token}`,
          Accept: "application/json",
        },
      })
    
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
    
      return await response.json()
    }
    

    Submitted by hugo989 6 hours ago