[2409] | 1 | #!/bin/sh |
---|
| 2 | |
---|
| 3 | set -eu |
---|
| 4 | shopt -s failglob |
---|
| 5 | |
---|
| 6 | usage="Usage: |
---|
| 7 | $0 list |
---|
[2410] | 8 | $0 show-rand |
---|
| 9 | $0 email lockers... |
---|
| 10 | $0 purge lockers..." |
---|
[2409] | 11 | |
---|
[2410] | 12 | clean_locker() { |
---|
| 13 | echo "${1%%@scripts.mit.edu}" |
---|
| 14 | } |
---|
| 15 | |
---|
[2409] | 16 | show_rand() { |
---|
| 17 | files=$(ls /var/spool/postfix/deferred/?/* | shuf | head -n 3) |
---|
| 18 | for file in $files; do |
---|
| 19 | echo ">>>> $file"; |
---|
| 20 | strings "$file" |
---|
| 21 | echo; |
---|
| 22 | done |
---|
| 23 | } |
---|
| 24 | |
---|
| 25 | tmpl_email() { |
---|
| 26 | sender=${SSH_GSSAPI_NAME%%/*} |
---|
| 27 | if [[ $# -eq 0 ]]; then |
---|
| 28 | echo "Please specific a locker to generate template for." >&2 |
---|
| 29 | exit 1 |
---|
| 30 | fi |
---|
| 31 | for locker in "$@"; do |
---|
[2410] | 32 | locker=$(clean_locker "$locker") |
---|
[2409] | 33 | echo "fs la /mit/$locker/" |
---|
| 34 | fs la "/mit/$locker" |
---|
| 35 | echo |
---|
| 36 | cat <<-EOF |
---|
| 37 | The scripts.mit.edu servers currently have a large number of email |
---|
| 38 | messages destined for the *$locker* account that are not being handled by |
---|
| 39 | your account and are being queued. Sufficiently large numbers of queued |
---|
| 40 | messages can cause stability issues for the servers, so we would like |
---|
| 41 | you to ensure that your account can handle all messages it receives by |
---|
| 42 | two weeks from now. |
---|
| 43 | |
---|
| 44 | You will be able to process the incoming messages if you sign up for the |
---|
| 45 | mail scripts service (http://scripts.mit.edu/mail/). You're welcome to |
---|
| 46 | simply forward all incoming mail to another address (the default is to |
---|
| 47 | forward it to the mit.edu address of the user who signs up); otherwise, |
---|
| 48 | you can configure mail scripts to process the incoming messages in some |
---|
| 49 | suitable fashion. |
---|
| 50 | |
---|
| 51 | Frequently, large numbers of queued messages are a sign that some wiki, |
---|
| 52 | blog, forum, or other site has been spammed. If this is the case, you |
---|
| 53 | should apply some appropriate spam-blocking mechanism. |
---|
| 54 | |
---|
| 55 | If you have any questions, feel free to contact us. |
---|
| 56 | |
---|
| 57 | Thanks, |
---|
| 58 | scripts.mit.edu team |
---|
| 59 | scripts@mit.edu --- semi-private |
---|
| 60 | scripts-root@mit.edu --- service maintainers only |
---|
| 61 | EOF |
---|
| 62 | echo;echo |
---|
| 63 | done |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | purge() { |
---|
| 67 | if [[ $# -eq 0 ]]; then |
---|
| 68 | echo "Please specific a locker to purge emails for." >&2 |
---|
| 69 | exit 1 |
---|
| 70 | fi |
---|
| 71 | for locker in "$@"; do |
---|
[2410] | 72 | locker=$(clean_locker "$locker") |
---|
[2409] | 73 | echo "$locker..." |
---|
| 74 | mailq | tail -n +2 | grep -v '^ *(' | awk "BEGIN { RS = \"\" } (\$8 == \"$locker@scripts.mit.edu\" && \$9 == \"\") { print \$1 }" | tr -d '*!' | postsuper -d - |
---|
| 75 | echo |
---|
| 76 | done |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | op=${1:-} |
---|
| 80 | shift |
---|
| 81 | case $op in |
---|
| 82 | list) |
---|
| 83 | mailq | tail -n +2 | grep -v '^ *(' | awk 'BEGIN { RS = "" } { print $8 }' | sort | uniq -c | sort -n |
---|
| 84 | ;; |
---|
| 85 | show-rand) show_rand;; |
---|
| 86 | email) tmpl_email "$@";; |
---|
| 87 | purge) purge "$@";; |
---|
| 88 | *) |
---|
| 89 | echo "$usage" >&2; |
---|
| 90 | exit 1 |
---|
| 91 | ;; |
---|
| 92 | esac |
---|
| 93 | |
---|
| 94 | # vim: set sts=4 sw=4 et: |
---|