Skip to content

fix(deeplink): encode message-id as base64url for deep links - #14023

Merged
kesselb merged 1 commit into
nextcloud:mainfrom
SoleroTG:fix/deeplink-message-id-slashes
Nov 20, 2026
Merged

kesselb merged 1 commit into
nextcloud:mainfrom
SoleroTG:fix/deeplink-message-id-slashes

Conversation

@SoleroTG

@SoleroTG SoleroTG commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Encodes Message-IDs as URL-safe base64url in the Unified Search provider and decodes them in DeepLinkController::open(), addressing #13970 as suggested in #14023 (comment).

Context & Implementation

  • URL-safe encoding: Unified Search generates deep links with base64url-encoded Message-IDs (rtrim(strtr(base64_encode(...), "+/", "-_"), "=")). This eliminates issues with slashes and special characters in the URL path while keeping the route definition clean.
  • Backwards compatibility: DeepLinkController::open() checks !str_contains($messageId, "@") before decoding. Because RFC 5322 Message-IDs always contain @ and base64url never does, existing unencoded links continue to work.
  • Tests: Added unit tests for base64url decoding, invalid base64 handling, and raw Message-ID fallback in DeepLinkControllerTest, plus URL generation in FilteringProviderTest.

Fixes #13970

Signed-off-by: SoleroTG github-29h@solero.quietmail.eu

@kesselb

kesselb commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Hi @SoleroTG, thanks a lot for the quick fix for #13970! Allowing slashes fixes this case, but Message-IDs can contain other characters that are awkward in a URL path as well. Could you encode the Message-ID (e.g. base64url) when generating the link in the search provider and decode it in DeepLinkController::open() instead of relaxing the route requirement? That way the route parameter is always URL-safe.

Please keep accepting the raw Message-ID as well, so existing links keep working (a raw Message-ID always contains an @, which base64url never does). Something along these lines:

lib/Search/Provider.php

$this->urlGenerator->linkToRouteAbsolute('mail.deep_link.open', [
        'messageId' => rtrim(strtr(base64_encode($message->getMessageId()), '+/', '-_'), '='),
]),

lib/Controller/DeepLinkController.php

if (!str_contains($messageId, '@')) {
        $messageId = base64_decode(strtr($messageId, '-_', '+/'), true);
        if ($messageId === false) {
                return new RedirectResponse($this->urlGenerator->linkToRouteAbsolute('mail.page.index'));
        }
}

@SoleroTG
SoleroTG force-pushed the fix/deeplink-message-id-slashes branch from a61f6e6 to 1978bcc Compare November 7, 2026 21:41
@SoleroTG SoleroTG changed the title fix(deeplink): allow slashes in message-id route requirement fix(deeplink): encode message-id as base64url for deep links Nov 7, 2026
@SoleroTG

SoleroTG commented Nov 7, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the suggestion, @kesselb. That is indeed much cleaner than overriding Symfony's route requirements and avoids all web server / path-segment quirks.

I have updated the PR accordingly:

  1. Search Provider (lib/Search/Provider.php):

    • The Message-ID is now URL-safe base64url encoded (rtrim(strtr(base64_encode($messageId), '+/', '-_'), '=')) when generating the deep link URL.
  2. Controller (lib/Controller/DeepLinkController.php):

    • If !str_contains($messageId, '@'), it is decoded using base64url (strict mode with fallback redirect to mail.page.index if decoding fails).
    • Because valid RFC 5322 Message-IDs require an @ and base64url never contains @, raw legacy links remain 100% backwards-compatible.
  3. Routes (appinfo/routes.php):

    • Reverted the route requirement override; default Symfony path routing ([^/]+) is restored.
  4. Tests (tests/Unit/Controller/DeepLinkControllerTest.php & tests/Unit/Search/FilteringProviderTest.php):

    • Added unit tests for base64url-encoded IDs, invalid base64 payloads, and raw fallback IDs with slashes.
    • Updated existing test fixtures to RFC 5322 compliant Message-IDs containing @.
    • Verified that FilteringProvider generates deep links with base64url-encoded IDs.

@kesselb

