gmailr
is a fantastic package. I can get messages corresponding to particular criteria, but I would also like to know for sure which message with given criteria is the latest. I got a bit stumped there.
If I do > gm_message(msgs[[c(1)]]$messages[[c(1)]]$id)
I get output in console:
Id: 173193ce84e6e040
To: lemon.hwww@gmail.com
From: "Name" <name.surname@gmail.com>
Date: Sat, 4 Jul 2020 10:50:52 +0100
Subject: Test Rsend 2020-07-04
Attachments: 'caseload_data.csv'
I am not sure how I could easily access Date: - if I could then I could employ lubridate
. When I look at the quite complex list structure of the message, I also find an internalDate
- which I am not quite sure how to deal with and I do not know if it is the same as Date: above.
library(gmailr)
# I authenticate properly and can use gmailr functions:
# I get messages with a particular attachment and subject
srch <- "filename:caseload subject:Rsend newer_than:2d"
msgs <- gm_messages(search = srch)
# I need to determine unequivocally which is the newest
# internalDate gives me:
gm_message(msgs[[c(1)]]$messages[[c(1)]]$id)$internalDate
[1] "1593856252000"
# if I presume it is Unix epoch:
as.POSIXct(as.numeric(gm_message(msgs[[c(1)]]$messages[[c(1)]]$id)$internalDate), origin="1970-01-01")
# I get:
[1] "52477-04-17 08:46:40 BST"
# which is due to the extra zeros at the end of `internalDate` -
# but since I do not know the format and function of `internalDate`
# I am not sure how to best deal with them.
Advice on how to best write a function that would give me the newest message out of all messages retrieved based on some search criteria would be much appreciated. Or a clarification on how to get the message date and how it relates to internalDate would answer this question as well.