The Extraction Script

One of my more recent projects is a new literary magazine. Part of the process is reading submissions. As a poet myself, I know a lot of poets. To mitigate this fact, I wanted to read the submitted poems blinded. Part of my solution was to set very strict submission guidelines. But as it turns out, e-mails have author information on them. So I wrote a little script to extract submissions from my inbox and put them into Google Drive, where I could read them without any of the e-mail information. I got some interest in the script, so I decided to post the code.

function downloadSubmissions() {
  // ‘Submissions’ is the name of the Gmail label
  // that is automatically applied to incoming submissions.
  // You can use any label here.
  // See also: API reference.
  var label = GmailApp.getUserLabelByName(‘Submissions’);
  var threads = label.getThreads();

  // Again, this is the name of the Drive folder
  // where I want to put documents. Change it to suit you.
  var folder = DocsList.getFolder(‘Submissions’);

  // Loop through all the threads in the label.
  for (var i = 0; i < threads.length; i++) {     var messages = threads[i].getMessages();     // If the most recent message is unread...     var currentMessage = messages[messages.length-1];     if (currentMessage.isUnread()) {       // ... move it's attachments to the folder.       var attachments = currentMessage.getAttachments();       for (var j = 0; j < attachments.length; j++) {         var file = DocsList.createFile(             attachments[j].copyBlob());         file.addToFolder(folder);       }     }     // Mark the message as read so that we don't     // process it twice.     currentMessage.markRead();   } };

This code is a Google Apps script. If you don’t know what that means, you can read a little more about it here. Otherwise, enjoy. Feel free to leave questions or comments.

Comments are closed.