Skip to content

Commit 44a0a54

Browse files
committed
E-Mail-Reminder to all attendees is sent only by organizer of the reminder/event
1 parent bbee011 commit 44a0a54

File tree

5 files changed

+26
-11
lines changed

5 files changed

+26
-11
lines changed

apps/dav/lib/CalDAV/Reminder/INotificationProvider.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@ interface INotificationProvider {
4444
* @param VEvent $vevent
4545
* @param string $calendarDisplayName
4646
* @param IUser[] $users
47+
* @param IUser $userOfReminder
4748
* @return void
4849
*/
4950
public function send(VEvent $vevent,
5051
string $calendarDisplayName,
51-
array $users = []): void;
52+
array $users = [],
53+
IUser $userOfReminder = null): void;
5254
}

apps/dav/lib/CalDAV/Reminder/NotificationProvider/AbstractProvider.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,13 @@ public function __construct(ILogger $logger,
9191
* @param VEvent $vevent
9292
* @param string $calendarDisplayName
9393
* @param IUser[] $users
94+
* @param IUser $userOfReminder
9495
* @return void
9596
*/
9697
abstract public function send(VEvent $vevent,
9798
string $calendarDisplayName,
98-
array $users = []): void;
99+
array $users = [],
100+
IUser $userOfReminder = null): void;
99101

100102
/**
101103
* @return string

apps/dav/lib/CalDAV/Reminder/NotificationProvider/EmailProvider.php

+13-4
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
use OCP\IL10N;
3838
use OCP\ILogger;
3939
use OCP\IURLGenerator;
40+
use OCP\IUser;
4041
use OCP\L10N\IFactory as L10NFactory;
4142
use OCP\Mail\IEMailTemplate;
4243
use OCP\Mail\IMailer;
@@ -80,15 +81,24 @@ public function __construct(IConfig $config,
8081
* @param VEvent $vevent
8182
* @param string $calendarDisplayName
8283
* @param array $users
84+
* @param IUser $userOfReminder
8385
* @throws \Exception
8486
*/
8587
public function send(VEvent $vevent,
8688
string $calendarDisplayName,
87-
array $users = []):void {
89+
array $users = [],
90+
IUser $userOfReminder = null):void {
8891
$fallbackLanguage = $this->getFallbackLanguage();
8992

9093
$emailAddressesOfSharees = $this->getEMailAddressesOfAllUsersWithWriteAccessToCalendar($users);
91-
$emailAddressesOfAttendees = $this->getAllEMailAddressesFromEvent($vevent);
94+
95+
$organizer = $this->getOrganizerEMailAndNameFromEvent($vevent);
96+
97+
$emailAddressesOfAttendees = [];
98+
99+
if ($userOfReminder && strcasecmp($userOfReminder->getEMailAddress(), key($organizer)) == 0) {
100+
$emailAddressesOfAttendees = $this->getAllEMailAddressesFromEvent($vevent);
101+
}
92102

93103
// Quote from php.net:
94104
// If the input arrays have the same string keys, then the later value for that key will overwrite the previous one.
@@ -99,7 +109,6 @@ public function send(VEvent $vevent,
99109
);
100110

101111
$sortedByLanguage = $this->sortEMailAddressesByLanguage($emailAddresses, $fallbackLanguage);
102-
$organizer = $this->getOrganizerEMailAndNameFromEvent($vevent);
103112

104113
foreach ($sortedByLanguage as $lang => $emailAddresses) {
105114
if (!$this->hasL10NForLang($lang)) {
@@ -196,7 +205,7 @@ private function getOrganizerEMailAndNameFromEvent(VEvent $vevent):?array {
196205
}
197206

198207
$organizer = $vevent->ORGANIZER;
199-
if (strcasecmp($organizer->getValue(), 'mailto:') !== 0) {
208+
if (!str_starts_with($organizer->getValue(), 'mailto:')) {
200209
return null;
201210
}
202211

apps/dav/lib/CalDAV/Reminder/NotificationProvider/PushProvider.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,13 @@ public function __construct(IConfig $config,
8383
* @param VEvent $vevent
8484
* @param string $calendarDisplayName
8585
* @param IUser[] $users
86+
* @param IUser $userOfReminder
8687
* @throws \Exception
8788
*/
8889
public function send(VEvent $vevent,
8990
string $calendarDisplayName = null,
90-
array $users = []):void {
91+
array $users = [],
92+
IUser $userOfReminder = null):void {
9193
if ($this->config->getAppValue('dav', 'sendEventRemindersPush', 'no') !== 'yes') {
9294
return;
9395
}

apps/dav/lib/CalDAV/Reminder/ReminderService.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,13 @@ public function processReminders():void {
141141
}
142142

143143
$users = $this->getAllUsersWithWriteAccessToCalendar($reminder['calendar_id']);
144-
$user = $this->getUserFromPrincipalURI($reminder['principaluri']);
145-
if ($user) {
146-
$users[] = $user;
144+
$userOfReminder = $this->getUserFromPrincipalURI($reminder['principaluri']);
145+
if ($userOfReminder) {
146+
$users[] = $userOfReminder;
147147
}
148148

149149
$notificationProvider = $this->notificationProviderManager->getProvider($reminder['type']);
150-
$notificationProvider->send($vevent, $reminder['displayname'], $users);
150+
$notificationProvider->send($vevent, $reminder['displayname'], $users, $userOfReminder);
151151

152152
$this->deleteOrProcessNext($reminder, $vevent);
153153
}

0 commit comments

Comments
 (0)