I just wanted to synchronize all mails from the Google sent mail folder to the “Sent” folder of Dovecot and all mails from the Google “All Mails” view to a folder called “Archive” of the Dovecot account.
You need to make sure that you synchronize the “Sent” mails first as these are also included in the “All Mails” view and otherwise will not be added to the “Sent ” folder in addition.
This is the command I used for the migration:
--user1 <google mail user> --password1 <google mail user password> \
--host2 <dovecot hostname> \
--user2 <dovecot mail user> --password2 <dovecot mail user password> \
--exclude "\[Gmail\]$" \
--exclude "INBOX$" \
--folderlast "[Gmail]/Alle Nachrichten" \
--regextrans2 's#\[Gmail\]\.Gesendet$#Sent#' \
--regextrans2 's#\[Gmail\]\.Alle Nachrichten$#Archive#'
With the “–exclude” option you can specify which folders should not me synchronized. I excluded the Inbox as I just wanted to sync all mails to the “Archive” folder of my Dovecot account.
The “–folderlast” option makes sure that the “All Mails” folder of Google will be synchronized at the end, after all other folders have been synchronized.
With the “–regextrans2” options you can specify which source folder name should be synchronized to what target folder name. You need to adapt that in order to match your environment!
This is a real sync so you can have already mails in your target Dovecot account before which will not be deleted. And you can run this command several times and it will just only synchronize the mails which have changed on the Google mail account in the meantime.