1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- #!/bin/bash
-
- . "$(shellfu-get path)" || exit 3
-
- shellfu import pretty
-
- SHELLFU_DEBUG=${SHELLFU_DEBUG:-true}
-
- usage() {
- mkusage "newmail" \
- "rewind" \
- "cleanup" \
- -- "newmail - check for and file new mail" \
- "rewind - re-add messages from FILTER_FAIL back" \
- " to FILTER_QUEUE" \
- "cleanup - delete or archive old messages"
- }
-
- mkcmd() {
- #
- # Compose imapfilter command
- #
- echo -n "IMAPDOMO_ACTION=$Action"
- echo -n " IMAPFILTER_HOME=$CfgDir"
- echo -n " imapfilter"
- if $Debug
- then
- mkdir -p "$LogDir"
- echo -n " -d $LogDir/debug.log"
- fi
- echo -n " -c $CfgDir/main.lua"
- }
-
- main() {
- local Action # what to do
- local Debug # true if debugging
- local cmd # imapfilter command
- local CfgDir # config directory
- local LogDir # config directory
- CfgDir="$HOME/.imapdomo"
- LogDir="$HOME/.cache/imapdomo/logs"
- Debug=false
- while true; do case $1 in
- -d) Debug=true; SHELLFU_DEBUG=true; shift ;;
- -*) usage ;;
- *) break ;;
- esac done
- Action="$1"; shift
- grep -qw "$Action" <<< "newmail|rewind|cleanup" || usage
- cmd=$(mkcmd)
- debug -v cmd
- bash -n <<<"$cmd" || die
- eval "$cmd"
- }
-
- main "$@"
|