Skip to content

Commit

Permalink
tidy_msg
Browse files Browse the repository at this point in the history
  • Loading branch information
hrbrmstr committed May 6, 2021
1 parent c814941 commit 40098e0
Show file tree
Hide file tree
Showing 12 changed files with 149 additions and 59 deletions.
11 changes: 6 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: msgxtractr
Type: Package
Title: Read Outlook '.msg' Files
Version: 0.2.1
Date: 2017-08-23
Version: 0.3.0
Date: 2020-05-06
Authors@R: c(
person("Bob", "Rudis", email = "[email protected]", role = c("aut", "cre")),
person("Ariya", "Hidayat", email = "[email protected]", role = c("ctb", "cph"), comment = "POLE library"),
Expand All @@ -23,9 +23,10 @@ Suggests:
testthat,
covr
Depends:
R (>= 3.2.0)
R (>= 3.5.0)
Imports:
Rcpp,
scales
RoxygenNote: 6.1.1
scales,
tibble
RoxygenNote: 7.1.1
LinkingTo: Rcpp
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# Generated by roxygen2: do not edit by hand

S3method(as_tibble,msg)
S3method(print,msg)
export(decode_rtf)
export(is_rtf)
export(read_msg)
export(save_attachments)
export(tidy_msg)
importFrom(Rcpp,sourceCpp)
importFrom(scales,comma)
importFrom(tibble,as_tibble)
useDynLib(msgxtractr, .registration=TRUE)
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
0.3.0
* Added `tidy_msg()` to turn a `msg` object into a `tibble`

0.2.1
* Fixed issue #2

Expand Down
22 changes: 22 additions & 0 deletions R/as-tibble.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#' Turn a single `msg` object into a `tibble`
#'
#' @param x a `msg` object
#' @param ... passed on to [tibble::as_tibble()]
#' @export
tidy_msg <- function(x, ...) {

x <- unclass(x)

x <- x[lengths(x) > 0]

for (idx in which(sapply(x, mode) == "list")) {
x[[idx]] <- list(x[[idx]])
}

tibble::as_tibble(x, ...)

}

#' @rdname tidy_msg
#' @export
as_tibble.msg <- tidy_msg
1 change: 1 addition & 0 deletions R/msgxtractr-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#' @docType package
#' @author Bob Rudis (bob@@rud.is)
#' @importFrom scales comma
#' @importFrom tibble as_tibble
#' @useDynLib msgxtractr, .registration=TRUE
#' @importFrom Rcpp sourceCpp
NULL
17 changes: 6 additions & 11 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ The following functions are implemented:

- `read_msg`: Read in an Outlook '.msg' file
- `save_attachments`: Save all attachments from a 'msg' object
- `tidy_msg`: Turn a 'msg' object into a 'tibble'

### Installation

Expand All @@ -29,7 +30,7 @@ options(width=120)
```{r message=FALSE, warning=FALSE, error=FALSE}
library(msgxtractr)
# current verison
# current version
packageVersion("msgxtractr")
str(msg1 <- read_msg(system.file("extdata/unicode.msg", package="msgxtractr")))
Expand All @@ -41,17 +42,11 @@ str(msg2 <- read_msg(system.file("extdata/TestMessage-ansi.msg", package="msgxtr
str(msg3 <- read_msg(system.file("extdata/TestMessage-default.msg", package="msgxtractr")))
str(msg4 <- read_msg(system.file("extdata/TestMessage-unicode.msg", package="msgxtractr")))
```

### Test Results

```{r message=FALSE, warning=FALSE, error=FALSE}
library(msgxtractr)
library(testthat)
date()
test_dir("tests/")
str(tidy_msg(msg1), 2)
str(tidy_msg(msg2), 2)
str(tidy_msg(msg3), 2)
str(tidy_msg(msg4), 2)
```

### Code of Conduct
Expand Down
77 changes: 58 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@

[![Build Status](https://travis-ci.org/hrbrmstr/msgxtractr.svg?branch=master)](https://travis-ci.org/hrbrmstr/msgxtractr) [![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/github/hrbrmstr/msgxtractr?branch=master&svg=true)](https://ci.appveyor.com/project/hrbrmstr/msgxtractr) [![codecov](https://codecov.io/gh/hrbrmstr/msgxtractr/branch/master/graph/badge.svg)](https://codecov.io/gh/hrbrmstr/msgxtractr)
[![Build
Status](https://travis-ci.org/hrbrmstr/msgxtractr.svg?branch=master)](https://travis-ci.org/hrbrmstr/msgxtractr)
[![AppVeyor Build
Status](https://ci.appveyor.com/api/projects/status/github/hrbrmstr/msgxtractr?branch=master&svg=true)](https://ci.appveyor.com/project/hrbrmstr/msgxtractr)
[![codecov](https://codecov.io/gh/hrbrmstr/msgxtractr/branch/master/graph/badge.svg)](https://codecov.io/gh/hrbrmstr/msgxtractr)

`msgxtractr` : Read Outlook '.msg' Files
`msgxtractr` : Read Outlook .msg Files

'Microsoft' 'Outlook' messages can be saved in '.msg' files. Tools are provided that enable extraction of metadata, envelope, headers, body and attachments from these files.
‘Microsoft’ ‘Outlook’ messages can be saved in ‘.msg’ files. Tools are
provided that enable extraction of metadata, envelope, headers, body and
attachments from these files.

The following functions are implemented:

- `read_msg`: Read in an Outlook '.msg' file
- `save_attachments`: Save all attachments from a 'msg' object
- `read_msg`: Read in an Outlook ‘.msg’ file
- `save_attachments`: Save all attachments from a ‘msg’ object
- `tidy_msg`: Turn a ‘msg’ object into a ‘tibble’

### Installation

Expand All @@ -21,18 +28,18 @@ devtools::install_github("hrbrmstr/msgxtractr")
``` r
library(msgxtractr)

# current verison
# current version
packageVersion("msgxtractr")
```

## [1] '0.2.1'
## [1] '0.3.0'

``` r
str(msg1 <- read_msg(system.file("extdata/unicode.msg", package="msgxtractr")))
```

## List of 8
## $ headers :Classes 'tbl_df', 'tbl' and 'data.frame': 1 obs. of 18 variables:
## $ headers : tibble [1 × 18] (S3: tbl_df/tbl/data.frame)
## ..$ Return-path : chr "<[email protected]>"
## ..$ Received :List of 1
## .. ..$ : chr [1:4] "from st11p00mm-smtpin007.mac.com ([17.172.84.240])\nby ms06561.mac.com (Oracle Communications Messaging Server "| __truncated__ "from mail-vc0-f182.google.com ([209.85.220.182])\nby st11p00mm-smtpin007.mac.com\n(Oracle Communications Messag"| __truncated__ "by mail-vc0-f182.google.com with SMTP id ie18so3484487vcb.13 for\n<[email protected]>; Mon, 18 Nov 2013 00:26:25 -0800 (PST)" "by 10.58.207.196 with HTTP; Mon, 18 Nov 2013 00:26:24 -0800 (PST)"
Expand Down Expand Up @@ -217,26 +224,58 @@ str(msg4 <- read_msg(system.file("extdata/TestMessage-unicode.msg", package="msg
## ..$ last_mod_name: NULL
## - attr(*, "class")= chr "msg"

### Test Results
``` r
str(tidy_msg(msg1), 2)
```

## tibble [1 × 8] (S3: tbl_df/tbl/data.frame)
## $ headers :List of 1
## $ sender :List of 1
## $ recipients :List of 1
## $ subject : chr "Test for TIF files"
## $ body :List of 1
## $ attachments :List of 1
## $ display_envelope:List of 1
## $ times :List of 1

``` r
library(msgxtractr)
library(testthat)
str(tidy_msg(msg2), 2)
```

date()
## tibble [1 × 4] (S3: tbl_df/tbl/data.frame)
## $ recipients :List of 1
## $ body :List of 1
## $ attachments:List of 1
## $ times :List of 1

``` r
str(tidy_msg(msg3), 2)
```

## [1] "Mon Aug 28 21:55:44 2017"
## tibble [1 × 7] (S3: tbl_df/tbl/data.frame)
## $ sender :List of 1
## $ recipients :List of 1
## $ subject : chr "New Message!"
## $ body :List of 1
## $ attachments :List of 1
## $ display_envelope:List of 1
## $ times :List of 1

``` r
test_dir("tests/")
str(tidy_msg(msg4), 2)
```

## ..........testthat results ========================================================================================================
## OK: 4 SKIPPED: 0 FAILED: 0
##
## DONE ===================================================================================================================
## tibble [1 × 7] (S3: tbl_df/tbl/data.frame)
## $ sender :List of 1
## $ recipients :List of 1
## $ subject : chr "New Message!"
## $ body :List of 1
## $ attachments :List of 1
## $ display_envelope:List of 1
## $ times :List of 1

### Code of Conduct

Please note that this project is released with a [Contributor Code of Conduct](CONDUCT.md). By participating in this project you agree to abide by its terms.
Please note that this project is released with a [Contributor Code of
Conduct](CONDUCT.md). By participating in this project you agree to
abide by its terms.
1 change: 0 additions & 1 deletion man/msgxtractr.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/save_attachments.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions man/tidy_msg.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 21 additions & 21 deletions msgxtractr.Rproj
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
Version: 1.0
RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default
EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8
RnwWeave: Sweave
LaTeX: pdfLaTeX
StripTrailingWhitespace: Yes
BuildType: Package
PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source
PackageBuildArgs: --resave-data
PackageRoxygenize: rd,collate,namespace
Version: 1.0

RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default

EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8

RnwWeave: Sweave
LaTeX: pdfLaTeX

StripTrailingWhitespace: Yes

BuildType: Package
PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source
PackageBuildArgs: --resave-data
PackageRoxygenize: rd,collate,namespace
9 changes: 9 additions & 0 deletions tests/testthat/test-msgxtractr.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,13 @@ test_that("we can do something", {

expect_equal(nrow(mail_df), 100)

do.call(
rbind.data.frame,
lapply(1:10, function(.x) {
tidy_msg(read_msg(system.file("extdata/unicode.msg", package="msgxtractr")))
})
) -> res

expect_equal(nrow(res), 10)

})

0 comments on commit 40098e0

Please sign in to comment.