Skip to content

Instantly share code, notes, and snippets.

@justinfarrelldev
Forked from anonymous/gmailAutoarchive.js
Last active July 23, 2020 09:48
Show Gist options
  • Save justinfarrelldev/fd5146db8e1a4c8d8b5756576f75471d to your computer and use it in GitHub Desktop.
Save justinfarrelldev/fd5146db8e1a4c8d8b5756576f75471d to your computer and use it in GitHub Desktop.

Revisions

  1. justinfarrelldev revised this gist Jul 23, 2020. 1 changed file with 4 additions and 7 deletions.
    11 changes: 4 additions & 7 deletions gmailAutoarchive.js
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,11 @@
    function gmailAutoarchive() {

    var delayDays = 2; // will only impact emails more than 48h old
    function GmailAutoarchive() {
    // No need for a label
    var delayDays = 21; // three weeks
    var maxDate = new Date();
    maxDate.setDate(maxDate.getDate()-delayDays); // what was the date at that time?

    // Get all the threads labelled 'autoarchive'
    var label = GmailApp.getUserLabelByName("autoarchive");
    var threads = label.getThreads(0, 400);
    var threads = GmailApp.search("in:inbox" + " older_than:" + delayDays.toString() + "d");

    // we archive all the threads if they're unread AND older than the limit we set in delayDays
    for (var i = 0; i < threads.length; i++) {
    if (threads[i].getLastMessageDate()<maxDate)
    {
  2. @invalid-email-address Anonymous created this gist Jan 8, 2017.
    18 changes: 18 additions & 0 deletions gmailAutoarchive.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    function gmailAutoarchive() {

    var delayDays = 2; // will only impact emails more than 48h old
    var maxDate = new Date();
    maxDate.setDate(maxDate.getDate()-delayDays); // what was the date at that time?

    // Get all the threads labelled 'autoarchive'
    var label = GmailApp.getUserLabelByName("autoarchive");
    var threads = label.getThreads(0, 400);

    // we archive all the threads if they're unread AND older than the limit we set in delayDays
    for (var i = 0; i < threads.length; i++) {
    if (threads[i].getLastMessageDate()<maxDate)
    {
    threads[i].moveToArchive();
    }
    }
    }