Class EmailRateLimiter
java.lang.Object
cloud.opencode.base.email.security.EmailRateLimiter
Email Rate Limiter
邮件发送频率限制器
Limits email sending rate to prevent abuse.
限制邮件发送频率以防止滥用。
Features | 主要功能:
- Per-minute rate limiting - 每分钟频率限制
- Per-hour rate limiting - 每小时频率限制
- Per-day rate limiting - 每天频率限制
- Per-recipient tracking - 按收件人跟踪
Usage Examples | 使用示例:
EmailRateLimiter limiter = new EmailRateLimiter(10, 100, 500);
if (!limiter.allowSend("recipient@example.com")) {
throw new EmailException("Rate limit exceeded");
}
Security | 安全性:
- Thread-safe: Yes - 线程安全: 是
- Since:
- JDK 25, opencode-base-email V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordRate limit quota record 频率限制配额记录 -
Constructor Summary
ConstructorsConstructorDescriptionCreate rate limiter with default limits 使用默认限制创建频率限制器EmailRateLimiter(int maxPerMinute, int maxPerHour, int maxPerDay) Create rate limiter with custom limits 使用自定义限制创建频率限制器 -
Method Summary
Modifier and TypeMethodDescriptionbooleanCheck if sending is allowed (global, not per recipient) 检查是否允许发送(全局,非按收件人)booleanCheck if sending is allowed for recipient 检查是否允许向收件人发送intGet max per day limit 获取每天最大限制intGet max per hour limit 获取每小时最大限制intGet max per minute limit 获取每分钟最大限制Get remaining quota for recipient 获取收件人剩余配额voidReset rate limit for recipient 重置收件人的频率限制voidresetAll()Reset all rate limits 重置所有频率限制
-
Constructor Details
-
EmailRateLimiter
public EmailRateLimiter()Create rate limiter with default limits 使用默认限制创建频率限制器 -
EmailRateLimiter
public EmailRateLimiter(int maxPerMinute, int maxPerHour, int maxPerDay) Create rate limiter with custom limits 使用自定义限制创建频率限制器- Parameters:
maxPerMinute- max emails per minute | 每分钟最大邮件数maxPerHour- max emails per hour | 每小时最大邮件数maxPerDay- max emails per day | 每天最大邮件数
-
-
Method Details
-
allowSend
Check if sending is allowed for recipient 检查是否允许向收件人发送- Parameters:
recipient- the recipient email | 收件人邮箱- Returns:
- true if allowed | 允许返回true
-
allowSend
public boolean allowSend()Check if sending is allowed (global, not per recipient) 检查是否允许发送(全局,非按收件人)- Returns:
- true if allowed | 允许返回true
-
getQuota
Get remaining quota for recipient 获取收件人剩余配额- Parameters:
recipient- the recipient email | 收件人邮箱- Returns:
- the remaining quota | 剩余配额
-
reset
Reset rate limit for recipient 重置收件人的频率限制- Parameters:
recipient- the recipient email | 收件人邮箱
-
resetAll
public void resetAll()Reset all rate limits 重置所有频率限制 -
getMaxPerMinute
public int getMaxPerMinute()Get max per minute limit 获取每分钟最大限制- Returns:
- the limit | 限制值
-
getMaxPerHour
public int getMaxPerHour()Get max per hour limit 获取每小时最大限制- Returns:
- the limit | 限制值
-
getMaxPerDay
public int getMaxPerDay()Get max per day limit 获取每天最大限制- Returns:
- the limit | 限制值
-