From e19dc44524593a48c54479cc2f2081e94a375c94 Mon Sep 17 00:00:00 2001 From: xmailla Date: Sat, 4 Jan 2025 16:04:14 +0100 Subject: [PATCH] mailcheck: allow users to have variables in $MBLAZE/profile Fixes issue #1 by adding a new function to query option in the user profile. Thi version is both more robust and reliable when a user uses variables (like $HOME, $BLAZE or anything else) in his profile to specify path to commands or files. With this patch, user can now have this: MailCheckIndexCommand: mairix -f $MBLAZE/mairixrc It will be automatically transformed as: mairix -f /whatever/path/to/file/mairixrc at runtime. All the options are now using getmblazeopt to be filled. This commit is replacing 517694ba4f6137826218d9c1a3773ba669e77dde --- mailcheck | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/mailcheck b/mailcheck index 2767657..765b5ff 100755 --- a/mailcheck +++ b/mailcheck @@ -9,17 +9,6 @@ MBLAZE=${MBLAZE-$HOME/.mblaze} profile="$MBLAZE/profile" sleep=$1 -[ -z "$sleep" ] && sleep=$(mhdr -h MailCheckSleep $profile) -[ -z "$sleep" ] && sleep=30 -check_cmd=$(mhdr -h MailCheckCommand $profile) -[ -z "$check_cmd" ] && check_cmd="fdm -q fetch" -check_lockf=$(mhdr -h MailCheckLockFile $profile) -[ -z "$check_lockf" ] && check_lockf=$HOME/.fdm.lock -index_cmd=$(mhdr -h MailCheckIndexCommand $profile) -[ -z "$index_cmd" ] && index_cmd="mairix -p" -[ "$index_cmd" = "-" ] && index_cmd="" -date_fmt=$(mhdr -h MailCheckDateFmt $profile) -[ -z "$date_fmt" ] && date_fmt="%Y-%m-%d %H:%M" sleeper_pid=0 @@ -27,6 +16,31 @@ ts () { date +"$date_fmt" } +getmblazeopt () { + [[ -n $1 ]] && mhdr -h $1 $profile | envsubst && return 0 + return 1 +} + +check_cmd=$(getmblazeopt MailCheckCommand) +check_cmd=${check_cmd:-"fdm -q fetch"} + +sleep=${1:-$(getmblazeopt MailCheckSleep)} +sleep=${sleep:-30} + +check_lockf=$(getmblazeopt MailCheckLockFile) +check_lockf=${check_lockf:-"$HOME/.fdm.lock"} + +index_cmd=$(getmblazeopt MailCheckIndexCommand) +index_cmd=${index_cmd:--} +if [[ $index_cmd == "-" ]]; then + index_cmd="" +else + index_cmd=${index_cmd:-"mairix -p"} +fi + +date_fmt=$(getmblazeopt MailCheckDateFmt) +date_fmt=${date_fmt:-"%Y-%m-%d %H:%M"} + shleep () { sleep $1 >/dev/null 2>&1 & sleeper_pid=$! echo $(ts) sleeping ...