Advertisement
Guest User

Untitled

a guest
Jan 2nd, 2015
416
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. function processDocument(Subject, Contents, Attachments){
  2. var folders = DriveApp.getFoldersByName("WebAppDocuments");
  3. while (folders.hasNext()) {
  4. var folder = folders.next();
  5. doc = DocumentApp.create(Subject);
  6. doc.appendParagraph(Contents);
  7. doc.appendParagraph("Attachments:")
  8. for(a = 0; a < Attachments.length; a++){
  9. try{
  10. doc.appendParagraph(Attachments[a].getAs(File));
  11. }catch(e){
  12. Logger.log(e);
  13. }
  14. }
  15. //doc.saveAndClose();
  16. var file_doc = DriveApp.getFileById(doc.getId());
  17. folder.addFile(file_doc);
  18. DriveApp.removeFile(file_doc);
  19. Logger.log("Saved file \"" + file_doc.getName() + "\" to " + folder.getName());
  20. }
  21. }
  22.  
  23. function checkForEmails(){
  24. var found = false;
  25.  
  26. var threads = GmailApp.search("has:attachment label:Drive");
  27.  
  28. for (c = 0; c < threads.length; c++){
  29. var mails = threads[c].getMessages();
  30. for(i = 0; i < mails.length; i++){
  31. var attachments = mails[i].getAttachments();
  32. var subject = mails[i].getSubject();
  33. var contents = mails[i].getPlainBody();
  34. processDocument(subject, contents, attachments);
  35. }
  36. }
  37.  
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement