It basically allows new mail to be put to sleep until a more appropriate time. My implementation mirrors the calendrical file system advocated by Merlin Mann of 43 folders. Whereas any mail can be attached to 1 of 43 different time triggers. The first 31 signifying the days of the month, the remaining 12 for months of the year.
This actual script is a modification of the Gmail Snooze script written by Corey Goldfeder that I found referenced on LifeHacker.
var MARK_UNREAD = false;
var ADD_REACTIVATED_LABEL = true;
var DAYS_IN_MONTH = 31;
var THREADS_PER_PAGE = 100;
var BACKLOG_ITEM_TOTAL = 43;
var REACTIVATED = "Reactivated"
var BACKLOG = "Backlog";
var BUFFER = "Buffer";
var ENABLE_BUFFER = true;
var monthNames = [ "01-January", "02-February", "03-March", "04-April", "05-May", "06-June",
"07-July", "08-August", "09-September", "10-October", "11-November", "12-December" ];
function getLabelName(i) {
return BACKLOG + "/" + ((i <= DAYS_IN_MONTH) ? "Day/" + i : "Month/" + monthNames[i-DAYS_IN_MONTH-1]);
}
function setup() {
// Create the labels we'll need for backlogging
GmailApp.createLabel(BACKLOG);
GmailApp.createLabel(BACKLOG + "/Day");
GmailApp.createLabel(BACKLOG + "/Month");
for (var i = 1; i <= BACKLOG_ITEM_TOTAL; i++) {
GmailApp.createLabel(getLabelName(i));
}
if (ADD_REACTIVATED_LABEL) {GmailApp.createLabel(REACTIVATED)}
if (ENABLE_BUFFER) {GmailApp.createLabel(BUFFER)}
}
function reactivateBacklog() {
var day = new Date().getDate();
var label = GmailApp.getUserLabelByName(getLabelName(day));
reactivateLabel(label);
switch(day) {
//Check month label on first day
case 1:
var month = new Date().getMonth();
var monthLabel = GmailApp.getUserLabelByName(getLabelName(month + DAYS_IN_MONTH));
reactivateLabel(monthLabel);
break;
//Check for last day, if last, check for threads in remaining label to the 31st
case 28:
case 29:
case 30:
function isTodayTheLastDayOfTheMonth() {
var currentDate = new Date();
return currentDate.getDate() == new Date(currentDate.getFullYear(), currentDate.getMonth() + 1, 0).getDate();
}
if(isTodayTheLastDayOfTheMonth())
for(i=day;day <= DAYS_IN_MONTH;i++)
reactivateLabel(getLabelName(i));
break;
}
if (ENABLE_BUFFER) reactivateLabel(GmailApp.getUserLabelByName(BUFFER));
}
function reactivateLabel(label) {
var page = null;
while(!page || page.length == THREADS_PER_PAGE) {
page = label.getThreads(0, THREADS_PER_PAGE);
if (page.length > 0) {
// Unless it's time to reactivate it
GmailApp.moveThreadsToInbox(page);
if (MARK_UNREAD) {
GmailApp.markThreadsUnread(page);
}
if (ADD_REACTIVATED_LABEL) {
GmailApp.getUserLabelByName(REACTIVATED)
.addToThreads(page);
}
}
// Move the threads out of label
label.removeFromThreads(page);
}
}
Follow the same instructions listed below from Goldfeder's post on how to install Gmail Snooze to install Calendrify. With the exception of replacing "moveSnoozes" with "reactivateBacklog".
If you don't know how to setup a script, it's pretty simple. Create a new Google Spreadsheet, and choose "Script Editor" from the "Tools" menu. Paste in all of the code from above and then click the “Save” button and give it a name. In the dropdown labeled "Select a function to run," choose "setup" and click the blue run arrow to the left of it. This will ask you to authorize the script, and will create the necessary labels in your Gmail. Then go to the "Triggers" menu and choose "current script's triggers." Click the link to set up a new trigger, choosing the "moveSnoozes" function, a "time-driven" event, "day timer," and then "midnight to 1am." Click save and you are done.
No comments:
Post a Comment