K-9 mail export (ideally to maildir/mbox)

Hi everyone,

I lost my mail server access… I’d like to save the few mails stored in K-9 for reference somewhere more accessible to me (ideally in maildir or mbox format). My phone is rooted, because I didn’t pay to just use it but to fully own it, which might help now. There are some files in a cache directory in /data/data/… :

attachment5400037824712087504.tmp 720828 2020-11-24 22:54:03
attachment7074676263537072439.tmp 711431 2020-11-24 22:53:57
body8357479725205177977.tmp 506293 2021-03-31 14:08:01
attachment3806664318984255608.tmp 302067 2020-11-27 10:05:04

The content is not in a human readable format:

Looking there I also found folders like the following
These folders seem to correlate with the mail accounts I have set up. Files in there are somewhat human readable (HTML representation of my received mails… yay). Unfortunately the mail headers are not in these files.

Does anyone know where to find the headers? And maybe corresponding attachments? And does anyone know the purpose/difference of .db .db-shm and .db-wal files also in this ‘databases’ folder?

Maybe this topic is relevant to other who lost access to their server and did out of various reasons not make a backup before or just miss an export for not only the settings but also only the mail? I would be very thankful for any help :pensive:

It’s non-trivial to reconstruct messages from the database dump and the message part files. If you now how to code you can start here: k-9/LocalFolder.java at 756ffc78564f051f34edc56b65784f393b72de1b · k9mail/k-9 · GitHub

Please also note that by default K-9 Mail only downloads small (see Settings > [Account] > Fetching mail > Fetch messages up to) messages in their entirety. For large messages only the text and/or HTML parts are downloaded. So there’s a good chance some of the messages are incomplete. As far as I know this is not something maildir/mbox is capable of handling. So you might have to do some additional work to make sure to build valid messages.