From 5f60f4057af4211d20d4ee1c98bdb0b2af70f1c1 Mon Sep 17 00:00:00 2001 From: Angela <50903312+aalucaci@users.noreply.github.com> Date: Sat, 11 Nov 2023 23:12:32 +0100 Subject: [PATCH] fix Excel attachments (#314) (#316) --- DESCRIPTION | 4 +++- NEWS.md | 2 ++ R/mime.R | 4 ++-- tests/testthat/test-mime.R | 24 ++++++++++++++++++++++++ 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 7ce2fc54..9c110ece 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -47,7 +47,9 @@ Suggests: keyring, knitr, spelling, - xml2 + xml2, + openxlsx, + withr SystemRequirements: pandoc (>= 1.12.3) - http://pandoc.org Encoding: UTF-8 RoxygenNote: 7.2.3 diff --git a/NEWS.md b/NEWS.md index 75b3cd3f..12301cdb 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # blastula (development version) +* Fixed Excel attachments which were broken due to wrong conversion into RFC2822. (#314) + # blastula 0.3.4 * Modified tests to remove specific cases that no longer work in newer versions of R. (#310) diff --git a/R/mime.R b/R/mime.R index d6eaf025..a9ffcabd 100644 --- a/R/mime.R +++ b/R/mime.R @@ -100,8 +100,8 @@ generate_rfc2822 <- function( quoted_filename <- header_quoted( - attachment$filename, - str = "Filename", + str = attachment$filename, + fieldname = "Filename", encode_unicode = TRUE ) diff --git a/tests/testthat/test-mime.R b/tests/testthat/test-mime.R index 5e058ddd..59f77c10 100644 --- a/tests/testthat/test-mime.R +++ b/tests/testthat/test-mime.R @@ -144,3 +144,27 @@ test_that("varying formats for recipient lists work as expected", { grepl("(?% expect_false() }) + +test_that("excel attachment", { + email <- compose_email() + + withr::with_tempfile( + fileext = ".xlsx", + new = "out_file", + code = { + openxlsx::write.xlsx(x = mtcars, file = out_file) + + email <- email %>% + add_attachment(out_file) + + generate_rfc2822( + eml = email, + date = Sys.Date(), + subject = NULL, + from = NULL, + to = NULL + ) %>% + expect_match(paste0('filename=\"', basename(out_file))) + } + ) +})