Quota

Quota support for Policyd v2. This module supports message count and message cumulative size over a user defined period of time.

Message counters can be based on (tracked) depending on sender, recipient or sender IP. It works in the following manner… One defines a quota linked to a policy, you then set how this quota is going to be tracked using the below "Track"ing options, a period is provided over which time the limits will apply. Limits are then defined and linked against the quota, a counter type (described below) is supplied along with the counter limit.

See an explanation at the bottom of this page regarding counters.

Policy

  • Track counters using the policy. All mail hitting this policy will be tracked in a single counter.

Sender

  • SenderIP:/bitmask
    • One can specify a bitmask to apply to the sending servers' IP address, for instance /24. This will track the triplet through the entire /24 block. SenderIP's bitmask can be any bitmask, 1-32. A sane value is /24.
    • Specifying any IPv6 bitmask, 1-128 will apply the bitmask to the sending server's IP address. A sane value for this is /64. When using quotas on both IPv4 and IPv6, please ensure you use the IPv4 policy member 0.0.0.0/0 (or 0/0) and the IPv6 policy member ::/0 to distinguish between the two so you get the bitmask right. (Support for IPv6 is included in r493+, v2.1.x)
  • SASLUsername
    • Track counters using the SASL username the user is logged in with.
    • For email where the SASL username is unspecified, the tracking key will be set to "SASLUsername:-", so it may be in your best interest to adjust your policy to ONLY match email which has a SASL username unless this is your intention. (Additional support in r493+, v2.1.x)
  • Sender:user@domain
    • A counter will be created for each sender email address and counters for each individual sender will be tracked.
  • Sender:@domain
    • A counter will be created for each sender domain, each domain is tracked on its own and all email sent from these domains will be tracked and matched.
  • Sender:user@
    • A counter will be created for each sender user part of the domain, each user is tracked on its own just like the domain above. Any email orginating from this user portion will be matched.

Recipient

  • Recipient:user@domain
    • A counter will be created for each recipient email address and counters for each individual recipient will be tracked.
  • Recipient:@domain
    • A counter will be created for each recipient domain, each domain is tracked on its own and all email sent from these domains will be tracked and matched.
  • Recipient:user@
    • A counter will be created for each recipient user part of the domain, each user is tracked on its own just like the domain \ above. Any email destined to this user portion will be matched.
  • MessageCount
    • Message count, in other words the number of email messages.
  • MessageCumulativeSize
    • Cumulative size of email messages, or you could say bandwidth quota. This is in bytes.
  • LastQuota (present in r348+, v2.1.x)
    • The first policy matched will be the only one that gets used, if you have 10 policies ranging from 1 to 10 in priority and you set this to 'yes' for the 5th policy, it will not continue through the rest of the matching quotas.

Configuration for this module is done in the [Quotas] section in the configuration file.

  • enable
    • Set to 1 if you wish to enable this module. Default 0 (disabled).

The following example demonstrates how to limit the number of outbound emails per hour to 3600:

Policy: Default Outbound Policy
Track: Sender:user@domain
Period: 3600

# Associate a limit:

Type: MessageCount
CounterLimit: 3600

Quota counters example:

1. Counter = DBValue
2. ElapsedTime = Now - LastUpdate
3. IF ElapsedTime > Period THEN CurrentCounter = 0 ELSE CurrentCounter = ( 1 - (ElapsedTime / Period) ) * Counter
4. Delta = CurrentCounter - Counter
5. CurrentCounter++
6. IF CurrentCounter > Limit THEN 
7. DBValue += Delta (+1)

Consider the following if Counter is currently 8 and the Period is 300:

Counter = 8
ElapsedTime = 13:29:57 - 13:26:22 = 215
CurrentCounter = ( 1 - (215 / 300) ) * 8 = 2.27
Delta = 2.27 - 8 = -5.73
* * allow mail .... CurrentCounter (+1) < Limit * *
DBValue += -5.73 (+1) = 3.27