Will my emails be kept if I upgrade from 10.6.8 to 10.11?
The upgrade does keep all emails, but the new mail program will reprocess and reindex and move the actual files. 

IF there is corruption in the filed or database on your computer now, an upgrade is when things get worse, so be sure to back up your Mac before the upgrade. That way, no matter what happens with the script, you could wipe and go back to the way things were or investigate your follow on question of how to export or make the mails portable in general as opposed to trusting the upgrade does what is intended.