IMAP Toolkit for R

Overview

mRpostman makes extensive use of ‘curl’ and ‘libcurl’ capabilities, providing functions for mailboxes and electronic messages manipulation. Beyond many other functionalities, it is possible to move, delete, search and fetch messages or its parts using specific criteria.

mRpostman website: https://allanvc.github.io/mRpostman

First things first …

Before using mRpostman, it is essential to configure your email account. Many mail providers require authorizing “less secure apps” to access your account from a third part app.

See how to do it for Gmail, Yahoo Mail and AOL Mail.

Gmail

  1. Go to Gmail website and log in with your credentials.

  2. Then, go to https://myaccount.google.com/u/1/lesssecureapps?pageId=none

  1. Set “Allow less secure apps” to ON.

Yahoo Mail

  1. Go to Yahoo Mail website and log in with your credentials.

  2. Click on “Account Info”.

  1. Click on “Account Security” on the left menu.

  1. After, set “Allow apps that use less secure sign in” ON

AOL Mail

  1. Go to AOL Mail website and log in with your credentials.

  2. Click on “Options” and then on “Account Info”.

  1. Click on “Account Security” on the left menu.

  1. After, set “Allow apps that use less secure sign in” ON

Outlook - Office 365

There is no need to execute any external configuration. The parameter url in configure_imap() should be set as url="imaps://outlook.office365.com".

Installation

Basic Usage

2) Examining a Mailbox


# examine mailbox -- number of existent and recent messages
imapconf %>%
  select_mailbox(mbox = "Kansas State University") %>% # mbox names are case sensitive
  examine_mailbox()

3) Searching by period using a flag

4) Searching for a string in the “Text” section of messages


# search
results <- imapconf %>%
  select_mailbox(mbox = "Kansas State University") %>%
  search_string(section_or_field = "TEXT", string = "Welcome!")

results$msg_id

5) Fetch headers after searching


results <- imapconf %>%
  select_mailbox(mbox = "Kansas State University") %>%
  search_string(section_or_field = "TEXT", string = "Welcome!") %$% # exposition pipe, not %>%!!
  fetch_msg_header(imapconf = imapconf, 
                   msg_id = msg_id, 
                   fields = c("DATE", "SUBJECT"))

results

6) Attachments

This will list all the attachments filenames and the Content-Disposition type for each fetched message.

imapconf %>%
  select_mailbox(mbox = "INBOX") %>%
  search_since(date_char = "23-Sep-2019") %$%
  fetch_full_msg(imapconf, msg_id=msg_id) %>%
  list_attachments()

This extracts and decode your base64 text attachments (regular and inline) from messages, and save them locally.

imapconf %>%
  select_mailbox(mbox = "INBOX") %>%
  search_since(date_char = "23-Sep-2019") %$%
  fetch_full_msg(imapconf, msg_id=msg_id) %>%
  get_attachments()

Future Improvements

  • better error handling and messages;

  • add further IMAP functionalities;

  • include SMTP support for sending emails.

If you want to contribute, specially with the SMTP support, please contact the package mantainer.

License

This package is licensed under the terms of the GPL-3 License.

References

Crispin, M., INTERNET MESSAGE ACCESS PROTOCOL - VERSION 4rev1, RFC 3501, DOI: 10.17487/RFC3501, March 2003, https://www.rfc-editor.org/info/rfc3501.

Ooms, J. curl: A Modern and Flexible Web Client for R. R package version 3.3, 2019, https://CRAN.R-project.org/package=curl

Stenberg, D. Libcurl - The Multiprotocol File Transfer Library, https://curl.haxx.se/libcurl/