#!/bin/bash
#
# vmail-stack
# https://git.stack-source.com/msb/vmail-stack
# Copyright (c) 2022 Matthew Saunders Brown <matthewsaundersbrown@gmail.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
#
PERCENT=$1
USER=$2
DOMAIN=${USER##*@}

if [ "$PERCENT" -eq '95' ] ; then
  MSG="Your mailbox is now $PERCENT% full. Please delete some messages immediately to avoid email service interruptions."
else
  MSG="Your mailbox is now $PERCENT% full. Please delete some messages to avoid exceeding your quota."
fi

echo "$MSG" | mail -s "Email quota warning" $USER -aFrom:postmaster@$DOMAIN