r-lib / gmailr

Access the Gmail RESTful API from R.
https://gmailr.r-lib.org
Other
229 stars 56 forks source link

gmailr hangs with larger attachments #75

Closed alansz closed 5 years ago

alansz commented 7 years ago

Windows 7, using Rstudio .99.903, R3.3.1, and a cygwin toolchain.

When I attempt to send some PDF files as attachments via gmailr, the send_message commands hangs. I can send a text file attachment or a small pdf (11k) but not a pdf (356k in size).

If I terminate the R session while this is hanging, I get: Error in curl::curl_fetch_memory(url, handle = handle) : Operation was aborted by an application callback

If I debug into a tweaked send_message, I see:

curl::curl_fetch_memory(url, handle = handle) 7 request_fetch.write_memory(req$output, req$url, handle) 6 request_fetch(req$output, req$url, handle) 5 request_perform(req, hu$handle$handle) 4 fun(gmail_path(user_id, location), config(token = get_token()), ...) 3 gmailr_query(POST, location, user_id, class, ...) 2 gmailr:::gmailr_POST(c("messages", "send"), user_id, class = "gmail_message", query = list(uploadType = type), body = jsonlite::toJSON(auto_unbox = TRUE, null = "null", c(threadId = thread_id, list(raw = gmailr:::base64url_encode(mail)))), httr::add_headers(Content-Type = "application/json")) 1 send_message_fixed(msg3)

The url curl is calling is ""https://www.googleapis.com/gmail/v1/users/me/messages/send?uploadType=multipart"

So it may be curl's fault. Is it?

Here's my test code:

library(gmailr)

use_secret_file('PMAC-CCC.json') from<-'alansz@uic.edu' to<-'alansz@uic.edu' body<-'Testing' subject<-'Testing'

mime() %>% from(from) %>% to(to) %>% text_body(body) %>% subject(subject) -> msg

msg %>% attach_file('test.pdf') -> msg2 send_message(msg2)

msg %>% attach_file('test2.pdf') -> msg3 send_message(msg3)

alansz commented 7 years ago

Hmm. Updated curl from 2.1 to 2.2 and now even the small test pdf won't send.

schatt89 commented 7 years ago

It's a pity it still doesn't work, no files can be attached :(

wimpel commented 6 years ago

same here... too bad

jimhester commented 5 years ago

This seems to be fixed, gmailr has no problem with a 5Mb attachment. Note the API has a limit of 25Mb for an attachment.

``` r
pkgload::load_all("~/p/gmailr")
#> Loading gmailr
for (i in 1:10) {
  iris <- rbind(iris, iris)
}
write.csv(iris, "iris.csv")
file.size("iris.csv")
#> [1] 5324358
gm_mime() %>%
  gm_from("email@foo.com") %>%
  gm_to("email@bar.com") %>%
  gm_subject("I bought you") %>%
  gm_text_body('Some flowers!') %>%
  gm_attach_file("iris.csv") %>%
  gm_create_draft()
#> Draft Id: r-3012378952667407841 
#> Thread Id: 16caba3313022b33

Created on 2019-08-19 by the reprex package (v0.3.0)