Skip to content

prune-mailq: Add an option to prune by regex #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 19, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion server/fedora/config/etc/scripts/prune-mailq
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ usage="Usage:
$0 show-rand [from regex|to regex]
$0 email lockers...
$0 purge-from lockers...
$0 purge-to lockers..."
$0 purge-from-re regexes...
$0 purge-to lockers...
$0 purge-to-re regexes..."

usage() {
echo "$usage" >&2;
Expand Down Expand Up @@ -102,6 +104,18 @@ purge_from() {
done
}

purge_from_re() {
if [[ $# -eq 0 ]]; then
echo "Please specify a regex to purge emails from" >&2
exit 1
fi
for re in "$@"; do
echo "$re"
mailq | tail -n +2 | grep -v '^ *(' | awk "BEGIN { RS = \"\" } (\$7 ~ \"$re\") { print \$1 }" | tr -d '*!' | postsuper -d -
echo
done
}

purge_to() {
if [[ $# -eq 0 ]]; then
echo "Please specify a locker to purge emails to" >&2
Expand All @@ -115,6 +129,18 @@ purge_to() {
done
}

purge_to_re() {
if [[ $# -eq 0 ]]; then
echo "Please specify a regex to purge emails to" >&2
exit 1
fi
for re in "$@"; do
echo "$re"
mailq | tail -n +2 | grep -v '^ *(' | awk "BEGIN { RS = \"\" } (\$8 ~ \"$re\" && \$9 == \"\") { print \$1 }" | tr -d '*!' | postsuper -d -
echo
done
}

op=${1:-}

# We want to go ahead and show the usage message if there are no args, so
Expand All @@ -127,7 +153,9 @@ case "$op" in
show-rand) show_rand "$@";;
email) tmpl_email "$@";;
purge-from) purge_from "$@";;
purge-from-re) purge_from_re "$@";;
purge-to) purge_to "$@";;
purge-to-re) purge_to_re "$@";;
*)
usage
;;
Expand Down