Google Apps Script - Forward travel confirmations to TripIt for indexing
Tripit can be configured to automatically browse through all your email looking for travel information. Although I really like their product, I’m not really comfortable letting them dive into my personal email. So for some time I’ve been manually forwarding them all travel confirmations for indexing.
Some time ago a friend of mine told me about Google Apps Script. I have to say that I’m very, very impressed with what Google has pulled of here! From knowing nothing at all to having working code that automated my previously manual GMail workflow just took me an hour!
function processTripItQueue() {
var archiveLabel = GmailApp.getUserLabelByName("Personlig/Reise");
var queueLabel = GmailApp.getUserLabelByName("tripit-queue");
var threads = queueLabel.getThreads();
for (var i = 0; i < threads.length; i++) {
var tripThread = threads[i];
var messages = tripThread.getMessages();
for (var j = 0; j < messages.length; j++) {
var queuedMessage = messages[j];
Logger.log('Forwarding "%s" to plans@tripit.com', queuedMessage.getSubject());
queuedMessage.forward("plans@tripit.com");
}
queueLabel.removeFromThread(tripThread);
archiveLabel.addToThread(tripThread)
}
}
function onInstall() {
var everySixHours = ScriptApp.newTrigger('processTripItQueue')
.timeBased()
.everyHours(6)
.create();
}
Pretty cool!