#!/bin/bash
# Version: 0.1.0
# Copyright (c) 2023:
#   Darren 'Tadgy' Austin <darren (at) afterdark.org.uk>
# Licensed under the terms of the GNU General Public License version 3.
#
# A Dovecot service script to check whether a domain or user has been suspended from being able to use mail.

VIRTUAL_DIR="/etc/virtual"
U="${USER%%@*}"
D="${USER#*@}"

[[ -e "$VIRTUAL_DIR/$D/suspended" ]] && {
  printf "* %s\\r\\n" "NO [ALERT] Domain suspended"
  exit 0
}

[[ -e "$VIRTUAL_DIR/$D/$U/suspended" ]] && {
  printf "* %s\\r\\n" "NO [ALERT] User suspended"
  exit 0
}

exec "$@"
