function save_Gmail_as_PDF(){ var label = GmailApp.getUserLabelByName("Salva come PDF"); if(label == null){ GmailApp.createLabel('Salva come PDF'); } else{ var threads = label.getThreads(); for (var i = 0; i < threads.length; i++) { var messages = threads[i].getMessages(); var message = messages[0]; var body = message.getBody(); var subject = message.getSubject(); var attachments = message.getAttachments(); for(var j = 1;j0){ for(var k =0;k 0){ DocsList.createFolder(subject); var folder = DocsList.getFolder(subject); for (var j = 0; j < attachments.length; j++) { folder.createFile(attachments[j].getName(),attachments[j].getBytes()); } folder.createFile(bodydocpdf); } else{ DocsList.createFile(bodydocpdf); } DocsList.getFileById(bodyId).setTrashed(true); label.removeFromThread(threads[i]); } } }