Skip to content

Commit fd85c86

Browse files
committed
fix(dav): Parse sender PARTSTAT in REPLYs
Signed-off-by: Anna Larch <anna@nextcloud.com>
1 parent f37b29e commit fd85c86

2 files changed

Lines changed: 35 additions & 3 deletions

File tree

apps/dav/lib/CalDAV/Schedule/IMipPlugin.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,12 @@ public function schedule(Message $iTipMessage) {
217217

218218
$sender = substr($iTipMessage->sender, 7);
219219

220+
$replyingAttendee = null;
220221
switch (strtolower($iTipMessage->method)) {
221222
case self::METHOD_REPLY:
222223
$method = self::METHOD_REPLY;
223224
$data = $this->imipService->buildBodyData($vEvent, $oldVevent);
225+
$replyingAttendee = $this->imipService->getReplyingAttendee($iTipMessage);
224226
break;
225227
case self::METHOD_CANCEL:
226228
$method = self::METHOD_CANCEL;
@@ -256,7 +258,7 @@ public function schedule(Message $iTipMessage) {
256258
$template = $this->mailer->createEMailTemplate('dav.calendarInvite.' . $method, $data);
257259
$template->addHeader();
258260

259-
$this->imipService->addSubjectAndHeading($template, $method, $data['invitee_name'], $data['meeting_title'], $isModified);
261+
$this->imipService->addSubjectAndHeading($template, $method, $data['invitee_name'], $data['meeting_title'], $isModified, $replyingAttendee);
260262
$this->imipService->addBulletList($template, $vEvent, $data);
261263

262264
// Only add response buttons to invitation requests: Fix Issue #11230

apps/dav/lib/CalDAV/Schedule/IMipService.php

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,15 +366,32 @@ public function getAttendeeRsvpOrReqForParticipant(?Property $attendee = null) {
366366
* @param bool $isModified
367367
*/
368368
public function addSubjectAndHeading(IEMailTemplate $template,
369-
string $method, string $sender, string $summary, bool $isModified): void {
369+
string $method, string $sender, string $summary, bool $isModified, ?Property $replyingAttendee = null): void {
370370
if ($method === IMipPlugin::METHOD_CANCEL) {
371371
// TRANSLATORS Subject for email, when an invitation is cancelled. Ex: "Cancelled: {{Event Name}}"
372372
$template->setSubject($this->l10n->t('Cancelled: %1$s', [$summary]));
373373
$template->addHeading($this->l10n->t('"%1$s" has been canceled', [$summary]));
374374
} elseif ($method === IMipPlugin::METHOD_REPLY) {
375375
// TRANSLATORS Subject for email, when an invitation is replied to. Ex: "Re: {{Event Name}}"
376376
$template->setSubject($this->l10n->t('Re: %1$s', [$summary]));
377-
$template->addHeading($this->l10n->t('%1$s has responded to your invitation', [$sender]));
377+
// Build the strings
378+
$partstat = (isset($replyingAttendee)) ? $replyingAttendee->offsetGet('PARTSTAT') : null;
379+
$partstat = ($partstat instanceof Parameter) ? $partstat->getValue() : null;
380+
switch ($partstat) {
381+
case 'ACCEPTED':
382+
$template->addHeading($this->l10n->t('%1$s has accepted your invitation', [$sender]));
383+
break;
384+
case 'TENTATIVE':
385+
$template->addHeading($this->l10n->t('%1$s has tentatively accepted your invitation', [$sender]));
386+
break;
387+
case 'DECLINED':
388+
$template->addHeading($this->l10n->t('%1$s has declined your invitation', [$sender]));
389+
break;
390+
case null:
391+
default:
392+
$template->addHeading($this->l10n->t('%1$s has responded to your invitation', [$sender]));
393+
break;
394+
}
378395
} elseif ($method === IMipPlugin::METHOD_REQUEST && $isModified) {
379396
// TRANSLATORS Subject for email, when an invitation is updated. Ex: "Invitation updated: {{Event Name}}"
380397
$template->setSubject($this->l10n->t('Invitation updated: %1$s', [$summary]));
@@ -603,4 +620,17 @@ public function addMoreOptionsButton(IEMailTemplate $template, $token) {
603620

604621
$template->addBodyText($html, $text);
605622
}
623+
624+
public function getReplyingAttendee(Message $iTipMessage): ?Property {
625+
/** @var VEvent $vevent */
626+
$vevent = $iTipMessage->message->VEVENT;
627+
$attendees = $vevent->select('ATTENDEE');
628+
foreach ($attendees as $attendee) {
629+
/** @var Property $attendee */
630+
if (strcasecmp($attendee->getValue(), $iTipMessage->sender) === 0) {
631+
return $attendee;
632+
}
633+
}
634+
return null;
635+
}
606636
}

0 commit comments

Comments
 (0)