Guest User

Untitled

a guest
Apr 21st, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. /*
  2. Este script mantiene limpia mi bandeja de entrada, archivando correos antiguos
  3. */
  4. function gmailAutoArchive() {
  5. gmailAutoarchiveHelper("Informes",3);
  6. gmailAutoarchiveHelper("Sistemas",3);
  7. gmailAutoarchiveHelper("Diseños",3);
  8. gmailAutoarchiveHelper("inbox",7);
  9.  
  10. }
  11.  
  12. function gmailAutoarchiveHelper(queryStr, numDays) {
  13. Logger.log('Running archiver on label %s for numDays: %s',queryStr, numDays);
  14.  
  15. var query = "label:"+ queryStr + " AND label:inbox AND -is:starred AND older_than:" + numDays +"d";
  16. var threads = GmailApp.search(query,0, 250).filter(function(thread) {
  17. // Only return if the thread does not have any unread messages.
  18. return (!thread.isUnread());
  19. // return (thread.isInInbox() && !thread.isUnread() && !thread.isImportant());
  20. });
  21.  
  22. if(threads.length!=0){
  23. Logger.log('Found %s email threads belonging to %s to be archived', threads.length, queryStr);
  24. while (threads.length) {
  25. var this_batch_size = Math.min(threads.length, 250);
  26. var this_batch = threads.splice(0, this_batch_size);
  27. GmailApp.moveThreadsToArchive(this_batch);
  28. }
  29. }
  30. }
Add Comment
Please, Sign In to add comment