mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-10-13 11:21:13 +02:00
136 lines
3.9 KiB
Text
136 lines
3.9 KiB
Text
#autoload
|
|
|
|
#emulate -L zsh
|
|
setopt localoptions nullglob
|
|
|
|
# This is still needlessly mutt-biased and should be fixed.
|
|
|
|
local -U dirboxes
|
|
local i j expl muttrc="${muttrc:-~/.muttrc}" files nm="$compstate[nmatches]"
|
|
local pinedirectory="${pinedirectory:-~/mail}"
|
|
local maildirectory="${maildirectory:-~/Mail}"
|
|
|
|
if (( ! $+_mailbox_cache )) then
|
|
|
|
typeset -U -g _mailbox_cache
|
|
typeset -U -g _maildir_cache _mbox_cache _mh_cache _mutt_cache _pine_cache
|
|
|
|
_mailbox_cache=()
|
|
_mbox_cache=()
|
|
_maildir_cache=()
|
|
_mh_cache=()
|
|
_mutt_cache=()
|
|
_pine_cache=()
|
|
|
|
[[ -f ${~muttrc:-.} ]] &&
|
|
_mutt_cache=( ${$(grep mailboxes ${~muttrc})[2,-1]} )
|
|
|
|
_mbox_cache=( ${~maildirectory}/*(^/) )
|
|
_pine_cache=( ${~pinedirectory}/**/*(.) )
|
|
|
|
dirboxes=( ${~maildirectory}/*(/) )
|
|
|
|
while (( $#dirboxes )); do
|
|
i=${dirboxes[1]}
|
|
shift dirboxes
|
|
if [[ -d "$i/cur" ]]; then
|
|
_maildir_cache=( "${_maildir_cache[@]}" "$i" )
|
|
elif j=( $i/<1-> ) && [[ -n "$j" ]]; then
|
|
_mh_cache=( "${_mh_cache[@]}" "$i" )
|
|
else
|
|
_mbox_cache=( "${_mbox_cache[@]}" "$i"/*(.) )
|
|
dirboxes=( $dirboxes $i/*(/) )
|
|
fi
|
|
done
|
|
|
|
[[ -n "$_mutt_cache" || -d ~/.elm || -d ~/.mutt ]] &&
|
|
_mailbox_cache=( \! \< \> )
|
|
[[ -n "$mailpath" ]] &&
|
|
_mailbox_cache=( "${_mailbox_cache[@]}" "${(@)mailpath%%\?*}" )
|
|
|
|
[[ -n "$MAIL" ]] && _mailbox_cache=( "${_mailbox_cache[@]}" $MAIL )
|
|
fi
|
|
|
|
# Files for pine must be absolute paths.
|
|
|
|
if [[ "$PREFIX" != (|-f)+* &&
|
|
( "${curcontext}" = *:(mail|mush|zmail|zmlite):* ||
|
|
( "${curcontext}" = *:pine:* && "$PREFIX" = (|-f)[/\~]* ) ) ]]; then
|
|
_tags mailboxes files
|
|
else
|
|
_tags mailboxes
|
|
fi
|
|
|
|
while _tags; do
|
|
if _requested mailboxes expl 'mailbox specification'; then
|
|
local mbox_short
|
|
local -U mbox_names
|
|
|
|
mbox_short=()
|
|
mbox_names=()
|
|
|
|
case "${curcontext}" in
|
|
(*:elm:*) # I've probably got this wrong, or at least incomplete
|
|
mbox_names=( "${_mbox_cache[@]}" "${_mailbox_cache[@]}" )
|
|
mbox_short=( \! \< \> )
|
|
;;
|
|
(*:mail:*)
|
|
if compset -P '+|-f+'; then
|
|
mbox_names=( "${(@)_mbox_cache#$~maildirectory/}" )
|
|
else
|
|
mbox_names=( +"${(@)^_mbox_cache#$~maildirectory/}"
|
|
"${_mailbox_cache[@]}" )
|
|
fi
|
|
;;
|
|
(*:mh:*) # I've probably got this wrong, or at least incomplete
|
|
(( $#_mh_cache )) && _multi_parts "${expl[@]}" / _mh_cache
|
|
;;
|
|
(*:mush:*)
|
|
if compset -P '+|-f+'; then
|
|
mbox_names=( "${(@)_mbox_cache#$~maildirectory/}" )
|
|
else
|
|
mbox_names=( +"${(@)^_mbox_cache#$~maildirectory/}"
|
|
"${_mailbox_cache[@]}" )
|
|
mbox_short=( % \& )
|
|
fi
|
|
;;
|
|
(*:mutt:*)
|
|
mbox_names=( "${_mutt_cache[@]}" "${_mailbox_cache[@]}"
|
|
"${_maildir_cache[@]}" )
|
|
mbox_short=( \! \< \> );;
|
|
(*:pine:*)
|
|
# Pine is like mail but with no leading `+' to disambiguate;
|
|
# any files not in $pinedirectory must be absolute paths.
|
|
mbox_names=( "${(@)_pine_cache#$~pinedirectory/}" "${_mbox_cache[@]}"
|
|
"${_mailbox_cache[@]}" "${_mh_cache[@]}" )
|
|
;;
|
|
(*:tkrat:*) # Has a couple of custom formats I haven't programmed for.
|
|
mbox_names=( "${_mbox_cache[@]}"
|
|
"${_mailbox_cache[@]}" "${_mh_cache[@]}" )
|
|
;;
|
|
(*:(zmail|zmlite):*)
|
|
if compset -P '+|-f+'; then
|
|
mbox_names=( "${(@)_mbox_cache#$~maildirectory/}" )
|
|
else
|
|
mbox_names=( +"${(@)^_mbox_cache#$~maildirectory/}"
|
|
"${_mailbox_cache[@]}" "${_mh_cache[@]}" )
|
|
mbox_short=( % \& )
|
|
fi
|
|
;;
|
|
(*) # Some other program wants mailbox names? Use them all?
|
|
mbox_names=( "${_mailbox_cache[@]}" "${_mbox_cache[@]}"
|
|
"${_mh_cache[@]}" "${_mutt_cache[@]}" "${_pine_cache[@]}" )
|
|
;;
|
|
esac
|
|
|
|
(( $#mbox_names )) && _multi_parts "${expl[@]}" / mbox_names
|
|
(( $#mbox_short )) && compadd "$expl[@]" - "$mbox_short[@]"
|
|
fi
|
|
if _requested files expl 'mailbox file'; then
|
|
compset -P -f
|
|
_path_files "$expl[@]"
|
|
fi
|
|
[[ nm -ne $compstate[nmatches] ]] && return 0
|
|
done
|
|
|
|
return 1
|