Skip to content

Commit

Permalink
fix(dav): Parse sender PARTSTAT in REPLYs
Browse files Browse the repository at this point in the history
Signed-off-by: Anna Larch <anna@nextcloud.com>
  • Loading branch information
miaulalala committed Apr 13, 2023
1 parent f37b29e commit fd85c86
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
4 changes: 3 additions & 1 deletion apps/dav/lib/CalDAV/Schedule/IMipPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,12 @@ public function schedule(Message $iTipMessage) {

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

$replyingAttendee = null;
switch (strtolower($iTipMessage->method)) {
case self::METHOD_REPLY:
$method = self::METHOD_REPLY;
$data = $this->imipService->buildBodyData($vEvent, $oldVevent);
$replyingAttendee = $this->imipService->getReplyingAttendee($iTipMessage);
break;
case self::METHOD_CANCEL:
$method = self::METHOD_CANCEL;
Expand Down Expand Up @@ -256,7 +258,7 @@ public function schedule(Message $iTipMessage) {
$template = $this->mailer->createEMailTemplate('dav.calendarInvite.' . $method, $data);
$template->addHeader();

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

// Only add response buttons to invitation requests: Fix Issue #11230
Expand Down
34 changes: 32 additions & 2 deletions apps/dav/lib/CalDAV/Schedule/IMipService.php
Original file line number Diff line number Diff line change
Expand Up @@ -366,15 +366,32 @@ public function getAttendeeRsvpOrReqForParticipant(?Property $attendee = null) {
* @param bool $isModified
*/
public function addSubjectAndHeading(IEMailTemplate $template,
string $method, string $sender, string $summary, bool $isModified): void {
string $method, string $sender, string $summary, bool $isModified, ?Property $replyingAttendee = null): void {
if ($method === IMipPlugin::METHOD_CANCEL) {
// TRANSLATORS Subject for email, when an invitation is cancelled. Ex: "Cancelled: {{Event Name}}"
$template->setSubject($this->l10n->t('Cancelled: %1$s', [$summary]));
$template->addHeading($this->l10n->t('"%1$s" has been canceled', [$summary]));
} elseif ($method === IMipPlugin::METHOD_REPLY) {
// TRANSLATORS Subject for email, when an invitation is replied to. Ex: "Re: {{Event Name}}"
$template->setSubject($this->l10n->t('Re: %1$s', [$summary]));
$template->addHeading($this->l10n->t('%1$s has responded to your invitation', [$sender]));
// Build the strings
$partstat = (isset($replyingAttendee)) ? $replyingAttendee->offsetGet('PARTSTAT') : null;
$partstat = ($partstat instanceof Parameter) ? $partstat->getValue() : null;
switch ($partstat) {
case 'ACCEPTED':
$template->addHeading($this->l10n->t('%1$s has accepted your invitation', [$sender]));
break;
case 'TENTATIVE':
$template->addHeading($this->l10n->t('%1$s has tentatively accepted your invitation', [$sender]));
break;
case 'DECLINED':
$template->addHeading($this->l10n->t('%1$s has declined your invitation', [$sender]));
break;
case null:
default:
$template->addHeading($this->l10n->t('%1$s has responded to your invitation', [$sender]));
break;
}
} elseif ($method === IMipPlugin::METHOD_REQUEST && $isModified) {
// TRANSLATORS Subject for email, when an invitation is updated. Ex: "Invitation updated: {{Event Name}}"
$template->setSubject($this->l10n->t('Invitation updated: %1$s', [$summary]));
Expand Down Expand Up @@ -603,4 +620,17 @@ public function addMoreOptionsButton(IEMailTemplate $template, $token) {

$template->addBodyText($html, $text);
}

public function getReplyingAttendee(Message $iTipMessage): ?Property {
/** @var VEvent $vevent */
$vevent = $iTipMessage->message->VEVENT;
$attendees = $vevent->select('ATTENDEE');
foreach ($attendees as $attendee) {
/** @var Property $attendee */
if (strcasecmp($attendee->getValue(), $iTipMessage->sender) === 0) {
return $attendee;
}
}
return null;
}
}

0 comments on commit fd85c86

Please sign in to comment.