#!/bin/sh

# ALIASES=$(ksh -ic alias | grep ^mutt- | cut -d= -f1)
# 
# MAILBOX="imaps://mail.codevoid.de"
# 
# SEL=$(printf "$ALIASES" | $DMENU_CMD -p Mutt)
# 
# [ -z "$SEL" ] || texec $SEL

. $HOME/.bin/_config
# MAILBOXES=$(cd ~/.emails && find Mailboxes/*/ \
#             -mindepth 1 -maxdepth 1 -type d \
#                 -not -path "*/tmp*" \
#                 -not -path "*/cur*" \
#                 -not -path "*/new*")

MAILBOXES="$(print "t1 login sdk $(pass Internet/mail.codevoid.de | head -1)\nt1 list \"\" \"*\"\nt1 logout" \
    | openssl s_client -quiet -connect mail.codevoid.de:993 -crlf - 2>/dev/null \
    | grep "^\* LIST" | awk '{ print $NF }' | sort | dos2unix)"


HOST="imaps://mail.codevoid.de"

SEL=$(echo "$MAILBOXES" | $DMENU_CMD -l 12 -p Mailbox)

[ -z "$SEL" ] || texec "mutt -F $HOME/.mutt/rc-account-private -f $HOST/$SEL"
