jeffharbert

Gmail: Archive 'read' messages in Inbox older than 30 days

Feb 24th, 2013
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. ;This Google Apps Script for Gmail archives all 'read' messages in the Inbox
  2. ;that are older than 30 days
  3.  
  4. function checkRead() {
  5. var delayDays = 30 // Enter # of days before read messages are archived
  6. var maxDate = new Date();
  7. maxDate.setDate(maxDate.getDate()-delayDays);
  8. var threads = GmailApp.getInboxThreads();
  9. for ( var i = 0 ; i < threads.length; i++){
  10. var checkread = threads[i].isUnread();
  11. if (threads[i].getLastMessageDate()<maxDate){
  12. if ( checkread == false )
  13. {
  14. Logger.log(threads[i].getLastMessageDate());
  15. GmailApp.moveThreadToArchive(threads[i])
  16. }
  17. }
  18. }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment