Skip to content

feat(HDNEXT-1010): intercept file-request send-email via IONOS mailer API#17

Open
printminion-co wants to merge 6 commits into
mainfrom
HDNEXT-1010-intercept-send-email
Open

feat(HDNEXT-1010): intercept file-request send-email via IONOS mailer API#17
printminion-co wants to merge 6 commits into
mainfrom
HDNEXT-1010-intercept-send-email

Conversation

@printminion-co

@printminion-co printminion-co commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Summary

Replaces ShareCreatedEventListener with BeforeShareMailSentEventListener — the single handler for all share-by-link email delivery via the IONOS internal mail API.

What changed

  • New: BeforeShareMailSentEventListener handles BeforeShareMailSentEvent fired by ShareByMailProvider.sendEmail() (nc-server PR#262). Calls markMailHandled() unconditionally in every TYPE_EMAIL code path, suppressing native Nextcloud SMTP.
  • Retired: ShareCreatedEventListener caused double-sends — it called the IONOS API at ShareCreatedEvent time while native SMTP also ran via sendMailNotification().
  • Simplified: listener constructor drops IUserManager and IURLGenerator — the event now carries pre-computed mailData (senderUserId, fileName, resourceUrl, note, expiration).
  • psalm.xml: adds ../../apps/sharebymail/lib/Event as extra files so psalm resolves the event class.
  • tests/stubs/: provides BeforeShareMailSentEvent stub for CI environments without nc-server.

markMailHandled() coverage

Code path markMailHandled() called?
Non-TYPE_EMAIL share no — native SMTP still runs
TYPE_EMAIL, empty recipients yes — suppressed + warning logged
TYPE_EMAIL, missing senderUserId in mailData yes — suppressed + error logged
TYPE_EMAIL, successful IONOS send yes — suppressed
TYPE_EMAIL, IONOS send throws propagates as exception (native send also skipped)

Related PRs

Test plan

  • composer test:unit — 14/14 pass
  • composer cs:fix — no changes
  • composer psalm — no errors
  • E2E: regular share by email → IONOS API called once; no double-send
  • E2E: file request send-email → IONOS API called; no native SMTP

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for routing “send-email” (share email resend) requests through the IONOS mailer API by introducing a new listener for BeforeShareMailNotifiedEvent, while also hardening existing share-created handling against empty recipients to prevent IONOS API errors.

Changes:

  • Add BeforeShareMailNotifiedEventListener to intercept email resend events and forward them to IonosMailerService.
  • Add an early-return guard in ShareCreatedEventListener when getSharedWith() is empty.
  • Extend unit tests and test bootstrap to support the new event (via stub fallback) and validate listener registrations.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
lib/Listener/ShareCreatedEventListener.php Adds empty-recipient guard before sending to the mailer service.
lib/Listener/BeforeShareMailNotifiedEventListener.php New listener for resend/send-email flow, sends share-by-link payload via IONOS mailer.
lib/AppInfo/Application.php Registers the new listener in the app bootstrap.
tests/Listener/ShareCreatedEventListenerTest.php Adds unit test for empty-recipient guard behavior.
tests/Listener/BeforeShareMailNotifiedEventListenerTest.php New unit tests for the new listener’s behavior and error paths.
tests/stubs/BeforeShareMailNotifiedEvent.php Provides test-only fallback event class when not available in the runtime.
tests/bootstrap.php Loads the fallback event stub conditionally for unit tests.
tests/AppInfo/ApplicationTest.php Updates expectations to verify both event listener registrations.
psalm.xml Adds the new event stub file to Psalm stubs to satisfy static analysis.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/AppInfo/Application.php Outdated
Comment on lines +46 to +47
$context->registerEventListener(ShareCreatedEvent::class, ShareCreatedEventListener::class);
$context->registerEventListener(BeforeShareMailNotifiedEvent::class, BeforeShareMailNotifiedEventListener::class);
Comment thread tests/Listener/BeforeShareMailNotifiedEventListenerTest.php Outdated
Comment thread tests/Listener/BeforeShareMailNotifiedEventListenerTest.php Outdated
Comment thread tests/Listener/BeforeShareMailNotifiedEventListenerTest.php Outdated
Comment thread tests/Listener/BeforeShareMailNotifiedEventListenerTest.php Outdated
Comment thread tests/Listener/BeforeShareMailNotifiedEventListenerTest.php Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Comment on lines +16 to +18
use OCA\IonosProcesses\Service\IonosMailerService;
use OCP\EventDispatcher\Event;
use OCP\Files\Node;
…lock

Signed-off-by: Misha M.-Kupriyanov <kupriyanov@strato.de>
…n composer.lock

Signed-off-by: Misha M.-Kupriyanov <kupriyanov@strato.de>
Signed-off-by: Misha M.-Kupriyanov <kupriyanov@strato.de>
…it to version ^8.5.52 || ^9.6.34 in composer.lock

Signed-off-by: Misha M.-Kupriyanov <kupriyanov@strato.de>
@printminion-co printminion-co force-pushed the HDNEXT-1010-intercept-send-email branch 2 times, most recently from da3dcb8 to fbce3b2 Compare June 15, 2026 13:46
…lSentEventListener (HDNEXT-1010)

Delivery is now triggered by BeforeShareMailSentEvent fired from inside
ShareByMailProvider.sendEmail() (nc-server PR#262). This covers both
Manager::createShare() and the sendShareEmail() Controller path with a
single listener — eliminating the previous double-send on regular shares.

The event carries pre-computed mail data (senderUserId, fileName,
resourceUrl, note, expiration) so the listener no longer needs
IUserManager or IURLGenerator injections.

markMailHandled() is called unconditionally in every TYPE_EMAIL code path
so native Nextcloud SMTP is suppressed in all branches. IONOS send
failures propagate as exceptions without falling back to SMTP.

Non-TYPE_EMAIL share types are not marked handled — native SMTP still
runs for them.

Retires ShareCreatedEventListener which caused double-sends when combined
with the native sendMailNotification() call in Manager::createShare().
Adds tests/stubs/BeforeShareMailSentEvent.php for CI environments without
the nc-server sharebymail app. Adds sharebymail event path to psalm.xml
for static analysis.
…NEXT-1010)

BeforeShareMailSentEvent now exposes named typed getters (getSenderUserId(),
getFileName(), getResourceUrl(), getNote(), getExpiration()) instead of a
generic getMailData(): array<string,mixed>.

Drop all defensive is_string() / null checks in the listener — types are
guaranteed by the event class.  Remove testMissingSenderUserIdMarkHandledAndLogsError
(the corresponding listener guard no longer exists).

Update the CI stub and makeEvent() to use the new constructor shape
($templateData with Nextcloud template-convention key names: 'filename',
'link', 'initiator', … instead of the old camelCase event keys).
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