]>
git.wh0rd.org - home.git/blob - .config/mutt/list-mailboxes.py
3 """Produce a "sorted" list of maildir paths based on subdirs."""
5 from __future__
import print_function
19 def find_dirs(topdir
, ignored
):
20 """Walk the subdirs following the KDE layout."""
22 for d
in sorted(os
.listdir(topdir
)):
23 if d
in ('cur', 'new', 'tmp'):
26 fulld
= os
.path
.join(topdir
, d
)
27 if d
.startswith('.') or fulld
in ignored
:
29 if not os
.path
.islink(fulld
):
30 if os
.path
.isdir(os
.path
.join(fulld
, 'cur')):
32 subdir
= os
.path
.join(topdir
, '.%s.directory' % d
)
33 if subdir
not in ignored
and os
.path
.isdir(subdir
):
34 ret
.extend(find_dirs(subdir
, ignored
))
40 maildir
= os
.path
.expanduser('~/.mail/')
42 ignored
= set(os
.path
.join(maildir
, x
) for x
in IGNORED_DIRS
)
44 results
= find_dirs(maildir
, ignored
)
45 print(' '.join('"%s"' % x
for x
in results
))
49 # Old logic that doesn't sort right.
50 for root
, dirs
, _
in os
.walk(maildir
, followlinks
=False):
51 for d
in ('cur', 'new', 'tmp'):
59 fulld
= os
.path
.join(root
, d
)
62 elif not os
.path
.islink(fulld
):
63 if os
.path
.isdir(os
.path
.join(fulld
, 'cur')):
66 print('\n'.join('"%s"' % x
for x
in results
))
69 if __name__
== '__main__':
70 sys
.exit(main(sys
.argv
[1:]))