IONOS(sharebymail): add BeforeShare*MailSentEvent dispatched before each mail send (HDNEXT-1010)#262
Open
printminion-co wants to merge 3 commits into
Open
IONOS(sharebymail): add BeforeShare*MailSentEvent dispatched before each mail send (HDNEXT-1010)#262printminion-co wants to merge 3 commits into
printminion-co wants to merge 3 commits into
Conversation
6 tasks
0dfb4f0 to
05ca5da
Compare
05ca5da to
e5d9cd6
Compare
…ateData variables Extract the inline array literals passed to each createEMailTemplate() call into named $templateData variables. For sendNote(), which previously passed no data array, add a minimal array so all four send methods are consistent. Zero behaviour change — $templateData is passed straight through to createEMailTemplate() with identical contents.
1083f45 to
450ed8c
Compare
…ach mail send
Dispatch a typed PSR-14 event immediately before every mailer->send() call
in ShareByMailProvider so that external listeners can intercept and replace
Nextcloud's native SMTP delivery.
Event hierarchy:
AbstractBeforeShareMailSentEvent (base: share, resolvedEmails, message,
markMailHandled / isMailHandled)
├── BeforeShareMailSentEvent – sendEmail()
├── BeforeSharePasswordMailSentEvent – sendPassword() + sendPasswordToOwner()
└── BeforeShareNoteMailSentEvent – sendNote()
Each concrete class holds its own typed $templateData (psalm array-shape)
and exposes named getters (getSenderUserId(), getFileName(), …) instead of
a generic getMailData(): array<string,mixed>. This avoids defensive
is_string() / null guards in listeners.
$templateData reuses the array already passed to createEMailTemplate(), with
one extra key added for sendEmail(): senderUserId (the raw user ID, distinct
from the display name stored under 'initiator').
The native mailer->send() is skipped when a listener calls markMailHandled().
If the listener's own send throws, the exception propagates and the native
send is also skipped — no silent SMTP fallback.
sendEmail() and sendPassword() are flattened from nested
if (!isMailHandled()) { ... } pyramids to early-return style.
Signed-off-by: Misha M.-Kupriyanov <kupriyanov@strato.de>
…etters) Signed-off-by: Misha M.-Kupriyanov <kupriyanov@strato.de>
450ed8c to
ccc0f83
Compare
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.
Summary
Introduces a PSR-14 event hook inside
ShareByMailProviderthat allows app-layer listeners to replace the native Nextcloud SMTP path for share-by-mail notifications.New event classes in
apps/sharebymail/lib/Event/AbstractBeforeShareMailSentEvent— abstract base carrying the fully-preparedIMessage, validated recipient list, pre-computed mail data, and amarkMailHandled()flagBeforeShareMailSentEvent— fired bysendEmail()before the share-link notification sendBeforeSharePasswordMailSentEvent— fired bysendPassword()andsendPasswordToOwner()before password emailsBeforeShareNoteMailSentEvent— fired bysendNote()before note-update emailsHow the replacement mechanism works
When a listener calls
$event->markMailHandled(), the nativemailer->send()is skipped. If the listener's own send throws, the exception propagates — native send is also skipped. No silent fallback. When no listener is active, native SMTP runs as before.mailDataarrayEach send method passes the data it already computed before building the
IMessage. Listeners read$event->getMailData()instead of re-deriving from the share, avoiding duplicate user/node lookups.BeforeShareMailSentEventcarries:senderUserId,fileName,resourceUrl,note,expiration(\DateTime|null).Dispatch point
Events fire inside each private send method immediately before
mailer->send()— covering bothManager::createShare()andsendShareEmail()Controller paths without touching either.Related PRs
BeforeShareMailSentEventTest plan
apps/sharebymail/unit tests pass