12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- #!/bin/bash
-
- . "$(shellfu-get path)" || exit 3
-
- shellfu import pretty
-
- usage() {
- mkusage "newmail" \
- "rewind" \
- "cleanup" \
- "migrate" \
- -- "newmail - check for and file new mail" \
- "rewind - re-add messages from FILTER_FAIL back" \
- " to FILTER_QUEUE" \
- "cleanup - delete or archive old messages" \
- "migrate - move mail between mailboxes"
- }
-
- 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"
- echo -n " -v"
- 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 # directory to store logs
- local CdTo # change dir to this before running imapfilter
- CfgDir="$HOME/.imapdomo"
- LogDir="$HOME/.local/share/imapdomo/logs"
- Debug=false
- #shellcheck disable=SC2034
- while true; do case $1 in
- -c) CdTo="$2"; shift 2 || usage ;;
- -d) Debug=true; PRETTY_DEBUG=true; shift ;;
- -*) usage ;;
- *) break ;;
- esac done
- Action="$1"; shift
- grep -qw "$Action" <<< "newmail|rewind|cleanup|migrate" || usage
- cmd=$(mkcmd)
- debug -v cmd
- bash -n <<<"$cmd" || die
- if test -n "$CdTo";
- then
- cd "$CdTo" || die
- fi
- eval "$cmd"
- }
-
- main "$@"
|