#!/bin/sh
### Copyright 1999-2024. WebPros International GmbH. All rights reserved.

export PATH=/bin:/usr/bin

recipient="$1"

if [ -z "$recipient" ]; then
	echo "User was not specified."
	exit 1
fi

msg_path="/var/qmail/mailnames/.quotawarnmsg"

if [ ! -f "$msg_path" ]; then
	echo "Unable to find warning report message '$msg_path'"
	exit 1
fi

sender_domain="`hostname -f`"
sender="postmaster@$sender_domain"
date="`date --rfc-2822`"

user_dir="`echo $recipient | awk -F '@' '{print tolower($1)}'`"
domain_dir="`echo $recipient | awk -F '@' '{print tolower($2)}'`"
dest_dir="/var/qmail/mailnames/$domain_dir/$user_dir/Maildir"

cat $msg_path | \
	sed -e "s|@SENDER@|$sender|" \
	    -e "s|@RECIPIENT@|$recipient|" \
	    -e "s|@DATE@|$date|" \
	| /usr/bin/deliverquota $dest_dir
