]>
Commit | Line | Data |
---|---|---|
318958d6 MF |
1 | #!/usr/bin/python |
2 | ||
3 | """Glue Maildir++/dovecot to kmail""" | |
4 | ||
5 | from __future__ import print_function | |
6 | ||
7 | import os | |
8 | import sys | |
9 | ||
10 | ||
11 | def main(argv): | |
12 | mail = os.path.expanduser('~/.mail') | |
13 | for root, dirs, files in os.walk(mail): | |
14 | try: | |
15 | dirs.remove('cur') | |
16 | dirs.remove('new') | |
17 | dirs.remove('tmp') | |
18 | except ValueError: | |
19 | pass | |
20 | ||
21 | if not root.endswith('.directory'): | |
22 | continue | |
23 | ||
24 | print(root, file=sys.stderr) | |
25 | for d in dirs: | |
26 | # We will start with: | |
27 | # root = ~/.mail/.gentoo.org.directory/ | |
28 | # d = buildroot | |
29 | # So create symlinks: | |
30 | # ~/.mail/gentoo.org/.buildroot -> ../.gentoo.org.directory/buildroot | |
31 | ||
32 | # ~/.mail/ | |
33 | parent = os.path.dirname(root) | |
34 | ||
35 | # .gentoo.org.directory | |
36 | maildir = os.path.basename(root) | |
37 | if maildir[0] == '.': | |
38 | continue | |
39 | # ../.gentoo.org.directory/buildroot | |
40 | target = os.path.join('..', maildir, d) | |
41 | # gentoo.org | |
42 | maildir = maildir[1:-10] | |
43 | # ~/.mail/gentoo.org/.buildroot | |
44 | source = os.path.join(parent, maildir, '.' + d) | |
45 | ||
46 | print('%s -> %s' % (source, target), file=sys.stderr) | |
47 | if not os.path.islink(source): | |
48 | os.symlink(target, source) | |
49 | ||
50 | fsdir = root[len(mail) + 1:] | |
51 | parts = fsdir.split('/') | |
52 | fsdir = '/'.join(parts[0:-1] + [parts[-1][1:-10]]) | |
53 | ns_parts = [x[1:-10] for x in parts] | |
54 | ns = '/'.join(ns_parts) | |
55 | ||
56 | extra = '' | |
57 | if ns == 'inbox': | |
58 | extra = '\n\tinbox = yes' | |
59 | ||
60 | print("""\ | |
61 | namespace "%(ns)s" {%(extra)s | |
62 | separator = / | |
63 | prefix = "%(ns)s/" | |
64 | location = "maildir:~/.mail/%(fsdir)s" | |
65 | } | |
66 | """ % {'ns': ns, 'fsdir': fsdir, 'extra': extra}) | |
67 | ||
68 | ||
69 | if __name__ == '__main__': | |
70 | sys.exit(main(sys.argv[1:])) |