doar.sh 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/bin/bash
  2. # doar - mail aggregation script based on mpop and msmtp
  3. # Written in 2014 by fr33domlover <fr33domlover@riseup.net>
  4. #
  5. # To the extent possible under law, the author(s) have dedicated all copyright
  6. # and related and neighboring rights to this software to the public domain
  7. # worldwide. This software is distributed without any warranty.
  8. #
  9. # You should have received a copy of the CC0 Public Domain Dedication along with
  10. # this software. If not, see
  11. # <http://creativecommons.org/publicdomain/zero/1.0/>.
  12. global_config_dir="/etc/doar"
  13. user_config_dir=".config/doar"
  14. mpop_config="mpoprc"
  15. #msmtp_config="msmtprc"
  16. account_defs="account_defs"
  17. account_list="account_list"
  18. temp_config=".generated_temp_config"
  19. defs="${user_config_dir}/${account_defs}"
  20. list="${user_config_dir}/${account_list}"
  21. mpoprc="${global_config_dir}/${mpop_config}"
  22. #msmtprc="${global_config_dir}/${msmtp_config}"
  23. mpoprc_full="${user_config_dir}/${temp_config}"
  24. users=`awk -F':' '{ if ( $3 >= 500 ) print $1 ":" $6 }' /etc/passwd`
  25. for user in $users
  26. do
  27. user_name="$(echo "$user" | sed s/^\\\([^:]\\+\\\):.*$/\\1/)"
  28. user_home="$(echo "$user" | sed s/^[^:]\\+://)"
  29. user_mpoprc="${user_home}/${defs}"
  30. user_list="${user_home}/${list}"
  31. final_mpoprc="${user_home}/${mpoprc_full}"
  32. if test -f "$user_mpoprc" && test -f "$user_list"
  33. then
  34. accounts="$(sed /^#/d "$user_list" | tr "\n" " ")"
  35. export DOAR_USER="$user_name"
  36. cat "$mpoprc" "$user_mpoprc" > "$final_mpoprc"
  37. chmod 400 "$final_mpoprc"
  38. mpop --file="$final_mpoprc" -- $accounts
  39. rm "$final_mpoprc"
  40. fi
  41. done