My dotfiles. Period.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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/.cache/imapdomo/logs"
  39. Debug=false
  40. while true; do case $1 in
  41. -c) CdTo="$2"; shift 2 || usage ;;
  42. -d) Debug=true; PRETTY_DEBUG=true; shift ;;
  43. -*) usage ;;
  44. *) break ;;
  45. esac done
  46. Action="$1"; shift
  47. grep -qw "$Action" <<< "newmail|rewind|cleanup|migrate" || usage
  48. cmd=$(mkcmd)
  49. debug -v cmd
  50. bash -n <<<"$cmd" || die
  51. if test -n "$CdTo";
  52. then
  53. cd "$CdTo" || die
  54. fi
  55. eval "$cmd"
  56. }
  57. main "$@"