Skip to content

Instantly share code, notes, and snippets.

@michaelgold
Last active August 29, 2015 14:24
Show Gist options
  • Save michaelgold/4e4fbc1a0006e6b06ddc to your computer and use it in GitHub Desktop.
Save michaelgold/4e4fbc1a0006e6b06ddc to your computer and use it in GitHub Desktop.
GMail Snoozes for Mailbox
var MARK_UNREAD = true;
var ADD_UNSNOOZED_LABEL = true;
function do_setup() {
GmailApp.createLabel("[Mailbox]");
GmailApp.createLabel("[Mailbox]/Later Today");
GmailApp.createLabel("[Mailbox]/This Weekend");
GmailApp.createLabel("[Mailbox]/Tomorrow");
GmailApp.createLabel("[Mailbox]/Next Week");
GmailApp.createLabel("[Mailbox]/Next Month");
GmailApp.createLabel("[Mailbox]/This Evening");
GmailApp.createLabel("[Mailbox]/Wednesday");
GmailApp.createLabel("!unsnoozed");
}
function do_move(glabel) {
var page = glabel.getThreads(0, 100);
if (page.length > 0) {
GmailApp.moveThreadsToInbox(page);
if (MARK_UNREAD) {
for (var i = 0 ; i < page.length; i++) {
var messages = GmailApp.getMessagesForThread(page[i]);
var lastMessageID = messages.length-1;
GmailApp.markMessageUnread(messages[lastMessageID]); // mark last message as unread
}
}
if (ADD_UNSNOOZED_LABEL) {
GmailApp.getUserLabelByName("!unsnoozed").addToThreads(page);
}
glabel.removeFromThreads(page);
}
}
function moveLaters() {
do_move(GmailApp.getUserLabelByName("[Mailbox]/Later Today"));
}
function moveWeekends() {
do_move(GmailApp.getUserLabelByName("[Mailbox]/This Weekend"));
}
function moveTomorrow() {
do_move(GmailApp.getUserLabelByName("[Mailbox]/Tomorrow"));
}
function moveNextWeek() {
do_move(GmailApp.getUserLabelByName("[Mailbox]/Next Week"));
}
function moveMonth() {
do_move(GmailApp.getUserLabelByName("[Mailbox]/Next Month"));
}
function moveEvenings() {
do_move(GmailApp.getUserLabelByName("[Mailbox]/This Evening"));
}
function moveWednesday() {
do_move(GmailApp.getUserLabelByName("[Mailbox]/Wednesday"));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment