Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function processDocument(Subject, Contents, Attachments){
- var folders = DriveApp.getFoldersByName("WebAppDocuments");
- while (folders.hasNext()) {
- var folder = folders.next();
- doc = DocumentApp.create(Subject);
- doc.appendParagraph(Contents);
- doc.appendParagraph("Attachments:")
- for(a = 0; a < Attachments.length; a++){
- try{
- doc.appendParagraph(Attachments[a].getAs(File));
- }catch(e){
- Logger.log(e);
- }
- }
- //doc.saveAndClose();
- var file_doc = DriveApp.getFileById(doc.getId());
- folder.addFile(file_doc);
- DriveApp.removeFile(file_doc);
- Logger.log("Saved file \"" + file_doc.getName() + "\" to " + folder.getName());
- }
- }
- function checkForEmails(){
- var found = false;
- var threads = GmailApp.search("has:attachment label:Drive");
- for (c = 0; c < threads.length; c++){
- var mails = threads[c].getMessages();
- for(i = 0; i < mails.length; i++){
- var attachments = mails[i].getAttachments();
- var subject = mails[i].getSubject();
- var contents = mails[i].getPlainBody();
- processDocument(subject, contents, attachments);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement