Created
July 3, 2016 19:05
-
-
Save macleginn/dec6fbff1f51a8e95a0445674d703316 to your computer and use it in GitHub Desktop.
Put all the messages from a Gmail inbox satisfying a query into a Google document
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function collateMessages() { | |
var searchString = "YOURQUERYHERE"; | |
// A query can be anything that you can enter | |
// into the Gmail search field: | |
// "datageddon from:ivan@pochta.net filename:pdf" | |
// etc. | |
var doc = DocumentApp.create(searchString); | |
var threads = GmailApp.search(searchString); | |
for (var j = 0; j < threads.length; j++) { | |
var messages = threads[j].getMessages(); | |
for (var i = 0; i < messages.length; i++) { | |
var txt = messages[i].getPlainBody(); | |
doc.getBody().appendParagraph(txt); | |
doc.getBody().appendParagraph(""); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment