Skip to content

Instantly share code, notes, and snippets.

@Aminadav
Created February 10, 2020 12:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Aminadav/de32bf41e79b79d1f626194b3b11ddfc to your computer and use it in GitHub Desktop.
Save Aminadav/de32bf41e79b79d1f626194b3b11ddfc to your computer and use it in GitHub Desktop.
auto archive
function AutoArchiveLabelOld() {
Logger.log('asdssss')
var AutoArchiveLabel=GmailApp.getUserLabelByName("Automation/AutoArchive")
Logger.log('asd')
Logger.log(AutoArchiveLabel)
var AutoArchivedLabel=GmailApp.getUserLabelByName("Automation/AutoArchived")
var threads=AutoArchiveLabel.getThreads()
for (var i=0;i<threads.length;i++){
var thread=threads[i]
Logger.log('a=' + thread.getLastMessageDate().valueOf())
Logger.log('b=' + new Date().setDate((new Date().getDate())-2))
if (thread.getLastMessageDate().valueOf() < new Date().setDate((new Date().getDate())-1)) {
Logger.log('To Archive')
thread.moveToArchive()
thread.addLabel(AutoArchivedLabel)
thread.removeLabel(AutoArchiveLabel)
// thread.moveToTrash()
} else {
Logger.log('To Not Archive')
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment