list email's attachments from Microsoft365R package

0

I am trying to scrape my emails from outlook and list their attachments for some work. I have hundreds of emails and files and this can help out fasten my work flow

I succeeded accessing emails and listing attachments but found one issue, I cannot split the list object of email attachments into rows

for example

`# Create a tibble with a column containing a list of lists 
tbl <- tibble(x = list(list(1,2), list(3,4), list(5,6))) 

# Unnest the list of lists using unnest_longer() 
unnest_list <- unnest_longer(tbl, x) 

# Print the unnested list 
print(unnest_list)`

i was expecting that if I apply something similar each attachment would come in a separate row, thus, duplicating basic info like email subject but it just won't come out of list format

`
library(tidyverse)
library(Microsoft365R)

outlook_app <- get_business_outlook()

# Get the Inbox folder
inbox <- outlook_app$get_inbox()

# Get the specified number of emails
emails <- inbox$list_emails(n = 2)

# list of first email's attachments
emails[[1]]$list_attachments()

# first attachment of first email
emails[[1]]$list_attachments()[1]


#tried
tibble(files=emails[[1]]$list_attachments()) |> 
    mutate(row_id = row_number(),
           files_extracted = map(row_id, \(x){
               emails[[1]]$list_attachments()[x]
           }))

tibble(files=emails[[1]]$list_attachments()) |> 
    mutate(row_id = row_number(),
           files_extracted = map(row_id, \(x){
               pluck(files,x)
           }))

tibble(files=emails[[1]]$list_attachments()) |> 
    mutate(row_id = row_number(),
           files_extracted = files |> 
               unnest_longer())
`

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.