mrnavaone

77

May 26th, 2020
68
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var SEARCH_QUERY = "label:astronomia is:unread";
  2.  
  3. function getEmails_(q) {
  4.     var emails = [];
  5.     var emailsdata = [];
  6.     var threads = GmailApp.search(q);
  7.     for (var i in threads) {
  8.         var msgs = threads[i].getMessages();
  9.         for (var j in msgs) {
  10.             emails.push([msgs[j].getBody().replace(/<.+?>/g, '\n')
  11.                 .replace(/^\s*\n/gm, '').replace(/^\s*/gm, '').replace(/\s*\n/gm, '\n')
  12.              
  13.             ]);
  14.            
  15.         }
  16.     }
  17.  
  18.     return emails;
  19. }
  20.  
  21.  
  22. function getEmailst_(p) {
  23.     var emailst = [];
  24.     var emailsdatat = [];
  25.     var threadst = GmailApp.search(p);
  26.     for (var it in threadst) {
  27.         var msgst = threadst[it].getMessages();
  28.         for (var jt in msgst) {
  29.             emailst.push([msgst[jt].getDate()
  30.                
  31.              
  32.             ]);
  33.            
  34.         }
  35.     }
  36.  
  37.     return emailst;
  38. }
  39.  
  40. function appendData_(sheet, array2d) {
  41.     sheet.getRange(sheet.getLastRow() + 2, 1, array2d.length, array2d[0].length).setValues(array2d);
  42.      sheet.getRange(1,1).setValue("TITULO");
  43.    
  44.    
  45.    
  46.    
  47.  
  48.    
  49. }
  50.  
  51. function appendDatae_(sheet, dates) {
  52.  
  53.     sheet.getRange(2, 2, dates.length, dates[0].length).setValues(dates);
  54.       sheet.getRange(1,2).setValue("FECHA");
  55.    
  56.    
  57. }
  58.  
  59. function saveEmails() {
  60.     var array2d = getEmails_(SEARCH_QUERY);
  61.     var dates = getEmailst_(SEARCH_QUERY);
  62.     if (array2d) {
  63.         appendData_(SpreadsheetApp.getActiveSheet(), array2d);
  64.     }
  65.     if (dates) {
  66.         appendDatae_(SpreadsheetApp.getActiveSheet(), dates);
  67.     }
  68. }
RAW Paste Data