kesselb commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Thank you!

  • The "Copy message link" action in src/components/MenuEnvelope.vue still builds the link from the raw Message-ID, so links with a slash still 404 from there. Please encode it there as well.

Smaller things:

  • The encoding is written out in the provider, the controller and three times in the tests. A small helper for encode/decode keeps them in sync, and the tests can then compare against a fixed value instead of the same expression.
  • A message without Message-ID ends up as /apps/mail/open/. Please skip the link or fall back to the thread link.
  • testOpenMessageRawFallbackWithSlashes calls the controller directly, so it doesn't cover the routing, where the slash is the problem.
  • The comment in testOpenMessageInvalidBase64 only repeats the test name and can go.

Assisted by ClaudeCode:claude-opus-5-5

RFC 5322 permits characters in Message-IDs (such as slashes, quotes,
etc., commonly seen in GitHub notifications or Bugzilla/GitLab messages)
that are problematic in URL paths. When generating a deep link in the
Unified Search provider (mail.deep_link.open) or copying a direct link,
Symfony's UrlGenerator threw an InvalidParameterException or web servers
failed to route slashes.

Encode Message-IDs using URL-safe base64url via a Base64Url helper in
the search provider and envelope menu, and decode it in
DeepLinkController::open(). Unencoded Message-IDs are still accepted
for backwards compatibility by checking for the mandatory '@' symbol.
If a message lacks a Message-ID, the search provider falls back to
the direct thread link.

Fixes nextcloud#13970

Signed-off-by: SoleroTG <github-29h@solero.quietmail.eu>
@SoleroTG
SoleroTG force-pushed the fix/deeplink-message-id-slashes branch from e53ea62 to bee7643 Compare November 15, 2026 00:19
@SoleroTG

Copy link
Copy Markdown
Contributor Author

Thanks for the thorough review, @kesselb. All points have been addressed:

  1. MenuEnvelope ("Copy message link"):

    • Switched to Base64.encodeURL(trimmedMessageId) using js-base64, so links generated via the UI no longer 404 on IDs with slashes.
  2. Base64Url Helper:

    • Extracted Base64Url::encode() and Base64Url::decode() into OCA\Mail\Util\Base64Url and added unit test coverage in Base64UrlTest.
    • Tests in DeepLinkControllerTest and FilteringProviderTest now compare against the fixed string 'PG9yZy9yZXBvL2lzc3Vlcy8xMjMvNDU2QGV4YW1wbGUuaW52YWxpZD4'.
  3. Fallback when Message-ID is missing:

    • In Provider::search(), if a message does not have a Message-ID, it now falls back to mail.page.thread with mailboxId and id. Added a test in FilteringProviderTest covering this fallback.
  4. Test Cleanups:

    • Removed testOpenMessageRawFallbackWithSlashes and the redundant comment in testOpenMessageInvalidBase64.

@github-actions

Copy link
Copy Markdown

Hello there,
Thank you so much for taking the time and effort to create a pull request to our Nextcloud project.

We hope that the review process is going smooth and is helpful for you. We want to ensure your pull request is reviewed to your satisfaction. If you have a moment, our community management team would very much appreciate your feedback on your experience with this PR review process.

Your feedback is valuable to us as we continuously strive to improve our community developer experience. Please take a moment to complete our short survey by clicking on the following link: https://cloud.nextcloud.com/apps/forms/s/i9Ago4EQRZ7TWxjfmeEpPkf6

Thank you for contributing to Nextcloud and we hope to hear from you soon!

(If you believe you should not receive this message, you can add yourself to the blocklist.)

@kesselb
kesselb enabled auto-merge November 19, 2026 11:52
@kesselb

kesselb commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

/backport to stable5.13 please

@kesselb
kesselb merged commit 0b2cc67 into nextcloud:main Nov 20, 2026
58 of 66 checks passed
SoleroTG pushed a commit to SoleroTG/nextcloud-mail that referenced this pull request Nov 20, 2026
Base64UrlTest, added in nextcloud#14023, was not final, which fails the FinalizeTestCaseClassRector check on main.

Assisted-by: ClaudeCode:claude-sonnet-5-5
Signed-off-by: Christoph Wurst <1374172+ChristophWurst@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Global Mail search fails for Message-IDs containing '/' when generating deep links

3 participants