]>
Commit | Line | Data |
---|---|---|
b0e7e909 | 1 | #!/usr/bin/python3 |
6bf5458d MF |
2 | |
3 | """Produce a "sorted" list of maildir paths based on subdirs.""" | |
4 | ||
5 | from __future__ import print_function | |
6 | ||
7 | import os | |
b0e7e909 | 8 | from pathlib import Path |
6bf5458d MF |
9 | import sys |
10 | ||
11 | ||
b0e7e909 | 12 | IGNORED_DIRS = { |
6bf5458d MF |
13 | 'drafts', |
14 | 'outbox', | |
15 | 'templates', | |
16 | '.inbox.directory', | |
b0e7e909 MF |
17 | } |
18 | MAILDIR_DIRS = { | |
19 | 'cur', 'new', 'tmp', | |
20 | } | |
6bf5458d MF |
21 | |
22 | ||
23 | def find_dirs(topdir, ignored): | |
24 | """Walk the subdirs following the KDE layout.""" | |
b0e7e909 MF |
25 | for d in sorted(topdir.iterdir()): |
26 | if d.name in MAILDIR_DIRS: | |
6bf5458d MF |
27 | continue |
28 | ||
b0e7e909 | 29 | if d in ignored: |
6bf5458d | 30 | continue |
b0e7e909 MF |
31 | if not d.is_symlink(): |
32 | if (d / 'cur').is_dir(): | |
33 | yield d | |
34 | subdir = topdir / f'.{d.name}.directory' | |
35 | if subdir not in ignored and subdir.is_dir(): | |
36 | yield from find_dirs(subdir, ignored) | |
6bf5458d MF |
37 | |
38 | ||
39 | def main(argv): | |
b0e7e909 MF |
40 | maildir = Path('~/.mail/').expanduser() |
41 | ignored = {maildir / x for x in IGNORED_DIRS} | |
6bf5458d MF |
42 | |
43 | results = find_dirs(maildir, ignored) | |
b0e7e909 | 44 | print(' '.join(f'"{x}"' for x in results)) |
6bf5458d MF |
45 | return 0 |
46 | ||
47 | ||
6bf5458d MF |
48 | if __name__ == '__main__': |
49 | sys.exit(main(sys.argv[1:])) |