View Issue Details

IDProjectCategoryView StatusLast Update
0006227SOGoWeb Mailpublic2026-07-02 06:32
Reportertk_umr Assigned To 
PrioritynormalSeverityminorReproducibilityalways
Status newResolutionopen 
Product Version5.12.9 
Summary0006227: Broken encoding of display names containing a comma and square brackets
Description

We have many users who use the format

<surname>, <given name> [department]

as their sender name (preferences: "Full Name").

SOGo does not quote the "display name" [see RFC 5322: https://www.rfc-editor.org/info/rfc5322/#section-3.4] (which is probably correct because it's not required here, I guess) when sending new messages or responding to messages with such a sender name. Instead it uses the "Q encoding" as transfer-encoding [see RFC 2047: https://www.rfc-editor.org/info/rfc2047/#section-4.2].

When encoding the display name the comma is interpreted as separator of multiple addresses and since the part before the comma is not a valid email address, "@MISSING_DOMAIN" is appended here to mark the "address".

The same display error occurs when the message was sent from a different mail client which does not quote the display name.
It does not occur (in the first place) when the display name is quoted (as e.g. Thunderbird does). But it does in replies to such messages: the recipient of the reply works when sending the message, but it's wrongly displayed when opening the reply in SOGo.

Steps To Reproduce

1) Create a new IMAP Identity and set the "Full Name" according to the mentioned pattern "<text>, <text> [<text>]".
2) Send a new message.
3) Open the new message in SOGo.

The error shows up in the "Sent" folder of the sending account as well as in the INBOX of the receiveing account.

Additional Information

This issue was reported at the SOGo users mailing list before: https://www.mail-archive.com/users@sogo.nu/msg34104.html

Tagsencoding

Activities

tk_umr

tk_umr

2026-06-26 15:39

reporter   ~0018512

Maybe the home-grown parser can be improved by the GNUstep library GSMime (https://www.gnustep.org/resources/documentation/Developer/BaseAdditions/Reference/GSMime.html). The library class GSMimeHeader probably already contains the required functionality.

tobias.weiss@uni-marburg.de

tobias.weiss@uni-marburg.de

2026-07-02 06:32

reporter   ~0018515

I believe this bug can be fixed by https://github.com/Alinto/sogo/pull/375

The Bug
The _quoteSpecials: method in SoObjects/Mailer/SOGoDraftObject.m had three problems that caused addresses like "Max, Muster [ABC]" <Max.Muster@ab-cd.df> to "break into pieces":

  1. Checked for special chars ANYWHERE in the string (including the <email> part). Since every email contains @ and ., the quoting logic was always triggered for any address with angle brackets — even when unnecessary.

  2. Incorrect display name extraction: It scanned from the end for <, then used substringToIndex: i - 1 (assuming a space before <). This broke for addresses like Lastname, Firstname <user@ex.com> where there's no space or unexpected whitespace.

  3. No detection of already-formatted names: It would double-quote an already-quoted "Doe, John" <user@ex.com> into ""Doe, John"" <user@ex.com>.

  4. No RFC 2047 encoded-word awareness: Would corrupt already-encoded display names.

The Fix (4 methods)

Method What it does
_needsQuotingForPhrase: RFC 5322-compliant check — only inspects display name part for ,;:@.<>[]()\"
_alreadyProperlyFormatted: Detects already-quoted "..." or RFC 2047 =?…?= names — skips re-quoting
_quoteAndEscape: Properly escapes \ and " inside quoted strings per RFC 5322
_quoteSpecials: Full rewrite — splits display name from email, applies checks per component

Test Coverage — 18 tests

  • The exact reported bug: Lastname, Firstname (INFO)[MoreINFO] <user@example.com> → correctly quoted
  • Simple email, simple display name — unchanged
  • Display names with: comma, parenthesis, brackets, colon, semicolon, @, ., backslash, double-quote — all correctly quoted
  • Already-quoted / RFC 2047 encoded — passed through unmodified
  • Nil/empty input — handled gracefully
  • Array version _quoteSpecialsInArray: — works for batch recipient lists
  • Whitespace trimming around display names

Files Changed
SoObjects/Mailer/SOGoDraftObject.m 89 insertions, 42 deletions — full rewrite of _quoteSpecials: + 3 new helpers
Tests/Unit/TestSOGoDraftObjectQuoteSpecials.m 429 lines — new test file
Tests/Unit/GNUmakefile 1 line — adds new test to build
docs/fix-email-header-serialization-bug.md 146 lines — root cause analysis doc // maybe exlude

Verdict
The fix is thorough and RFC 5322 compliant. The old code was checking for specials on the entire address string. The new approach cleanly separates display name from email, only quotes when needed, and avoids double-quoting. 18 tests cover corner cases. The "Max, Muster [ABC]" <Max.Muster@ab-cd.df> case from the description would be handled perfectly by this fix — the comma and brackets in the display name would be quoted via _quoteAndEscape:, emitting "Max, Muster [ABC]" <Max.Muster@ab-cd.df>.

Best, Tobias

Issue History

Date Modified Username Field Change
2026-06-26 15:26 tk_umr New Issue
2026-06-26 15:26 tk_umr Tag Attached: encoding
2026-06-26 15:39 tk_umr Note Added: 0018512
2026-07-02 06:32 tobias.weiss@uni-marburg.de Note Added: 0018515