#!/bin/bash
# Author: Alex Efros <powerman-asdf@yandex.ru>, 2008
# License: Public Domain
#
# ratelimit: Rate limiter designed for .qmail

VERSION="1.00"

if [ "$#" -lt 2 ]; then
    echo "Usage: ratelimit limiter-name period-in-minutes"
    echo "Example:"
    echo "  To setup new rate limiter 'sms' with rate 4 times per 2 hours:"
    echo "    ratelimit-setup sms 4"
    echo "  and put in ~/.qmail-sms:"
    echo "    |ratelimit sms 120"
    echo "    &sms@domain.tld"
    exit 1
fi

for f in $(find ~/.ratelimit/$1/ -type f -mmin +$2 | head -n 1); do
    touch $f
    exit 0
done
exit 99

