Refactor ensureUtf8 to handle exceptions and improve logic#33
Merged
Conversation
Contributor
Author
|
depends on horde/Util#28 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Handle unsupported charsets in
ensureUtf8()without aborting syncSummary
RuntimeExceptionfromHorde_String::convertCharset()inHorde_ActiveSync_Utils::ensureUtf8()so charset conversion failures use the existing fallback path instead of propagating up the stack.windows-1252,UTF-8) in the same exception handling so one unsupported label does not prevent later fallbacks from running.Problem
ensureUtf8()assumedHorde_String::convertCharset()always returns a string. Since Horde Util 6.x, conversion failures throwRuntimeException(for example when the MIME part declaresunknown-8bit, which PHP’s iconv/mbstring/intl stacks do not recognize).ActiveSync calls
ensureUtf8()when validating mail bodies (Horde_ActiveSync_Imap_MessageBodyData::_validateBodyData()), subjects, addresses, and iCalendar data. An uncaught exception during a Sync<Add>aborts the response; clients such as Outlook retry the same change indefinitely, which shows up as a sync loop in the logs.The method already documented fallbacks for invalid UTF-8 and for forcing transliteration, but those branches were unreachable if the initial
convertCharset()call threw.Solution
$from_charsetinsidetry/catch; return immediately on success with valid UTF-8.try/catch.This restores the original intent of
ensureUtf8(): best-effort UTF-8 output even when the declared charset is wrong or unsupported.Related work
Normalizing pseudo-charsets such as
unknown-8bitinhorde/util(CharacterSets::normalize()) addresses the most common case at the source. This change is complementary: any future or unknown charset that still makesconvertCharset()throw will no longer break ActiveSync export.Test plan
Content-Type: text/plain; charset=unknown-8bitvia Outlook (or another EAS client); confirm the message is added withoutERR: Unable to convert character setand without a sync loop.iso-8859-1,utf-8) still syncs with correct body text.RuntimeExceptionfromensureUtf8()duringSyncfor the test messages above.