Mail Importer for Gmail
Mail Importer for Gmail is an open source project from Google that uploads the contents of a Thunderbird mail archive to Gmail, doing its best to preserve the read state, flagged state, and folders of the messages. It is written in Java and uses Messages.import endpoint.
Clone the GitHub repository to get the full source code, or simply browse the Gmail-related code.