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