- Added rate limiting for outbound email sends to prevent abuse, implemented in `internal/api/mail/sendguard`. - Introduced idempotency key support for email sending to avoid duplicate submissions. - Enhanced attachment handling with new limits and validation in `internal/api/mail/limits`. - Updated outbox processing to include retry logic and circuit breaker for SMTP failures. - Improved HTML sanitization for email content to enhance security. - Added unit tests for new features, ensuring robust functionality and error handling. - Updated configuration options in `.env.example` for new mail settings.
27 lines
620 B
Go
27 lines
620 B
Go
package smtp
|
|
|
|
import "context"
|
|
|
|
// GuardedSender wraps Sender with a per-account SMTP circuit breaker.
|
|
type GuardedSender struct {
|
|
inner *Sender
|
|
circuit *CircuitBreaker
|
|
}
|
|
|
|
func NewGuardedSender(inner *Sender, circuit *CircuitBreaker) *GuardedSender {
|
|
return &GuardedSender{inner: inner, circuit: circuit}
|
|
}
|
|
|
|
func (g *GuardedSender) Send(ctx context.Context, req *SendRequest) error {
|
|
if err := g.circuit.Allow(req.AccountID); err != nil {
|
|
return err
|
|
}
|
|
err := g.inner.Send(ctx, req)
|
|
if err != nil {
|
|
g.circuit.RecordFailure(req.AccountID)
|
|
return err
|
|
}
|
|
g.circuit.RecordSuccess(req.AccountID)
|
|
return nil
|
|
}
|