[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
nnmaildir nested Maildirs workaround
From: |
Thomas Schneider |
Subject: |
nnmaildir nested Maildirs workaround |
Date: |
Tue, 18 Sep 2018 17:25:13 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) |
Hello,
I wanted to use Gnus also for reading mails. For historical reasons, my
Maildirs are nested (e. g. ~/.maildir/work/INBOX/foo/bar/{cur,new,tmp})
and synced to various IMAP servers. I still wanted to keep the Maildirs
local, and keep my nested structure, but nnmaildir only supports a flat
hierarchy without leading dots (as mbsync would create them).
Long story short, I now have ~/.nnmaildir with a bunch of symlinks
created by the following script. It could be better, but for now this
does the trick.
---
#!/usr/bin/env python3
import os
import os.path
import sys
try:
maildir = os.environ['MAILDIR']
except KeyError:
if os.path.exists(os.path.expanduser('~/.maildir')):
maildir = os.path.expanduser('~/.maildir')
elif os.path.exists(os.path.expanduser('~/Maildir')):
maildir = os.path.expanduser('~/Maildir')
else:
print('no maildir found', file = sys.stderr)
sys.exit(1)
maildirs = {d for d, dirs, _ in os.walk(maildir)
if 'cur' in dirs} # cur shall be sufficient to make a dir a maildir
nnm = os.path.expanduser('~/.nnmaildir')
if not os.path.exists(nnm):
os.mkdir(nnm, mode = 0o700)
for d in maildirs:
n = d[len(maildir) + 1:].replace('/', '.')
dst = os.path.join(nnm, n)
if os.path.exists(dst):
continue
src_rel = os.path.relpath(d, os.path.dirname(dst))
os.symlink(src_rel, dst)
---
- nnmaildir nested Maildirs workaround,
Thomas Schneider <=