#!/bin/sh
# Wombat-Email: a mailbox crossed a quota level (Dovecot runs this as root; installer/60-dovecot.sh says why).
#   wombat-email-quota-warning PERCENT|below ADDRESS
# The message goes into that mailbox itself, even when it's full (quota_enforce=no just for this).
# Ported from the reference server's quota-warning.sh.
PERCENT=$1
USER=$2
if [ "$PERCENT" = below ]; then
    SUBJECT="Your mailbox is no longer full"
    BODY="$USER is below its storage limit again: new mail arrives as usual."
else
    SUBJECT="Your mailbox is $PERCENT% full"
    BODY="$USER is using $PERCENT% of its storage limit.
Delete some mail (Trash and Spam count too) to make room.
At 100%, new mail waits, and senders try again later."
fi
cat <<MSG | /usr/local/libexec/wombat-email-mime | /usr/lib/dovecot/dovecot-lda -d "$USER" -o quota_enforce=no
From: postmaster@$(hostname -f)
To: $USER
Subject: $SUBJECT
Date: $(date -R)
Message-ID: <quota-$(date +%s)-$$@$(hostname -f)>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8

$BODY
MSG
