I'm building a script to automatically move my emails from one label to the next on a day by day basis (so that a message that is stored labelled "5 days" will automatically be labelled "4 days" tomorrow then "3 days" the day after that, and so on).
The problem is that it applies the label to the entire thread, not just the message - which is problematic if you have Conversation View turned off and the various emails seperated under different labels.
Here is my script (which has a daily trigger):
function moveUp(previousLabel, newLabel) {
var threads = GmailApp.getUserLabelByName(previousLabel).getThreads()
var numThreads = threads.length
if (numThreads>0) {
for(var i = 0; i < numThreads; i++) {
if(GmailApp.getUserLabelByName(previousLabel).getThreads().length>0) {
var lastThread = GmailApp.getUserLabelByName(previousLabel).getThreads()[0]
GmailApp.getUserLabelByName(newLabel).addToThread(lastThread.markUnread());
GmailApp.getUserLabelByName(previousLabel).removeFromThread(lastThread)
Utilities.sleep(200)
} else {
{break;}
}
}
}
}
function myFunction() {
var threads = GmailApp.getUserLabelByName("-To Do/1 Day").getThreads()
var numThreads = threads.length
if (numThreads>0) {
for(var i = 0; i < numThreads; i++) {
if(GmailApp.getUserLabelByName("-To Do/1 Day").getThreads().length>0) {
var lastThread = GmailApp.getUserLabelByName("-To Do/1 Day").getThreads()[0]
lastThread.moveToInbox().markUnread();
GmailApp.getUserLabelByName("-To Do/1 Day").removeFromThread(lastThread)
Utilities.sleep(200)
} else {
{break;}
}
}
}
moveUp("-To Do/2 Days", "-To Do/1 Day")
moveUp("-To Do/3 Days", "-To Do/2 Days")
moveUp("-To Do/4 Days", "-To Do/3 Days")
moveUp("-To Do/5 Days", "-To Do/4 Days")
}
So does anyone know how to only apply the labels to specific messages? Or a workaround to achieve that same result?
Thanks
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…