title: decoding mail attachments in PHP from Google Mail API
body: <p>I am using the Google API Client Library for PHP in conjunction with the Gmail API to download and process some emails.</p>
  
  <p>I am getting the messages without any problems:</p>
  
  <pre><code>$optParamsGet = [];
  $optParamsGet['format'] = 'full'; // Display message in payload
  $message = $service-&gt;users_messages-&gt;get('me',$id,$optParamsGet);
  $messagePayload = $message-&gt;getPayload();
  </code></pre>
  
  <p>Then I process getParts() array and come to the first attachment, which is a .eml file with no name</p>
  
  <pre><code>    [modelData:protected] =&gt; Array
          (
              [headers] =&gt; Array
                  (
                      [0] =&gt; Array
                          (
                              [name] =&gt; Content-Type
                              [value] =&gt; message/rfc822
                          )
                      [1] =&gt; Array
                          (
                              [name] =&gt; Content-Disposition
                              [value] =&gt; attachment; creation-date="Fri, 24 Jul 2015 00:20:48 GMT"; modification-date="Fri, 24 Jul 2015 00:20:48 GMT"
                          )
                  )
              [body] =&gt; Array
                  (
                      [attachmentId] =&gt; ANGjdJ_TfJlMTssCNackUcQfT...mpppKiT8sSg
                      [size] =&gt; 37099
                  )
          )
  </code></pre>
  
  <p>My question is: How do I unencode the "attachmentId" string?
  I thought it was a base64 encoding, but the command</p>
  
  <pre><code>echo base64_decode($parts[1]-&gt;body-&gt;attachmentId);
  </code></pre>
  
  <p>Just spits out binary data.</p>
  
  <p>What did I miss?</p>