title: Gmail API - Fetches incomplete Raw data for mails with attachments > 5MB
body: <p>The GMAIL API "<strong>Users.messages: get</strong>" doesn't fetches the complete raw data for the mails having more than 5MB attachments which in turn throws "<em>Unterminated string literal</em>" due to incomplete JSON.</p>
  
  <pre><code>function insertMessage(messageId) {
          var url = "https://www.googleapis.com/gmail/v1/users/me/messages/" + messageId + "?format=raw&amp;fields=raw";
          var headers = {
                  Authorization: 'Bearer ' + ScriptApp.getOAuthToken()
          }
          var params = {
                  method: "get",
                  contentType: "application/json",
                  headers: headers,
                  muteHttpExceptions: true
          }
          var response = UrlFetchApp.fetch(url, params);
          var rawMsg = JSON.parse(response)["raw"].toString().replace(/\-/g, '+').replace(/\_/g, '/');
  }
  </code></pre>
  
  <p>The above works perfectly for mails without attachments or with attachments which are below 5MB.</p>
  
  <p>If I change to the below line there won't be any error but the mail attachments in case of excel gets corrupted and in case of images some are not included.</p>
  
  <pre><code>var rawMsg = JSON.parse(response+'"}')["raw"].toString().replace(/\-/g, '+').replace(/\_/g, '/');
  </code></pre>
  
  <p>I have already raised issue in <a href="https://issuetracker.google.com/issues/67467848" rel="nofollow noreferrer">Google Issue Tracker</a>. Is there any alternate way to fetch raw data along with all attachments?</p>