datawookie / emayili

Compare 83e15d2 ... +11 ... a7ec347

No flags found

Use flags to group coverage reports by test type, project and/or folders.
Then setup custom commit statuses and notifications for each flag.

e.g., #unittest #integration

#production #enterprise

#frontend #backend

Learn more about Codecov Flags here.


@@ -22,6 +22,9 @@
Loading
22 22
#' @param encoding How content is transformed to ASCII. Options are
23 23
#'   \code{"7bit"}, \code{"quoted-printable"} and \code{"base64"}. Use \code{NA}
24 24
#'   or \code{NULL} for no (or "identity") encoding.
25 +
#' @param language Langauge of content. If \code{FALSE} then will not include
26 +
#'   language field. If \code{TRUE} then will attempt to auto-detect language.
27 +
#'   Otherwise will use the specified language.
25 28
#' @param boundary Boundary string.
26 29
#' @param type The MIME type of the content.
27 30
#' @param children List of child MIME objects.
@@ -69,6 +72,7 @@
Loading
69 72
  disposition = NA,
70 73
  charset = NA,
71 74
  encoding = NA,
75 +
  language = NA,
72 76
  format = NA,
73 77
  boundary = emayili:::hexkey(),
74 78
  type = NA,
@@ -87,6 +91,7 @@
Loading
87 91
      disposition = disposition,
88 92
      charset = charset,
89 93
      encoding = encoding,
94 +
      language = language,
90 95
      format = format,
91 96
      boundary = boundary,
92 97
      children = children,
@@ -318,6 +323,7 @@
Loading
318 323
    content_type(type, x$charset, x$boundary, x$format),
319 324
    content_disposition(x$disposition),
320 325
    content_transfer_encoding(x$encoding),
326 +
    content_language(x$language, x$content),
321 327
    x_attachment_id(x$cid),
322 328
    content_id(x$cid)
323 329
  )

@@ -218,3 +218,54 @@
Loading
218 218
    subject(paste0(subject_prefix, subject(msg)))
219 219
  if (get_option_invisible()) invisible(msg) else msg # nocov
220 220
}
221 +
222 +
#' Add or query comments of message.
223 +
#'
224 +
#' @param msg A message object.
225 +
#' @param comments Comments for the message.
226 +
#'
227 +
#' @return A message object or the comments of the message object (if \code{comments} is \code{NULL}).
228 +
#' @seealso \code{\link{subject}}
229 +
#' @export
230 +
#' @examples
231 +
#' # Create a message and set the comments.
232 +
#' msg <- envelope() %>% comments("This is a comment")
233 +
#'
234 +
#' # Retrieve the comments for a message.
235 +
#' comments(msg)
236 +
comments <- function(msg, comments = NULL) {
237 +
  if (is.null(comments)) {
238 +
    header_get(msg, "Comments")
239 +
  } else {
240 +
    msg <- header_set(msg, "Comments", comments, append = FALSE)
241 +
    if (get_option_invisible()) invisible(msg) else msg # nocov
242 +
  }
243 +
}
244 +
245 +
#' Add or query keywords of message.
246 +
#'
247 +
#' @param msg A message object.
248 +
#' @param ... Keywords.
249 +
#' @param append Whether to append or replace keywords.
250 +
#'
251 +
#' @return A message object or the comments of the message object (if \code{comments} is \code{NULL}).
252 +
#' @seealso \code{\link{to}}, \code{\link{from}}, \code{\link{cc}}, \code{\link{bcc}} and \code{\link{reply}}
253 +
#' @export
254 +
#' @examples
255 +
#' # Create a message and set the keywords.
256 +
#' envelope() %>% keywords("newsletter, marketing")
257 +
#' envelope() %>% keywords("newsletter", "marketing")
258 +
#' envelope() %>% keywords(c("newsletter", "marketing"))
259 +
#'
260 +
#' # Retrieve the keywords for a message.
261 +
#' msg <- envelope() %>% keywords("newsletter, marketing")
262 +
#' keywords(msg)
263 +
keywords <- function(msg, ..., append = FALSE) {
264 +
   arguments <- c(...)
265 +
  if (is.null(arguments)) {
266 +
    header_get(msg, "Keywords")
267 +
  } else {
268 +
    msg <- header_set(msg, "Keywords", arguments, append = append, sep = ", ")
269 +
    if (get_option_invisible()) invisible(msg) else msg # nocov
270 +
  }
271 +
}

@@ -3,7 +3,8 @@
Loading
3 3
  params = NULL,
4 4
  squish = TRUE,
5 5
  css,
6 -
  include_css
6 +
  include_css,
7 +
  language
