Skip to content

Commit ea90ce2

Browse files
authored
Allow to set MIME type for attached files
Fixes #9.
1 parent f57bfbc commit ea90ce2

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

R/mime_part.R

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,19 +197,25 @@ mime_part.data.frame <- function(
197197
##'
198198
##' @param x Character string, possibly a filename.
199199
##' @param name Name of attachment.
200-
##' @param type Content type of inline text. Defaults to "text/plain".
200+
##' @param type Content type of inline text. Defaults to "text/plain" for
201+
##' character strings and to "application/octet-stream" for files.
201202
##' @param flowed Should "format=flowed" be added to the content header.
202203
##' @param ... Ignored.
203204
##' @return An S3 \code{mime_part} object.
204205
##'
205206
##' @method mime_part character
206207
##' @export
207208
##' @seealso \code{\link{mime_part_html}} for adding inline HTML
208-
mime_part.character <- function(x, name, type = "text/plain", flowed = FALSE, ...) {
209+
mime_part.character <- function(x, name, type, flowed = FALSE, ...) {
209210
if (length(x) == 1 && file.exists(x)) {
210-
.file_attachment(x, name, ...)
211+
if (missing(type)) {
212+
type = "application/octet-stream"
213+
}
214+
.file_attachment(x, name, type, ...)
211215
} else {
212-
216+
if (missing(type)) {
217+
type = "text/plain"
218+
}
213219
res <- .generate_charset_convert_utf8(x)
214220
format_flowed <- ifelse(flowed, "; format=flowed", "")
215221

man/mime_part.character.Rd

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)