GMail Scripting

Simple script to move emails in a tomorrow label.

function setUp() {
  GmailApp.createLabel("domani");
}


function daily() {
  var l = GmailApp.getUserLabelByName("domani");
  var threads = l.getThreads();
  GmailApp.moveThreadsToInbox(threads);
  GmailApp.markThreadsUnread(threads);
  l.removeFromThreads(threads);  
}


function hourly() {
  var l = GmailApp.getUserLabelByName("domani");
  var threads = l.getThreads();
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheets()[0];
  for (var i = 0; i < threads.length; ++i) {
    var t = threads[i];
    sheet.getRange(i + 1, 1).setValue(t.getFirstMessageSubject());
    sheet.getRange(i + 1, 2).setValue(t.getLastMessageDate());
  }
}


function tearDown() {
  daily();
  var l = GmailApp.getUserLabelByName("domani");
  GmailApp.deleteLabel(l);
}