-
-
Save Adeleye080/6bf232a9c77d201467d1836c84dc73de to your computer and use it in GitHub Desktop.
Revisions
-
benbjurstrom revised this gist
Apr 30, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ # PurgeOldEmails A [Google Apps Script](https://developers.google.com/apps-script/) script to automatically delete unarchived mail after 7 days that hasn't been starred or marked as important ## Quick Start -
benbjurstrom revised this gist
Apr 30, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,7 +8,7 @@ A [Google Apps Script](https://developers.google.com/apps-script/) script that d 2. Load this script into a new Google Apps Script [project](https://script.google.com/). 3. Execute the _setPurgeTrigger()_ function to set a trigger that will call the _purge()_ function every day. A detailed blog post with more information can be found at [https://benbjurstrom.com/purge-email](https://benbjurstrom.com/purge-email) ## Acknowledgements -
benbjurstrom revised this gist
Apr 27, 2020 . 1 changed file with 4 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -13,7 +13,8 @@ var DELETE_AFTER_DAYS = 7 var PAGE_SIZE = 150 /** * Create a trigger that executes the purge function every day. * Execute this function to install the script. */ function setPurgeTrigger() { ScriptApp @@ -34,7 +35,7 @@ function setPurgeMoreTrigger(){ } /** * Deletes all triggers that call the purgeMore function. */ function removePurgeMoreTriggers(){ var triggers = ScriptApp.getProjectTriggers() @@ -48,6 +49,7 @@ function removePurgeMoreTriggers(){ /** * Deletes all of the project's triggers * Execute this function to unintstall the script. */ function removeAllTriggers() { var triggers = ScriptApp.getProjectTriggers() -
benbjurstrom revised this gist
Apr 27, 2020 . 1 changed file with 8 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,11 @@ /* |-------------------------------------------------------------------------- | PurgeOldEmails |-------------------------------------------------------------------------- | https://gist.github.com/benbjurstrom/00cdfdb24e39c59c124e812d5effa39a | */ // Purge messages automatically after how many days? var DELETE_AFTER_DAYS = 7 -
benbjurstrom revised this gist
Dec 14, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -67,7 +67,7 @@ function purge() { var threads = GmailApp.search(search, 0, PAGE_SIZE) if (threads.length === PAGE_SIZE) { console.log('PAGE_SIZE exceeded. Setting a trigger to call the purgeMore function in 2 minutes.') setPurgeMoreTrigger() } -
benbjurstrom revised this gist
Dec 14, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,7 +6,7 @@ A [Google Apps Script](https://developers.google.com/apps-script/) script that d 1. Backup your emails using [Google Takeout](https://takeout.google.com/). 2. Load this script into a new Google Apps Script [project](https://script.google.com/). 3. Execute the _setPurgeTrigger()_ function to set a trigger that will call the _purge()_ function every day. A detailed blog post with more information can be found at [https://benbjurstrom.com/purge-old-emails](https://benbjurstrom.com/purge-old-emails) -
benbjurstrom revised this gist
Dec 14, 2019 . 1 changed file with 48 additions and 44 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,32 +1,55 @@ // Purge messages automatically after how many days? var DELETE_AFTER_DAYS = 7 // Maximum number of message threads to process per run. var PAGE_SIZE = 150 /** * Create a trigger that executes the purge function every day */ function setPurgeTrigger() { ScriptApp .newTrigger('purge') .timeBased() .everyDays(1) .create() } /** * Create a trigger that executes the purgeMore function two minutes from now */ function setPurgeMoreTrigger(){ ScriptApp.newTrigger('purgeMore') .timeBased() .at(new Date((new Date()).getTime() + 1000 * 60 * 2)) .create() } /** * Deletes all triggers that call the purgeMore function */ function removePurgeMoreTriggers(){ var triggers = ScriptApp.getProjectTriggers() for (var i = 0; i < triggers.length; i++) { var trigger = triggers[i] if(trigger.getHandlerFunction() === 'purgeMore'){ ScriptApp.deleteTrigger(trigger) } } } /** * Deletes all of the project's triggers */ function removeAllTriggers() { var triggers = ScriptApp.getProjectTriggers() for (var i = 0; i < triggers.length; i++) { ScriptApp.deleteTrigger(triggers[i]) } } /** * Wrapper for the purge function */ function purgeMore() { purge() @@ -38,47 +61,28 @@ function purgeMore() { * and not starred or marked as important. */ function purge() { removePurgeMoreTriggers() var search = 'in:inbox -in:starred -in:important older_than:' + DELETE_AFTER_DAYS + 'd' var threads = GmailApp.search(search, 0, PAGE_SIZE) if (threads.length === PAGE_SIZE) { console.log('Scheduling follow up job...') setPurgeMoreTrigger() } console.log('Processing ' + threads.length + ' threads...') var cutoff = new Date() cutoff.setDate(cutoff.getDate() - DELETE_AFTER_DAYS) // For each thread matching our search for (var i = 0; i < threads.length; i++) { var thread = threads[i] // Only delete if the newest message in the thread is older then DELETE_AFTER_DAYS if (thread.getLastMessageDate() < cutoff) { thread.moveToTrash(); } } } -
benbjurstrom revised this gist
Dec 14, 2019 . 1 changed file with 24 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -25,26 +25,43 @@ function removeTriggers() { } } /** * Wrapper for our purge function */ function purgeMore() { purge() } /** * Deletes any emails from the inbox that are more then 7 days old * and not starred or marked as important. */ function purge() { try { // Remove any existing triggers that call purgeMore to avoid trigger limit var triggers = ScriptApp.getProjectTriggers() for (var i = 0; i < triggers.length; i++) { var trigger = triggers[i] if(trigger.getHandlerFunction() === 'purgeMore'){ ScriptApp.deleteTrigger(trigger) } } var cutoff = new Date() cutoff.setDate(cutoff.getDate() - DELETE_AFTER_DAYS) var search = 'in:inbox -in:starred -in:important older_than:' + DELETE_AFTER_DAYS + 'd' var threads = GmailApp.search(search, 0, PAGE_SIZE) // If the number of threads is equal to our page size if (threads.length === PAGE_SIZE) { console.log('Scheduling follow up job...') // Set a trigger to call the purgeMore method in two minutes ScriptApp.newTrigger('purgeMore') .timeBased() .at(new Date((new Date()).getTime() + 1000 * 60 * 2)) .create() -
benbjurstrom revised this gist
Dec 14, 2019 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,6 +3,7 @@ A [Google Apps Script](https://developers.google.com/apps-script/) script that deletes all gmail messages from the inbox that are more than 7 days old and not starred or marked as important. ## Quick Start 1. Backup your emails using [Google Takeout](https://takeout.google.com/). 2. Load this script into a new Google Apps Script [project](https://script.google.com/). 3. Execute the _setTrigger()_ function to set a trigger that will call the _purge()_ function every day. @@ -11,4 +12,4 @@ A [Google Apps Script](https://developers.google.com/apps-script/) script that d ## Acknowledgements Thanks to [this gist](https://gist.github.com/jamesramsay/9298cf3f4ac584a3dc05) by jamesramsay for getting me started in the right direction. -
benbjurstrom revised this gist
Dec 14, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,7 @@ A [Google Apps Script](https://developers.google.com/apps-script/) script that d ## Quick Start 1. Backup your emails using [Google Takeout](https://takeout.google.com/). 2. Load this script into a new Google Apps Script [project](https://script.google.com/). 3. Execute the _setTrigger()_ function to set a trigger that will call the _purge()_ function every day. A detailed blog post with more information can be found at [https://benbjurstrom.com/purge-old-emails](https://benbjurstrom.com/purge-old-emails) -
benbjurstrom revised this gist
Dec 14, 2019 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,13 +1,13 @@ # PurgeOldEmails A [Google Apps Script](https://developers.google.com/apps-script/) script that deletes all gmail messages from the inbox that are more than 7 days old and not starred or marked as important. ## Quick Start 1. Backup your emails using [Google Takeout](https://takeout.google.com/). 2. Load this script into a new Google Apps Script [project](https://script.google.com/). 3. Execute the /setTrigger()/ function to set a trigger that will call the /purge()/ function every day. A detailed blog post with more information can be found at [https://benbjurstrom.com/purge-old-emails](https://benbjurstrom.com/purge-old-emails) ## Acknowledgements -
benbjurstrom revised this gist
Dec 14, 2019 . 1 changed file with 8 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,13 @@ # PurgeOldEmails A [Google Apps Script](https://developers.google.com/apps-script/) script that deletes all gmail messages from the inbox that are more then 7 days old and not starred or marked as important. ## Quick Start 1. Backup your emails using [Google Takeout](https://takeout.google.com/). 2. Load this script into a new Google Apps Script [project](https://script.google.com/). 3. Execute the /setTrigger()/ function to set a trigger that will call the /purge()/ function every day. A detailed blog post with more infomration can be foud at [https://benbjurstrom.com/purge-old-emails](https://benbjurstrom.com/purge-old-emails) ## Acknowledgements -
benbjurstrom revised this gist
Dec 13, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -34,7 +34,7 @@ function purge() { var cutoff = new Date() cutoff.setDate(cutoff.getDate() - DELETE_AFTER_DAYS) var search = 'in:inbox -in:starred -in:important older_than:' + DELETE_AFTER_DAYS + 'd' try { var threads = GmailApp.search(search, 0, PAGE_SIZE) -
benbjurstrom revised this gist
Dec 13, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ // Purge messages automatically after how many days? var DELETE_AFTER_DAYS = 7 // Maximum number of message threads to process per run -
benbjurstrom revised this gist
Dec 13, 2019 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,9 @@ // Purge messages in the above label automatically after how many days? var DELETE_AFTER_DAYS = 7 // Maximum number of message threads to process per run var PAGE_SIZE = 150 /** * Create a trigger that executes the purge function every day */ -
benbjurstrom revised this gist
Dec 13, 2019 . 1 changed file with 5 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,7 @@ # PurgeOldEmails This is a [Google Apps Script](https://script.google.com/) intended to delete all emails from the inbox that are more then 7 days old and not starred or marked as important. ## Acknowledgements Thanks to [this gist](https://gist.github.com/jamesramsay/9298cf3f4ac584a3dc05) by jamesramsay -
benbjurstrom revised this gist
Dec 13, 2019 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,3 @@ # PurgeOldEmails This is a [Google Apps Script](https://script.google.com/) intended to delete all emails from the inbox that are more then 7 days old and not starred or marked as important. -
benbjurstrom revised this gist
Dec 13, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ # PurgeOldEmails This is a google scripts application intended to delete all emails from the inbox that are more then 7 days old and not starred or marked as important. -
benbjurstrom revised this gist
Dec 13, 2019 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,4 @@ #PurgeOldEmails This is a google scripts application intended to delete all emails from the inbox that are more then 7 days old and not starred or marked as important. -
benbjurstrom created this gist
Dec 13, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,67 @@ // Maximum number of message threads to process per run var PAGE_SIZE = 150 // Purge messages in the above label automatically after how many days? var DELETE_AFTER_DAYS = 7 /** * Create a trigger that executes the purge function every day */ function setTrigger() { ScriptApp .newTrigger('purge') .timeBased() .everyDays(1) .create() } /** * Deletes all of the project's triggers */ function removeTriggers() { var triggers = ScriptApp.getProjectTriggers() for (var i = 0; i < triggers.length; i++) { ScriptApp.deleteTrigger(triggers[i]) } } /** * Deletes any emails from the inbox that are more then 7 days old * and not starred or marked as important. */ function purge() { var cutoff = new Date() cutoff.setDate(cutoff.getDate() - DELETE_AFTER_DAYS) var search = 'in:inbox -in:starred -in:important older_than:7d' try { var threads = GmailApp.search(search, 0, PAGE_SIZE) // If the number of threads is equal to our page size if (threads.length === PAGE_SIZE) { console.log('Scheduling follow up job...') // Re-trigger the purge method again after two minutes ScriptApp.newTrigger('purge') .timeBased() .at(new Date((new Date()).getTime() + 1000 * 60 * 2)) .create() } console.log('Processing ' + threads.length + ' threads...') // For each thread matching our search for (var i = 0; i < threads.length; i++) { var thread = threads[i] // Only delete if the newest message in the thread is older then DELETE_AFTER_DAYS if (thread.getLastMessageDate() < cutoff) { thread.moveToTrash(); } } } catch (e) { console.log(e) } }