executable_mail 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. #!/usr/bin/env bash
  2. set -eu
  3. set -o pipefail
  4. help_main()
  5. {
  6. echo "\
  7. Usage: mail COMMANDS ARGS...
  8. Run COMMANDS with ARGS
  9. COMMAND must be one of the sub-commands listed below:
  10. inbox
  11. neomutt
  12. pull
  13. Report bugs to: go.wigust@gmail.com."
  14. }
  15. help_neomutt()
  16. {
  17. echo "\
  18. Usage: mail neomutt [OPTION] MAIL_ADDRESS...
  19. Run neomutt with MAIL_ADDRESS configuration.
  20. -A list available mail addresses
  21. -h, --help display this help and exit
  22. Report bugs to: go.wigust@gmail.com."
  23. }
  24. help_inbox()
  25. {
  26. echo "\
  27. Usage: mail inbox [OPTION] MAIL_ADDRESS...
  28. Run curl with MAIL_ADDRESS configuration.
  29. -A list available mail addresses
  30. -h, --help display this help and exit
  31. Report bugs to: go.wigust@gmail.com."
  32. }
  33. mail_addresses=(pyhalov@majordomo.ru
  34. asfjsdf@mail.ru
  35. rxaetbed@mail.ru
  36. houdinihar@yandex.ru
  37. jenkins@majordomo.ru
  38. i18n.wugi@yandex.ru
  39. zabbix.guix@yandex.ru
  40. localhost)
  41. case "$1" in
  42. pull)
  43. mbsync -a
  44. notmuch new
  45. ;;
  46. --help)
  47. help_main
  48. ;;
  49. inbox)
  50. case "$2" in
  51. pyhalov@majordomo.ru)
  52. exec -a "$0" curl \
  53. --silent \
  54. --request "EXAMINE ${3:-INBOX}" \
  55. --user "pyhalov@majordomo.ru:$(pass show majordomo/private/newmail.majordomo.ru/pyhalov@majordomo.ru)" \
  56. imaps://imap.majordomo.ru:993
  57. ;;
  58. asfjsdf@mail.ru)
  59. exec -a "$0" curl \
  60. --silent \
  61. --request "EXAMINE ${3:-INBOX}" \
  62. --user "asfjsdf@mail.ru:$(pass show mail.ru/asfjsdf)" \
  63. imaps://imap.mail.ru:993
  64. ;;
  65. rxaetbed@mail.ru)
  66. exec -a "$0" curl \
  67. --silent \
  68. --request "EXAMINE ${3:-INBOX}" \
  69. --user "rxaetbed@mail.ru:$(pass show mail.ru/rxaetbed@mail.ru)" \
  70. imaps://imap.mail.ru:993
  71. ;;
  72. houdinihar@yandex.ru)
  73. exec -a "$0" curl \
  74. --silent \
  75. --request "EXAMINE ${3:-INBOX}" \
  76. --user "houdinihar:$(pass show email/yandex.ru/houdinihar)" \
  77. imaps://imap.yandex.ru:993
  78. ;;
  79. jenkins@majordomo.ru)
  80. exec -a "$0" curl \
  81. --silent \
  82. --request "EXAMINE ${3:-INBOX}" \
  83. --user "jenkins@majordomo.ru:$(pass show majordomo/public/jenkins.intr/admin)" \
  84. imaps://imap.majordomo.ru:993
  85. ;;
  86. i18n.wugi@yandex.ru)
  87. exec -a "$0" curl \
  88. --silent \
  89. --request "EXAMINE ${3:-INBOX}" \
  90. --user "i18n.wugi:$(pass show email/yandex.ru/i18n.wugi)" \
  91. imaps://imap.yandex.ru:993
  92. ;;
  93. zabbix.guix@yandex.ru)
  94. exec -a "$0" curl \
  95. --silent \
  96. --request "EXAMINE ${3:-INBOX}" \
  97. --user "zabbix.guix:$(pass show email/yandex.ru/zabbix.guix)" \
  98. imaps://imap.yandex.ru:993
  99. ;;
  100. localhost)
  101. exec -a "$0" curl \
  102. --silent \
  103. --request "EXAMINE ${3:-INBOX}" \
  104. --user "oleg:$(pass localhost/imap/oleg)" \
  105. imap://localhost
  106. ;;
  107. -A)
  108. printf "%s\n" "${mail_addresses[@]}"
  109. ;;
  110. ll)
  111. mail inbox -A | while IFS= read -r address
  112. do
  113. echo "$address"
  114. mail inbox "$address"
  115. done
  116. ;;
  117. *)
  118. help_inbox
  119. ;;
  120. esac
  121. ;;
  122. neomutt)
  123. case "$2" in
  124. pyhalov@majordomo.ru)
  125. exec -a "$0" neomutt -F "$HOME/.muttrc_pyhalov_majordomo"
  126. ;;
  127. asfjsdf@mail.ru)
  128. exec -a "$0" neomutt -F "$HOME/.muttrc_asfjsdf_mail"
  129. ;;
  130. rxaetbed@mail.ru)
  131. exec -a "$0" neomutt -F "$HOME/.muttrc_rxaetbed_mail"
  132. ;;
  133. houdinihar@yandex.ru)
  134. exec -a "$0" neomutt -F "$HOME/.muttrc_houdinihar_yandex"
  135. ;;
  136. jenkins@majordomo.ru)
  137. exec -a "$0" neomutt -F "$HOME/.muttrc_jenkins_majordomo"
  138. ;;
  139. i18n.wugi@yandex.ru)
  140. exec -a "$0" neomutt -F "$HOME/.muttrc_i18n.wugi_yandex"
  141. ;;
  142. zabbix.guix@yandex.ru)
  143. exec -a "$0" neomutt -F "$HOME/.muttrc_zabbix.guix_yandex"
  144. ;;
  145. localhost)
  146. exec -a "$0" neomutt -F "$HOME/.muttrc_localhost"
  147. ;;
  148. -A)
  149. printf "%s\n" "${mail_addresses[@]}"
  150. ;;
  151. *)
  152. help_neomutt
  153. ;;
  154. esac
  155. ;;
  156. *)
  157. help_main
  158. ;;
  159. esac