Thanks for the clarification. If both email accounts are IMAP accounts, then all of your email messages for both accounts are on their respective email servers ... except for any messages that you downloaded locally to your Mac and placed into email folders.
I would second rccharles advice about exporting all of your mailboxes. Another option is to use a third-party app, like MailSteward to archive all of your email mailboxes. You can then access or restore them as needed and this would make for a good backup as well. In addition, Time Machine backs up your Mail app's mailboxes as well so you should make timely backups with it if you are not already doing so.