Skip to content

Commit a68d2cd

Browse files
committed
prune-mailq: Add an option to prune by regex
1 parent 11f7247 commit a68d2cd

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

server/fedora/config/etc/scripts/prune-mailq

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ usage="Usage:
99
$0 show-rand [from regex|to regex]
1010
$0 email lockers...
1111
$0 purge-from lockers...
12-
$0 purge-to lockers..."
12+
$0 purge-from-re regexes...
13+
$0 purge-to lockers...
14+
$0 purge-to-re regexes..."
1315

1416
usage() {
1517
echo "$usage" >&2;
@@ -102,6 +104,18 @@ purge_from() {
102104
done
103105
}
104106

107+
purge_from_re() {
108+
if [[ $# -eq 0 ]]; then
109+
echo "Please specify a regex to purge emails from" >&2
110+
exit 1
111+
fi
112+
for re in "$@"; do
113+
echo "$re"
114+
mailq | tail -n +2 | grep -v '^ *(' | awk "BEGIN { RS = \"\" } (\$7 ~ \"$re\") { print \$1 }" | tr -d '*!' | postsuper -d -
115+
echo
116+
done
117+
}
118+
105119
purge_to() {
106120
if [[ $# -eq 0 ]]; then
107121
echo "Please specify a locker to purge emails to" >&2
@@ -115,6 +129,18 @@ purge_to() {
115129
done
116130
}
117131

132+
purge_to_re() {
133+
if [[ $# -eq 0 ]]; then
134+
echo "Please specify a regex to purge emails to" >&2
135+
exit 1
136+
fi
137+
for re in "$@"; do
138+
echo "$re"
139+
mailq | tail -n +2 | grep -v '^ *(' | awk "BEGIN { RS = \"\" } (\$8 ~ \"$re\" && \$9 == \"\") { print \$1 }" | tr -d '*!' | postsuper -d -
140+
echo
141+
done
142+
}
143+
118144
op=${1:-}
119145

120146
# We want to go ahead and show the usage message if there are no args, so
@@ -127,7 +153,9 @@ case "$op" in
127153
show-rand) show_rand "$@";;
128154
email) tmpl_email "$@";;
129155
purge-from) purge_from "$@";;
156+
purge-from-re) purge_from_re "$@";;
130157
purge-to) purge_to "$@";;
158+
purge-to-re) purge_to_re "$@";;
131159
*)
132160
usage
133161
;;

0 commit comments

Comments
 (0)