old_contents: import quickstart
  import base64
  import email
  from httplib2 import Http
  
  from apiclient import errors
  
  from apiclient.discovery import build
  
  
  def GetMessage(service, user_id, msg_id):
    """Get a Message with given ID.
  
    Args:
      service: Authorized Gmail API service instance.
      user_id: User's email address. The special value "me"
      can be used to indicate the authenticated user.
      msg_id: The ID of the Message required.
  
    Returns:
      A Message.
    """
    try:
      message = service.users().messages().get(userId=user_id, id=msg_id).execute()
  
      print 'Message snippet: %s' % message['snippet']
  
      return message
    except errors.HttpError, error:
      print 'An error occurred: %s' % error
  
  
  def GetMimeMessage(service, user_id, msg_id):
    """Get a Message and use it to create a MIME Message.
  
    Args:
      service: Authorized Gmail API service instance.
      user_id: User's email address. The special value "me"
      can be used to indicate the authenticated user.
      msg_id: The ID of the Message required.
  
    Returns:
      A MIME Message, consisting of data from Message.
    """
    try:
      message = service.users().messages().get(userId=user_id, id=msg_id,
                                               format='raw').execute()
  
      print 'Message snippet: %s' % message['snippet']
  
      msg_str = base64.urlsafe_b64decode(message['raw'].encode('ASCII'))
  
      mime_msg = email.message_from_string(msg_str)
  
      return mime_msg
    except errors.HttpError, error:
      print 'An error occurred: %s' % error
  
  
  def main():
      credentials = quickstart.get_credentials()
      service = build('gmail', 'v1', http=credentials.authorize(Http()))
  
      message = GetMimeMessage(service, 'me', '1572cb5cbb852f6d')
  
      print (message)
  
  
  if __name__ == '__main__':
      main()
  
new_contents: # Copyright (C) 2016 Google Inc.
  #
  # Licensed under the Apache License, Version 2.0 (the "License");
  # you may not use this file except in compliance with the License.
  # You may obtain a copy of the License at
  #
  #     http://www.apache.org/licenses/LICENSE-2.0
  #
  #     Unless required by applicable law or agreed to in writing, software
  #     distributed under the License is distributed on an "AS IS" BASIS,
  #     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  #     See the License for the specific language governing permissions and
  #     limitations under the License.
  
  import quickstart
  import base64
  import email
  from httplib2 import Http
  
  from apiclient import errors
  
  from apiclient.discovery import build
  
  
  def GetMessage(service, user_id, msg_id):
    """Get a Message with given ID.
  
    Args:
      service: Authorized Gmail API service instance.
      user_id: User's email address. The special value "me"
      can be used to indicate the authenticated user.
      msg_id: The ID of the Message required.
  
    Returns:
      A Message.
    """
    try:
      message = service.users().messages().get(userId=user_id, id=msg_id).execute()
  
      print 'Message snippet: %s' % message['snippet']
  
      return message
    except errors.HttpError, error:
      print 'An error occurred: %s' % error
  
  
  def GetMimeMessage(service, user_id, msg_id):
    """Get a Message and use it to create a MIME Message.
  
    Args:
      service: Authorized Gmail API service instance.
      user_id: User's email address. The special value "me"
      can be used to indicate the authenticated user.
      msg_id: The ID of the Message required.
  
    Returns:
      A MIME Message, consisting of data from Message.
    """
    try:
      message = service.users().messages().get(userId=user_id, id=msg_id,
                                               format='raw').execute()
  
      print 'Message snippet: %s' % message['snippet']
  
      msg_str = base64.urlsafe_b64decode(message['raw'].encode('ASCII'))
  
      mime_msg = email.message_from_string(msg_str)
  
      return mime_msg
    except errors.HttpError, error:
      print 'An error occurred: %s' % error
  
  
  def main():
      credentials = quickstart.get_credentials()
      service = build('gmail', 'v1', http=credentials.authorize(Http()))
  
      message = GetMimeMessage(service, 'me', '1572cb5cbb852f6d')
  
      print (message)
  
  
  if __name__ == '__main__':
      main()
  
subject: Add license