Gmail will provide you with a single file with everything in it - which is probably more than you want and will be very slow and difficult to import. So, before you export your Gmail data, be sure to empty your trash and your spam folders try to delete as much email as you can (that you don't want).
Google has a wiki page on downloading your data. It directs you to login and then go to the Google Takeout page.
On this page, you can choose which data to download and what format to save it in. If you are not sure about the format, choose a zip file.
It may take a while for Google to send you the link (like a day or more).
Once they do, unzip the link and you should have a folder called Mail and inside that folder is a file called "All mail Including Spam and Trash.mbox".
If this file is more than 16MB (and it probably is), then you will need to split it up into smaller chunks before you can import it.
You can download a [http://www.hjsplit.org/ multi-platform file splitter] to do the trick. However, it won't be perfect - It can create a series of 15 MB files for you. But, it won't split the files at the right place. Each file should start with a line that has: From
(without a colon) followed by a space and then the name or address of the person sending the email. Note - this is different from lines that start with From:
.
So - you may need to manually adjust each file by adding the top portion of each file that preceeds the From line to the end of the previous file.
If you are on a unix-like machine, you can also try this command:
awk 'BEGIN{chunk=0} /^From /{msgs++;if(msgs==100){msgs=0;chunk++}}{print > "chunk_" chunk ".mbox"}' mbox
And lastly, if you find this tedious, please contact support and we can help you.
Once you have your 15 MB files ready, you can use this file to import your email via Roundcube.