Hello Im trying to setup EVERY-n-week events for gmail-snooze thus it would be reocurring events not just one time.
I would like to save everyXweek labeled-threads into "newpage" from the already created Xweek labeled-threads in "page" array. I used page = oldLabel.getThreads(0, 100); to grab the Xweek data.
I tried newpage = everyXweekLabel.page; and newpage = page[everyXweekLabel]; but newpage never gets turned into an array with threads.... so it doesnt work...
How i would like this to work:
- threads will have multiple labels.
XweekSnoozeis our iteration count down timing labeleveryXweekSnoozeis our static label to reset the thread once placed in inbox
An example would be thread#1 has 1weekSnooze left (which will be removed on the very next iteration) and it also has an every8weekSnooze label (which will need to apply an 8weekSnooze label once the email is put into inbox)
After the 8weekSnooze label is applied it then iterates (7weekSnooze, 6...) down until it is put into the inbox again where the every8weekSnooze label places another 8weekSnooze label back on to iterate through.
I can make this work for n-weeks but I cannot get the EVERY-n-week part to work since I cannot figure out how to pull everyXweek labels from previously pulled page-thread that contains Xweek labels and other labels as well.
Any help you can extend would be greatly appreciated for sure !
Thanks.
JP
function getLabelNameXWeekSnooze(i) {
return "Snooze/" + i + "weekSnooze";
}
function getLabelNameEveryXWeekSnooze(i) {
return "Snooze/" + "every" + i + "weekSnooze";
}
function moveWeekSnoozes() {
var oldLabel, newLabel, page;
for (var i = 1; i <= WEEKS_TRACKED; ++i) {
newLabel = oldLabel;
oldLabel = GmailApp.getUserLabelByName(getLabelNameXWeekSnooze(i));
page = null;
newpage = null;
// Get threads in "pages" of 100 at a time
while(!page || page.length == 100) {
page = oldLabel.getThreads(0, 100);
if (page.length > 0) {
if (newLabel) {
// Move the threads into "today’s" label
newLabel.addToThreads(page);
} else {
// Time to Unsnooze
GmailApp.moveThreadsToInbox(page);
if (MARK_UNREAD) {
GmailApp.markThreadsUnread(page);
}
// after returning mail to inbox please create an
// XweekSnooze label for every thread in page that has associated everyXweekSnooze label
// for example every3weekSnooze thread will need 3weekSnooze label to iterate/delay from
for (var j = 1; j <= WEEKS_TRACKED; ++j) {
// format the label data
everyXweekLabel = GmailApp.getUserLabelByName(getLabelNameEveryXWeekSnooze(j));
XweekLabel = GmailApp.getUserLabelByName(getLabelNameXWeekSnooze(j));
//trying to grab all thread from page that have everyXweek label and save to new page
newpage = everyXweekLabel.page;
if (newpage.length > 0) {
XweekLabel.addToThreads(newpage);
}
}
// Move the threads out of "yesterday’s" label
oldLabel.removeFromThreads(page);
}
}
}
}