about summary refs log tree commit diff
path: root/Completion/User/_mailboxes
blob: 08dbec8163e28e8545a6b3f65fa6dcdc6d76f058 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#autoload

emulate -L zsh
setopt nullglob

# This is still needlessly mutt-biased and should be fixed.

local -U muttboxes mboxes dirboxes MHboxes maildirboxes
local i j expl muttrc="${muttrc:-~/.muttrc}"
local pinedirectory="${pinedirectory:-~/mail}"
local maildirectory="${maildirectory:-~/Mail}"

if (( ! $+_mailbox_cache )) then

[[ -f "${~muttrc}" ]] && muttboxes=( ${$(grep mailboxes ${~muttrc})[2,-1]} )

mboxes=( ${~maildirectory}/*(^/) ${~pinedirectory}/**/*(.) )
dirboxes=( ${~maildirectory}/*(/) )

while (( $#dirboxes ))
do 
    i=$dirboxes[1]
    shift dirboxes
    if [[ -d "$i/cur" ]]
    then
	maildirboxes=( $maildirboxes $i )
    elif j=( $i/<1-> ) && [[ -n "$j" ]]
    then
	MHboxes=( $MHboxes $i )
    else
	mboxes=( $mboxes $i/*(.) )
	dirboxes=( $dirboxes $i/*(/) )
    fi
done

[[ -n "$muttboxes" ]] &&
    _mailbox_cache=(\! \< \> $muttboxes)
_mailbox_cache=($_mailbox_cache $mboxes $maildirboxes $MHboxes)

fi

_description expl 'mailbox specification'
compadd "$@" "$expl[@]" - "$_mailbox_cache[@]"