Gmailcc makes it possible to backup your Gmail account to a Maildir format usable by any standard IMAP-server.
It detects mails with multiple labels and will save only one copy of each, using a link for very duplicate. This achieves maximum space savings while still allowing an IMAP-server to find the mail with every label. Combine with Webmail software like Roundcube for optimum results.
Info on how to install and use it can be found on the project site.