]>
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', | |
b0e7e909 MF |
14 | } |
15 | MAILDIR_DIRS = { | |
16 | 'cur', 'new', 'tmp', | |
17 | } | |
6bf5458d MF |
18 | |
19 | ||
20 | def find_dirs(topdir, ignored): | |
21 | """Walk the subdirs following the KDE layout.""" | |
b0e7e909 MF |
22 | for d in sorted(topdir.iterdir()): |
23 | if d.name in MAILDIR_DIRS: | |
6bf5458d MF |
24 | continue |
25 | ||
b0e7e909 | 26 | if d in ignored: |
6bf5458d | 27 | continue |
b0e7e909 MF |
28 | if not d.is_symlink(): |
29 | if (d / 'cur').is_dir(): | |
30 | yield d | |
31 | subdir = topdir / f'.{d.name}.directory' | |
32 | if subdir not in ignored and subdir.is_dir(): | |
33 | yield from find_dirs(subdir, ignored) | |
6bf5458d MF |
34 | |
35 | ||
36 | def main(argv): | |
b0e7e909 MF |
37 | maildir = Path('~/.mail/').expanduser() |
38 | ignored = {maildir / x for x in IGNORED_DIRS} | |
6bf5458d MF |
39 | |
40 | results = find_dirs(maildir, ignored) | |
b0e7e909 | 41 | print(' '.join(f'"{x}"' for x in results)) |
6bf5458d MF |
42 | return 0 |
43 | ||
44 | ||
6bf5458d MF |
45 | if __name__ == '__main__': |
46 | sys.exit(main(sys.argv[1:])) |