executable_mail 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. oleg@wugi.info
  41. oleg-windows@wugi.info
  42. localhost)
  43. case "$1" in
  44. pull)
  45. mbsync -a
  46. notmuch new
  47. ;;
  48. --help)
  49. help_main
  50. ;;
  51. inbox)
  52. case "$2" in
  53. pyhalov@majordomo.ru)
  54. exec -a "$0" curl \
  55. --silent \
  56. --request "EXAMINE ${3:-INBOX}" \
  57. --user "pyhalov@majordomo.ru:$(pass show majordomo/private/newmail.majordomo.ru/pyhalov@majordomo.ru)" \
  58. imaps://imap.majordomo.ru:993
  59. ;;
  60. asfjsdf@mail.ru)
  61. exec -a "$0" curl \
  62. --silent \
  63. --request "EXAMINE ${3:-INBOX}" \
  64. --user "asfjsdf@mail.ru:$(pass show mail.ru/asfjsdf)" \
  65. imaps://imap.mail.ru:993
  66. ;;
  67. rxaetbed@mail.ru)
  68. exec -a "$0" curl \
  69. --silent \
  70. --request "EXAMINE ${3:-INBOX}" \
  71. --user "rxaetbed@mail.ru:$(pass show mail.ru/rxaetbed@mail.ru)" \
  72. imaps://imap.mail.ru:993
  73. ;;
  74. houdinihar@yandex.ru)
  75. exec -a "$0" curl \
  76. --silent \
  77. --request "EXAMINE ${3:-INBOX}" \
  78. --user "houdinihar:$(pass show email/yandex.ru/houdinihar)" \
  79. imaps://imap.yandex.ru:993
  80. ;;
  81. jenkins@majordomo.ru)
  82. exec -a "$0" curl \
  83. --silent \
  84. --request "EXAMINE ${3:-INBOX}" \
  85. --user "jenkins@majordomo.ru:$(pass show majordomo/public/jenkins.intr/admin)" \
  86. imaps://imap.majordomo.ru:993
  87. ;;
  88. i18n.wugi@yandex.ru)
  89. exec -a "$0" curl \
  90. --silent \
  91. --request "EXAMINE ${3:-INBOX}" \
  92. --user "i18n.wugi:$(pass show email/yandex.ru/i18n.wugi)" \
  93. imaps://imap.yandex.ru:993
  94. ;;
  95. zabbix.guix@yandex.ru)
  96. exec -a "$0" curl \
  97. --silent \
  98. --request "EXAMINE ${3:-INBOX}" \
  99. --user "zabbix.guix:$(pass show email/yandex.ru/zabbix.guix)" \
  100. imaps://imap.yandex.ru:993
  101. ;;
  102. oleg@wugi.info)
  103. exec -a "$0" curl \
  104. --silent \
  105. --request "EXAMINE ${3:-INBOX}" \
  106. --user "oleg:$(pass show vm1.wugi.info/oleg)" \
  107. imaps://imap.wugi.info:993
  108. ;;
  109. oleg-windows@wugi.info)
  110. exec -a "$0" curl \
  111. --silent \
  112. --request "EXAMINE ${3:-INBOX}" \
  113. --user "oleg:$(pass show vm1.wugi.info/oleg-windows)" \
  114. imaps://imap.wugi.info:993
  115. ;;
  116. localhost)
  117. exec -a "$0" curl \
  118. --silent \
  119. --request "EXAMINE ${3:-INBOX}" \
  120. --user "oleg:$(pass localhost/imap/oleg)" \
  121. imap://localhost
  122. ;;
  123. -A)
  124. printf "%s\n" "${mail_addresses[@]}"
  125. ;;
  126. ll)
  127. mail inbox -A | while IFS= read -r address
  128. do
  129. echo "$address"
  130. mail inbox "$address"
  131. done
  132. ;;
  133. *)
  134. help_inbox
  135. ;;
  136. esac
  137. ;;
  138. neomutt)
  139. case "$2" in
  140. pyhalov@majordomo.ru)
  141. exec -a "$0" neomutt -F "$HOME/.muttrc_pyhalov_majordomo"
  142. ;;
  143. asfjsdf@mail.ru)
  144. exec -a "$0" neomutt -F "$HOME/.muttrc_asfjsdf_mail"
  145. ;;
  146. rxaetbed@mail.ru)
  147. exec -a "$0" neomutt -F "$HOME/.muttrc_rxaetbed_mail"
  148. ;;
  149. houdinihar@yandex.ru)
  150. exec -a "$0" neomutt -F "$HOME/.muttrc_houdinihar_yandex"
  151. ;;
  152. jenkins@majordomo.ru)
  153. exec -a "$0" neomutt -F "$HOME/.muttrc_jenkins_majordomo"
  154. ;;
  155. i18n.wugi@yandex.ru)
  156. exec -a "$0" neomutt -F "$HOME/.muttrc_i18n.wugi_yandex"
  157. ;;
  158. zabbix.guix@yandex.ru)
  159. exec -a "$0" neomutt -F "$HOME/.muttrc_zabbix.guix_yandex"
  160. ;;
  161. localhost)
  162. exec -a "$0" neomutt -F "$HOME/.muttrc_localhost"
  163. ;;
  164. -A)
  165. printf "%s\n" "${mail_addresses[@]}"
  166. ;;
  167. *)
  168. help_neomutt
  169. ;;
  170. esac
  171. ;;
  172. *)
  173. help_main
  174. ;;
  175. esac