Learn R Programming

mRpostman (version 0.3.1)

search_string: Search By String

Description

Searches for messages containing a string in an specific section or field.

Usage

search_string(imapconf, section_or_field, string, negate = FALSE,
  by = "MSN", esearch = FALSE, return_imapconf = TRUE, retries = 2)

Arguments

imapconf

An object of class imapconf generated with configure_imap and with a mbox item added after a mailbox selection with select_mailbox.

section_or_field

A mandatory character string specifying in which message's Section or Header Field to search for the provided string. For some available options, see section_or_field_options.

string

A character string specifying the word or expression to search for in messages.

negate

If TRUE, negates the search and seeks for "NOT search_criterion". Default is FALSE.

by

Which id (MSN or UID) to use when searching for messages. "MSN" or message squence number is a message's relative position to the older message in the mailbox. It may change after deleting or moving messages. For instance, if a message is deleted, message sequence numbers are reordered to fill the gap. "UID" or unique identifier is always the same during the life cycle of a message. Default is "MSN".

esearch

A logical. Default is FALSE. If the IMAP server has ESEARCH capability, it can be used to optimize search results. It allows to condense results to message sets to cut down on transmission costs, e.g. 1:5 instead of writing ids individually such as 1,2,3,4,5. It can be used along with buffersize to avoid results stripping. Check if your IMAP server supports SEARCH with list_server_capabilities.

return_imapconf

A logical. If TRUE, the function returns a list of length 2, containing the imapconf object (IMAP settings) and the search results as message ids ("MSN" or "UID"). If FALSE, returns only the message ids as a numeric vector. Default is TRUE.

retries

Number of attempts to connect and execute the command. Default is 2.

Value

Depending on the return_imapconf parameter, it can be a list of length 2 containing the imapconf object and message ids resulted from search, or a numeric vector containing only message ids.

Examples

Run this code
# NOT RUN {
# }
# NOT RUN {
# configure IMAP
library(mRpostman)
imapconf <- configure_imap(url="imaps://your.imap.server.com",
                           username="your_username",
                           password=rstudioapi::askForPassword()
                          )

# search
results <- imapconf %>%
    select_mailbox(mbox = "TAM") %>%
    search_string(section_or_field = "FROM",
                  string = "michelle@hotmail.com",
                  negate = TRUE
                 ) # not FROM "michele"

# }
# NOT RUN {
# }

Run the code above in your browser using DataLab