After using about half a dozen different email clients I don't trust <i>any</i> of them to keep my messages safe indefinitely. I would much rather have several copies of every email all over the globe in a system which is fast and easy to sync, search, and reorganize, and which has easy recovery of deleted files: A self-hosted Git repository.<p>A quick search didn't come up with any obvious candidates. There seems to be some projects out there for saving IMAP contents to various file formats, but none of the ones I found seem to have a big community, and I've no idea which file formats would be easily amenable to version control. Also, should I save the attachments embedded in the emails or as separate files (better version control and smaller email files, but breaks the explicit connection to the email file, and makes relocating them harder)? Finally, is there any reason why this is a terrible idea altogether, and I should just accept that personal messages from many years ago are just going to randomly disappear at some point?
How does your IMAP implmentation store the emails?<p>If it's maildir format (it is for me on Postfix + Dovecot) you can just rsync the maildirs for users you care about, it also contains the IMAP folders and the original RFC822 emails.
While I don't know of any imap to git sync tool specifically, there are tons of tools for storing email locally in plain text and for keeping these local email stores in sync with imap servers. The most common local email store formats seem to be mbox[1] and maildir[2]. Mbox stores one "folder" of emails per file, while maildir stores one email per file, which does seem to be the more modern approach (exceeding your file quota does not seem to be a particularly urgent problem anymore).<p>I personally use mbsync[3] to pull my email into a local maildir. I also use notmuch[4] and a nice tui[5] to search, read and write it. Note that filenames in maildir are unique, but provide little value beyond that. Some emails are also encoded in ways that will hide content from grep and friends (base64 being among the most popular ones). This makes notmuch especially valuable, as it abstracts all those encoding issues away and provides an amazing search interface.<p>I do not use a git repository for email myself, yet since a maildir is just a directory tree of plain text files, storing it in a repo is a no-brainer:<p><pre><code> mbsync -a # Configured via dotfiles
cd my_local_maildir
git add .
git commit
</code></pre>
[1]: <a href="https://en.wikipedia.org/wiki/Mbox" rel="nofollow">https://en.wikipedia.org/wiki/Mbox</a><p>[2]: <a href="https://en.wikipedia.org/wiki/Maildir" rel="nofollow">https://en.wikipedia.org/wiki/Maildir</a><p>[3]: <a href="https://isync.sourceforge.io/" rel="nofollow">https://isync.sourceforge.io/</a><p>[4]: <a href="https://notmuchmail.org/" rel="nofollow">https://notmuchmail.org/</a><p>[5]: <a href="https://github.com/wangp/bower" rel="nofollow">https://github.com/wangp/bower</a>