My dotfiles. Period.

imapdomo 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/bin/bash
  2. . "$(shellfu-get path)" || exit 3
  3. shellfu import pretty
  4. usage() {
  5. mkusage "newmail" \
  6. "rewind" \
  7. "cleanup" \
  8. "migrate" \
  9. -- "newmail - check for and file new mail" \
  10. "rewind - re-add messages from FILTER_FAIL back" \
  11. " to FILTER_QUEUE" \
  12. "cleanup - delete or archive old messages" \
  13. "migrate - move mail between mailboxes"
  14. }
  15. mkcmd() {
  16. #
  17. # Compose imapfilter command
  18. #
  19. echo -n "IMAPDOMO_ACTION=$Action"
  20. echo -n " IMAPFILTER_HOME=$CfgDir"
  21. echo -n " imapfilter"
  22. if $Debug
  23. then
  24. mkdir -p "$LogDir"
  25. echo -n " -d $LogDir/debug.log"
  26. echo -n " -v"
  27. fi
  28. echo -n " -c $CfgDir/main.lua"
  29. }
  30. main() {
  31. local Action # what to do
  32. local Debug # true if debugging
  33. local cmd # imapfilter command
  34. local CfgDir # config directory
  35. local LogDir # directory to store logs
  36. local CdTo # change dir to this before running imapfilter
  37. CfgDir="$HOME/.imapdomo"
  38. LogDir="$HOME/.local/share/imapdomo/logs"
  39. Debug=false
  40. #shellcheck disable=SC2034
  41. while true; do case $1 in
  42. -c) CdTo="$2"; shift 2 || usage ;;
  43. -d) Debug=true; PRETTY_DEBUG=true; shift ;;
  44. -*) usage ;;
  45. *) break ;;
  46. esac done
  47. Action="$1"; shift
  48. grep -qw "$Action" <<< "newmail|rewind|cleanup|migrate" || usage
  49. cmd=$(mkcmd)
  50. debug -v cmd
  51. bash -n <<<"$cmd" || die
  52. if test -n "$CdTo";
  53. then
  54. cd "$CdTo" || die
  55. fi
  56. eval "$cmd"
  57. }
  58. main "$@"