title: Save attachment from Gmail to Google Drive AND give it another name
body: <p>I am using Amit Agarwal's fantastic <a href="http://www.labnol.org/internet/send-gmail-to-google-drive/21236/" rel="nofollow">script to extract attachments from Google Mail</a> and save them to Google Drive. It saves the attachment under its name and saves the Subject Line of the mail in the "Description" of the file (together with the Message ID).
  Instead, I would like to name the file whatever is written in the subject line of the email with the attachment.</p>
  
  <p>An example: The attachment is named abc.pdf, the subject line is "Invoice-February.pdf". As it is, the script would create a file in Google Drive called abc.pdf. Instead, I would like it to name the file "Invoice-February.pdf". </p>
  
  <p>This is the original code: </p>
  
  <pre><code> for (var x=0; x&lt;threads.length; x++) {
  
  var message = threads[x].getMessages()[0];    
  var desc   = message.getSubject() + " #" + message.getId();
  var att    = message.getAttachments();
  
  for (var z=0; z&lt;att.length; z++) {
    try {        
      if (check) {
        var name = att[z].getName();
        if (name.indexOf(".") != -1) {
          var extn = name.substr(name.lastIndexOf(".")+1).toLowerCase();
          if (valid.indexOf(extn) != -1) {
            file = folder.createFile(att[z]);
            file.setDescription(desc);
          } else {
            Logger.log("Skipping " + name);
          }
        }
      } else {
        file = folder.createFile(att[z]);
        file.setDescription(desc);
      }  
    }
  </code></pre>
  
  <p>The createFile function has no way to add a different name to a blog and I have not found a "renameFile". Does anyone know how to do that? </p>