7 8
) {
8 9
  stopifnot(is.null(params) || is.list(params))
9 10
@@ -154,7 +155,7 @@
Loading
154 155
    # Remove <meta> tag (a "Content-Type" <meta> inserted by {xml2}).
155 156
    str_replace("<meta[^>]*>", "")
156 157
157 -
  output <- text_html(output, squish = squish, css = css)
158 +
  output <- text_html(output, squish = squish, css = css, language = language)
158 159
159 160
  if (plain) {
160 161
    output
@@ -254,6 +255,7 @@
Loading
254 255
  squish = TRUE,
255 256
  css_files = c(),
256 257
  include_css = c("rmd", "bootstrap", "highlight"),
258 +
  language = FALSE,
257 259
  interpolate = TRUE,
258 260
  .open = "{{",
259 261
  .close = "}}",
@@ -311,7 +313,8 @@
Loading
311 313
    params,
312 314
    squish,
313 315
    list(extra = read_text(css_files)),
314 -
    include_css
316 +
    include_css,
317 +
    language
315 318
  )
316 319
317 320
  msg <- append(msg, body)

@@ -41,25 +41,59 @@
Loading
41 41
  disposition = "inline",
42 42
  charset = "utf-8",
43 43
  encoding = "7bit",
44 +
  language = FALSE,
44 45
  interpolate = TRUE,
45 46
  .open = "{{",
46 47
  .close = "}}",
47 48
  .envir = NULL
48 49
) {
49 50
  check_message_body(content)
50 51
51 -
  if (is.null(.envir)) .envir = parent.frame()
52 -
  else .envir = list2env(.envir)
52 +
  if (is.null(.envir)) {
53 +
    .envir <- parent.frame()
54 +
  } else {
55 +
    .envir <- list2env(.envir)
56 +
  }
53 57
54 58
  if (interpolate) content <- glue(content, .open = .open, .close = .close, .envir = .envir)
55 59
56 -
  body <- text_plain(content, disposition, charset, encoding)
60 +
  body <- text_plain(content, disposition, charset, encoding, language)
57 61
58 62
  msg <- append(msg, body)
59 63
60 64
  if (get_option_invisible()) invisible(msg) else msg # nocov
61 65
}
62 66
67 +
#' Transfor a (tag)list to a character string
68 +
#'
69 +
#' @param content element to transform.
70 +
#'
71 +
#' @return If the content is a list, a tagList or a tag,
72 +
#'     a character vector. Otherwise, it will return the
73 +
#'     input unchanged.
74 +
#'
75 +
#' @noRd
76 +
#' @examples
77 +
#' list_to_char(list("<h2>this</h2>", "<p>That</p>"))
78 +
#' library(htmltools)
79 +
#' list_to_char(tagList(h2("this"), p("That")))
80 +
list_to_char <- function(content) {
81 +
  if (
82 +
    # We do the change if the element is a
83 +
    # tag or a tag.list
84 +
    inherits(content, "shiny.tag.list") |
85 +
    inherits(content, "shiny.tag")
86 +
  ) {
87 +
    content <- as.character(content)
88 +
  }
89 +
  # Then if we have a list, we collapse it to
90 +
  # a character vector
91 +
  if (length(content) > 1) {
92 +
    content <- paste(content, collapse = "\n")
93 +
  }
94 +
  content
95 +
}
96 +
63 97
#' Add an HTML body to a message object.
64 98
#'
65 99
#' @inheritParams text
@@ -77,34 +111,49 @@
Loading
77 111
#' htmlfile <- tempfile(fileext = ".html")
78 112
#' cat("<p>Hello!</p>\n", file = htmlfile)
79 113
#' envelope() %>% html(htmlfile)
114 +
#'
115 +
#' # You can pass a a vector of character
116 +
#' # Note that they will be separated with a `\n`
117 +
#' envelope() %>% html(c("<b>Hello!</b>", "<p>World</p>"))
118 +
#'
119 +
#' # You can also pass a tagList built with {htmltools}
120 +
#' if (requireNamespace("hmltools", quietly = TRUE)) {
121 +
#'   library(htmltools)
122 +
#'   envelope() %>% html(tagList(h2("Hello"), p("World")))
123 +
#' }
80 124
html <- function(
81 125
  msg,
82 126
  content,
83 127
  disposition = "inline",
84 128
  charset = "utf-8",
85 129
  encoding = "quoted-printable",
86 130
  css_files = c(),
131 +
  language = FALSE,
87 132
  interpolate = TRUE,
88 133
  .open = "{{",
89 134
  .close = "}}",
90 135
  .envir = NULL
91 136
) {
92 -
  check_message_body(content)
137 +
  content <- list_to_char(content)
93 138
94 139
  # Check if it's a file.
95 140
  #
96 141
  if (file.exists(content)) {
97 142
    content <- paste(readLines(content), collapse = "\n")
98 143
  }
99 144
100 -
  if (is.null(.envir)) .envir = parent.frame()
101 -
  else .envir = list2env(.envir)
145 +
  if (is.null(.envir)) {
146 +
    .envir <- parent.frame()
147 +
  } else {
148 +
    .envir <- list2env(.envir)
149 +
  }
102 150
103 151
  if (interpolate) content <- glue(content, .open = .open, .close = .close, .envir = .envir)
104 152
105 153
  body <- text_html(
106 154
    content, disposition, charset, encoding,
107 -
    css = read_text(css_files)
155 +
    css = read_text(css_files),
156 +
    language = language
108 157
  )
109 158
110 159
  msg <- append(msg, body)

@@ -189,7 +189,6 @@
Loading
189 189
  x
190 190
}
191 191
192 -
193 192
#' Test if list is nested or flat
194 193
#'
195 194
#' @noRd

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Learn more Showing 1 files with coverage changes found.

New file R/header-language.R
New
Loading file...
Files Coverage
R -1.53% 98.30%
Project Totals (18 files) 98.30%
Loading