I attach a script that can do it.
On 28/10/2021 11:56, richard lucassen wrote:
On Thu, 28 Oct 2021 12:26:31 +0200
Matus UHLAR - fantomas <uh...@fantomas.sk> wrote:
Why do you have _any_ messages in the hold queue? Don't do that!
kind of quarantine I guess.
Yep. Most of these messages are bank phishing mails BTW, I delete the
hold queue once a day. But never mind, was just wondering if anybody
had written such a script.
#!/bin/bash
# hold_deleter.sh v0.1 by Dominic Raferd <domi...@timedicer.co.uk> [28 Oct 2021]
find_program() {
command -v "$1" || { echo "Cannot locate $1 program; aborted" >&2; exit
1; }
}
# help
[[ -z $1 || $1 == "-h" || $1 == "--help" ]] && { echo -e "Usage:
hold_deleter.sh DATETIME\nSpecify parameter 1 as a datetime (as understood by
command 'date -d'); mails still in the postfix hold queue, and which entered it
before then, will be deleted\nExample: ./hold_deleter.sh '-2 days'"; exit 0; }
# check dependencies
JQ="$(find_program jq)"
POSTQUEUE="$(find_program postqueue)"
POSTSUPER="$(find_program postsuper)"
# convert datetime to epoch style
BEFORE="$(date +%s -d"$1" 2>/dev/null)"
[[ $BEFORE =~ ^[1-9][0-9]+$ ]] || { echo "Error converting date/time; aborted"
>&2; exit 1; }
# obtain QIDs, if any
QIDS=( $("$POSTQUEUE" -j|grep -F '"queue_name": "hold"'|"$JQ" '.arrival_time,
.queue_id'|sed 'N;s/\n//;s/"/,/g'|awk -F, -v BEFORE="$BEFORE" '{if ($1<BEFORE)
print $2}') )
echo -n "${#QIDS[*]} mail(s) earlier than $1 found in postfix hold queue: "
# action, if any
[[ ${#QIDS[*]} -eq 0 ]] && { echo "nothing to do"; exit 0; }
echo ${QIDS[*]}|"$POSTSUPER" -d- && { echo "deleted OK"; exit 0; }
echo "deletion FAILED"
echo "Error attempting to delete QID(s) ${QIDS[*]}" >&2
exit 1