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