Learn R Programming

⚠️There's a newer version (1.1.4) of this package.Take me there.

mRpostman

IMAP Tools for R in a Tidy Way

Overview

mRpostman provides multiple IMAP (Internet Message Access Protocol) commands based on the RFC 3501 manual (Crispin, 2003), its updates, and other related documents. Besides other features, this package presents functions for listing, selecting and renaming mailboxes, as well as moving, fetching, and searching for messages using several criteria.

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

First things first …

Before using mRpostman, it is essential to configure your mail 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

Introduction

The package is divided in 7 groups of functions:

  • configuration: configure_imap();
  • mailboxes commands: list_mailboxes(), select_mailbox(), examine_mailbox(), rename_mailbox();
  • options listing: list_server_capabilities(),flag_options(), section_or_field_options(), metadata_options();
  • search: search_before(), search_since(), search_period(), search_on(), search_sent_before(),search_sent_since(), search_sent_period(), search_sent_on(), search_string(), search_flag(), search_smaller_than(), search_larger_than(), search_younger_than(), search_older_than(), custom_search();
  • custom search helper functions:
    • relational operators functions: AND(), OR();
    • criteria definition functions: before(), since(), on(), sent_before(), sent_since(), sent_on(), string(), flag(), smaller_than(), larger_than(), younger_than(), older_than();
  • fetch: fetch_full_msg(), fetch_msg_header(), fetch_msg_text(), fetch_msg_metadata();
  • miscellania: copy_msg(), get_min_id(), get_max_id(), delete_msg(), expunge(), add_flags(), remove_flags(), replace_flags(), move_msg().

Installation

# CRAN version
install.packages("mRpostman")

# Dev version
if (!require('devtools')) install.packages('devtools')
devtools::install_github("allanvc/mRpostman")

Basic Usage

1) Configuring IMAP and listing mailboxes


library(mRpostman)

# IMAP settings
# Gmail
imapconf <- configure_imap(url="imaps://imap.gmail.com",
                          username="your_user",
                          password=rstudioapi::askForPassword()
                          )

# Yahoo Mail
# imapconf <- configureIMAP(url="imaps://export.imap.aol.com/",
#                           username="your_user",
#                           password=rstudioapi::askForPassword()
#                           )

# AOL Mail
# imapconf <- configureIMAP(url="imaps://export.imap.aol.com/",
#                           username="your_user",
#                           password=rstudioapi::askForPassword()
#                           )

# you can try another IMAP server

# Listing
imapconf %>%
  list_mailboxes()

2) Examining a Mailbox


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

3) Searching by period using a flag


# search
results <- imapconf %>%
  select_mailbox(mbox = "INBOX") %>%
  search_period(since_date_char = "17-May-2018",
               before_date_char = "30-Jun-2019",
               flag = "ANSWERED")

results$msg_id

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


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

results$msg_id

5) Fetch headers after searching


results <- imapconf %>%
  select_mailbox(mbox = "UC Riverside") %>%
  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

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/

Copy Link

Version

Install

install.packages('mRpostman')

Monthly Downloads

746

Version

0.2.0

License

GPL-3

Maintainer

Allan Quadros

Last Published

August 22nd, 2019

Functions in mRpostman (0.2.0)

check_args_expunge

Expunge Message Arguments Check
check_args_delete_msg

Delete Message Arguments Check
AND

Relational Operators - Helper Functions for Custom Search
check_args_fetch_full_msg

Full Fetch Arguments Check
check_args_fetch_msg_header

Header Fetch Arguments Check
OR

Relational Operators - Helper Functions for Custom Search
check_args_search_flag

Flag Search Arguments Check
add_flags

Add Flag(s) To Messages
before

Criteria Helper Functions for Custom Search
check_args_search_date

Date Search Arguments Check
check_args_custom_search

Custom Search Arguments Check
check_args_date

Custom Search Specific Check
check_args_within

Custom Search Specific Check
check_args_fetch_msg_text

Text Fetch Arguments Check
check_args_fetch_msg_metadata

Metadata Fetch Arguments Check
check_args_add_replace_flags

Add/Replace Flags Arguments Check
check_args_search_period

Period Search Arguments Check
define_searchrequest_period

Period Search Request
define_searchrequest_flag

Flag Search Request
clean_fetch_results

Messages Results Cleaning
decode_base64_text_if_needed

Messages Results Decoding
%$%

Exposition Pipe operator
custom_search

Custom Search
examine_mailbox

Examine Mailbox
check_args_get_max_min_id

Max/Min Message Arguments Check
check_args_flag

Custom Search Specific Check
config_handle

Curl Handle Configuration
check_args_string

Custom Search Specific Check
check_args_size

Custom Search Specific Check
check_args_copy_msg

Copy Message Arguments Check
delete_msg

Delete Messages
get_min_id

Get Minimum Message ID in a Mailbox
get_max_id

Get Maximum Message ID in a Mailbox
define_searchrequest_within

Within Search Request
define_searchrequest_date

Date Search Request
fetch_msg_metadata

Fetch Message Metadata
fetch_msg_header

Fetch Message Headers
check_args_search_size

Size Search Arguments Check
define_searchrequest_custom

Custom Search Request
check_args_move_msg

Move Message Arguments Check
metadata_options

Message Metadata Options
check_args_search_string

String Search Arguments Check
check_args_remove_flags

Remove Flags Arguments Check
check_args_search_within

Within Search Arguments Check
%>%

Common Pipe operator
list_server_capabilities

IMAP Server Capabilities
loop_fetch_full_msg

Full Fetch Loop
count_msgs

Count Number of Messages
copy_msg

Copy Messages
configure_imap

IMAP Settings
loop_fetch_msg_header

Header Fetch Loop
search_sent_period

Search By Origination (RC-2822 Header) Date
loop_fetch_msg_metadata

Metadata Fetch Loop
search_sent_since

Search By Origination (RC-2822 Header) Date
older_than

Criteria Helper Functions for Custom Search
move_msg

Move Messages
remove_flags

Remove Flag(s) From Messages
section_or_field_options

Section or Header Fields Options
search_flag

Search By Flag
search_before

Search By Internal Date
search_larger_than

Search By Syze
select_mailbox

Mailbox Selection
search_on

Search By Internal Date
on

Criteria Helper Functions for Custom Search
fetch_msg_text

Fetch Message Text
define_searchrequest_size

Size Search Request
search_period

Search By Internal Date
sent_before

Criteria Helper Functions for Custom Search
sent_on

Criteria Helper Functions for Custom Search
since

Criteria Helper Functions for Custom Search
string

Criteria Helper Functions for Custom Search
search_older_than

Search Within seconds
smaller_than

Criteria Helper Functions for Custom Search
sent_since

Criteria Helper Functions for Custom Search
define_searchrequest_string

String Search Request
fetch_full_msg

Fetch Full Messages
expunge

Expunge Messages
fix_search_stripping

Fixing Stripped Search Results
flag

Criteria Helper Functions for Custom Search
larger_than

Criteria Helper Functions for Custom Search
rename_mailbox

Rename Mailbox
search_sent_before

Search By Origination (RC-2822 Header) Date
search_since

Search By Internal Date
list_mailboxes

Listing Mailboxes
replace_flags

Replace Flag(s) in Messages
search_sent_on

Search By Origination (RC-2822 Header) Date
search_smaller_than

Search By Syze
younger_than

Criteria Helper Functions for Custom Search
flag_options

Flag Options
search_younger_than

Search Within seconds
mRpostman-package

IMAP Tools for R
loop_fetch_msg_text

Metadata Fetch Loop
search_string

Search By String