R/header-sensitivity.R

Defines functions sensitivity

Documented in sensitivity

LEVELS_SENSITIVITY <- c("personal", "private", "company-confidential")

#' Set or query message sensitivity
#'
#' Manipulate the \code{Sensitivity} field as specified in \href{https://www.ietf.org/rfc/rfc2156.txt}{RFC 2156}.
#'
#' @param msg A message object.
#' @param sensitivity Sensitivity level. One of \code{"personal"}, \code{"private"}, or \code{"company-confidential"}.
#' @return A message object.
#'
#' @export
#'
#' @examples
#' # Not sensitive.
#' envelope() %>%
#'   subject("Your daily dose of spam")
#'
#' # Sensitive personal message.
#' envelope() %>%
#'   subject("The results from your test") %>%
#'   sensitivity("personal")
#'
#' # Sensitive private message.
#' envelope() %>%
#'   subject("Your OTP (don't show this to anybody!") %>%
#'   sensitivity("private")
#'
#' # Sensitive business message.
#' envelope() %>%
#'   subject("Top Secret Strategy Document") %>%
#'   sensitivity("company-confidential")
#'
sensitivity <- function(msg, sensitivity = NULL) {
  if (is.null(sensitivity)) {
    header_get(msg, "Sensitivity")
  } else {
    if (!(sensitivity %in% LEVELS_SENSITIVITY)) {
      stop("Invalid sensitivity Options are: ", paste(LEVELS_SENSITIVITY, collapse = ", "), ".")
    }

    msg <- header_set(msg, "Sensitivity", sensitivity, append = FALSE)

    if (get_option_invisible()) invisible(msg) else msg # nocov
  }
}

Try the emayili package in your browser

Any scripts or data that you put into this service are public.

emayili documentation built on Aug. 30, 2023, 5:12 p.m.