Skip to content

Instantly share code, notes, and snippets.

@kcarnold
Created November 3, 2011 19:46
Show Gist options
  • Save kcarnold/1337583 to your computer and use it in GitHub Desktop.
Save kcarnold/1337583 to your computer and use it in GitHub Desktop.
Random restore-to-inbox
Google Apps Script is clunky. You have to make a spreadsheet in Google Docs, then Tools->Script Editor. Then you can paste this code in a new project. Try running it once to make sure it works, then under Triggers select moveRandomSnoozes, time-based, and whatever frequency you want. (I had it going daily, but just changed the probabilities and set it to hourly; we'll see how I like that.)
This was partly based on the Gmail Snooze script that was making the rounds a few months ago.
function setup() {
// Create the labels we’ll need for snoozing
GmailApp.createLabel("r1");
GmailApp.createLabel("r5");
}
function moveRandomSnoozes() {
_move('r1', 0.005);
_move('r5', 0.05);
}
function _move(labelName, frac) {
var label = GmailApp.getUserLabelByName(labelName);
var page = null, start=0;
while (true) {
var toMove = [];
page = label.getThreads(start, 100);
if (page.length == 0) break;
for (var i=0; i<page.length; i++) {
if (Math.random() < frac) {
toMove.push(page[i]);
}
}
GmailApp.moveThreadsToInbox(toMove);
label.removeFromThreads(toMove);
start = start + page.length - toMove.length;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment