diff --git a/NEWS.md b/NEWS.md index 4dbba14f..c00a7867 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# blastula 0.3.3 + +* The `file` argument of `add_attachment()` now supports a vector of strings (#239, thanks @shrektan for the PR). + # blastula 0.3.2 * Email content width is now customizable in the `blastula_email()` and `compose_email()` functions. The default width is now increased to 1000px (#178). diff --git a/R/add_attachment.R b/R/add_attachment.R index aa3ab30e..68c5499d 100644 --- a/R/add_attachment.R +++ b/R/add_attachment.R @@ -31,16 +31,15 @@ add_attachment <- function(email, normalizePath(mustWork = TRUE) # Create the attachment list - attachment_list <- - list( - file_path = expanded_path, - content_type = content_type, - disposition = "attachment", - filename = filename - ) + attachment_list <- Map(function(path, type, name) list( + file_path = path, + content_type = type, + disposition = "attachment", + filename = name + ), expanded_path, content_type, filename, USE.NAMES = FALSE) # Add the attachment list to `email$attachments` - email$attachments <- c(email$attachments, list(attachment_list)) + email$attachments <- c(email$attachments, attachment_list) email } diff --git a/tests/testthat/test-compose_email.R b/tests/testthat/test-compose_email.R index 1b0a905c..62f44630 100644 --- a/tests/testthat/test-compose_email.R +++ b/tests/testthat/test-compose_email.R @@ -206,3 +206,17 @@ Here is a plot: class = "character" ) }) + +test_that("add_attachment supports multiple files", { + files <- c(tempfile(fileext = ".txt"), tempfile(fileext = ".txt")) + writeLines("file1", files[1]) + writeLines("file2", files[2]) + email <- compose_email("test") + out1 <- add_attachment(email, files)$attachments + out2 <- local({ + email <- add_attachment(email, files[1]) + email <- add_attachment(email, files[2]) + email$attachments + }) + expect_equal(out1, out2) +})