Created
March 15, 2013 03:15
-
-
Save patt0/5167237 to your computer and use it in GitHub Desktop.
This simple code snippet can be included in a Google Docs spreadsheet script editor to extract header information from email.
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 processInbox() { | |
sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); | |
// get all threads with the label draft > replave with the lable you need | |
searchString = "label:draft"; | |
var threads = GmailApp.search(searchString); | |
for (var i = 0; i < threads.length; i++) { | |
// get all messages in a given thread | |
var messages = threads[i].getMessages(); | |
// iterate over each message | |
for (var j = 0; j < messages.length; j++) { | |
var data = []; | |
data[0] = new Array(); | |
data[0][0] = messages[j].getFrom(); | |
data[0][1] = messages[j].getTo(); | |
data[0][2] = messages[j].getCc(); | |
data[0][3] = messages[j].getBcc(); | |
data[0][4] = messages[j].getSubject(); | |
data[0][5] = messages[j].getDate(); | |
var attachments = messages[j].getAttachments(); | |
// number of attachments | |
data[0][6] = attachments.length; | |
var attachmentList = "" | |
for (var k = 0; k < attachments.length; k++) { | |
attachmentList += attachments[k].getName() + ", "; | |
} | |
// name of attachments if any | |
data[0][7] = attachmentList; | |
// this link will allow you to open the mail thread from the spreadsheet to see the attachments. | |
data[0][8] = threads[i].getPermalink(); | |
// update spreasheet | |
sheet.getRange(sheet.getLastRow()+1, 1, 1, 9).setValues(data); | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment