Skip to content

fix: correct rate limiting interval calculation in UIxMailEditor#373

Open
tobias-weiss-ai-xr wants to merge 7 commits intoAlinto:masterfrom
tobias-weiss-ai-xr:fix/rate-limit-interval-calculation
Open

fix: correct rate limiting interval calculation in UIxMailEditor#373
tobias-weiss-ai-xr wants to merge 7 commits intoAlinto:masterfrom
tobias-weiss-ai-xr:fix/rate-limit-interval-calculation

Conversation

@tobias-weiss-ai-xr
Copy link

The rate limiting check was using messageSubmissionBlockInterval (block duration) instead of maximumSubmissionInterval (rate limit window) to determine if message submission should be blocked.

Configuration example:
SOGoMaximumMessageSubmissionCount: 5 messages
SOGoMaximumRecipientCount: 100 recipients
SOGoMaximumSubmissionInterval: 30 seconds (rate limit window)
SOGoMessageSubmissionBlockInterval: 300 seconds (how long to block after violation)

Previous incorrect behavior:
Code checked: delta <= block_time (<= 300s)
Result: 5th message blocked even if sent AFTER 30s had elapsed

Correct behavior now:
Code checks: delta < maximumSubmissionInterval (< 30s)
Result: Only blocks if 5 messages sent WITHIN the 30s window

This also simplifies the counter reset logic - reset when the submission interval has elapsed AND we're within limits.

@tobias-weiss-ai-xr tobias-weiss-ai-xr force-pushed the fix/rate-limit-interval-calculation branch 2 times, most recently from 24856af to 5c609d6 Compare February 25, 2026 06:52
The rate limiting check was using messageSubmissionBlockInterval (block duration)
instead of maximumSubmissionInterval (rate limit window) to determine if
message submission should be blocked.

Configuration example:
  SOGoMaximumMessageSubmissionCount: 5 messages
  SOGoMaximumRecipientCount: 100 recipients
  SOGoMaximumSubmissionInterval: 30 seconds (rate limit window)
  SOGoMessageSubmissionBlockInterval: 300 seconds (how long to block after violation)

Previous incorrect behavior:
  Code checked: delta <= block_time (<= 300s)
  Result: 5th message blocked even if sent AFTER 30s had elapsed

Correct behavior now:
  Code checks: delta < maximumSubmissionInterval (< 30s)
  Result: Only blocks if 5 messages sent WITHIN the 30s window

This also simplifies the counter reset logic - reset when the submission
interval has elapsed AND we're within limits.
@tobias-weiss-ai-xr tobias-weiss-ai-xr force-pushed the fix/rate-limit-interval-calculation branch from 5c609d6 to 7976508 Compare February 25, 2026 07:07
@QHivert
Copy link
Contributor

QHivert commented Feb 26, 2026

Hello,
Thank you for you PR.

Your fix was right but the user was no longer blocked for SOGoMessageSubmissionBlockInterval if they exceeds the 5 messages in 30seconds. They were free again after 30s.

I've updated this PR, could you try it and tell me if this is okay ?

Tobias Weiß and others added 3 commits March 10, 2026 13:52
…aders

Fix critical bug where SOGo fails to quote display names containing
special characters (commas, parentheses, brackets, etc.) when serializing
email headers. This caused parsers to create bogus recipients and bounce
emails.

Root Cause:
- The _quoteSpecials: method checked for special characters ANYWHERE in
  the address string (including email part), and since all emails contain
  @ and ., it was always triggering
- It incorrectly extracted display names, assuming whitespace before <
- It didn't detect already-formatted addresses (quoted or RFC 2047 encoded)

Fix:
- Complete rewrite of _quoteSpecials: method
- Only checks display name (not email part) for special characters
- Detects already-formatted addresses (quoted strings, encoded words)
- Properly escapes backslashes and double quotes inside quoted strings
- Follows RFC 5322 specification precisely

Added helper methods:
- _needsQuotingForPhrase: - RFC 5322-compliant special character check
- _alreadyProperlyFormatted: - Detects quoted or encoded display names
- _quoteAndEscape: - Proper quoting and escaping

Test Coverage:
- Added TestSOGoDraftObjectQuoteSpecials.m with 18 comprehensive tests
- Covers all RFC 5322 special characters
- Tests edge cases (nil, empty, whitespace, already-formatted)

Fixes: Display names like "Lastname, Firstname (INFO)[MoreINFO]" now emit as:
"Lastname, Firstname (INFO)[MoreINFO]" <user@example.com>
Instead of: Lastname, Firstname (INFO)[MoreINFO] <user@example.com>

Co-authored-by: TDD workflow
See: docs/fix-email-header-serialization-bug.md for full analysis
@tobias-weiss-ai-xr
Copy link
Author

I am fine with that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants