R/parse-search-ids.R

Defines functions parse_search_ids

#' Extract the message ids of a plain SEARCH response
#'
#' Reads the ids of the untagged \code{* SEARCH n n n ...} line. The
#' \code{(MODSEQ n)} item that servers append when the search uses the
#' CONDSTORE \code{MODSEQ} criterion (RFC 7162) is discarded, so that the
#' modification sequence is never mistaken for a message id.
#' @param content_char A \code{character} string with the server response.
#' @return A \code{numeric} vector of ids (possibly empty).
#' @noRd
parse_search_ids <- function(content_char) {
  m <- stringr::str_match_all(content_char, "\\*\\s+SEARCH([^\r\n]*)")[[1]]
  if (nrow(m) == 0) {
    return(numeric(0))
  }
  body <- gsub("\\(MODSEQ\\s+\\d+\\)", "", paste(m[, 2], collapse = " "))
  as.numeric(stringr::str_extract_all(body, "\\d+")[[1]])
}

Try the mRpostman package in your browser

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

mRpostman documentation built on Nov. 6, 2026, 9:06 a.m.