about summary refs log tree commit diff
path: root/Completion/User/_mailboxes
blob: 97628ef9a2eacd71f46c889447e5153fb46cccc7 (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
#autoload

#emulate -L zsh
setopt localoptions 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" || -d ~/.elm || -d ~/.mutt ]] &&
      _mailbox_cache=(\! \< \> $muttboxes)
  [[ -n "$mailpath" ]] &&
      _mailbox_cache=($_mailbox_cache ${mailpath//\?*/})

  _mailbox_cache=($_mailbox_cache $mboxes $maildirboxes $MHboxes)
fi

_wanted files expl 'mailbox specification' &&
    compadd "$@" "$expl[@]" - "$_mailbox_cache[@]"