Skip to content

Instantly share code, notes, and snippets.

@yetimdasturchi
Created January 28, 2025 16:11
Show Gist options
  • Save yetimdasturchi/1ebc4dc4ff1edb817827bf56c81a5748 to your computer and use it in GitHub Desktop.
Save yetimdasturchi/1ebc4dc4ff1edb817827bf56c81a5748 to your computer and use it in GitHub Desktop.
Mail queue cleaner script for antispam.

Maqil queue cleaner script for antispam

Add script to cronjob

*/5 * * * * /usr/bin/bash /bin/mailq_cleaner.sh > /dev/null 2>&1
#!/bin/bash
CURRENT_TIME=$(date +%s)
mailq | awk '/^[A-F0-9]/ {print $1, $3, $4, $5}' | while read -r ID MONTH DAY TIME; do
MESSAGE_DATE="$MONTH $DAY $TIME $(date +%Y)"
MSG_TIMESTAMP=$(date -d "$MESSAGE_DATE" +%s 2>/dev/null)
if [ $? -ne 0 ]; then
echo "Invalid date format for message ID: $ID"
continue
fi
AGE=$((CURRENT_TIME - MSG_TIMESTAMP))
if [ "$AGE" -gt 300 ]; then
echo "Removing message ID: $ID (Age: $((AGE / 60)) minutes)"
postsuper -d "$ID"
fi
done
echo "Cleanup complete: Removed messages older than 5 minutes."
@ZTectonic
Copy link

Ajoyib

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment