From 63001969da48cce9c525b2eaffc385540b83523c Mon Sep 17 00:00:00 2001
From: ralf <rb@egroupware.org>
Date: Fri, 16 Sep 2022 11:22:26 +0200
Subject: [PATCH] * Mail/Calendar: fix applying a participant reply as
 organizer overwrote event with data send by the participant (not just his
 status)

---
 calendar/inc/class.calendar_uiforms.inc.php | 22 ++++++++++++++++++++-
 calendar/lang/egw_de.lang                   |  1 +
 calendar/lang/egw_en.lang                   |  1 +
 3 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/calendar/inc/class.calendar_uiforms.inc.php b/calendar/inc/class.calendar_uiforms.inc.php
index 538ed9ef4d..d72bf1f2d2 100644
--- a/calendar/inc/class.calendar_uiforms.inc.php
+++ b/calendar/inc/class.calendar_uiforms.inc.php
@@ -2198,6 +2198,25 @@ class calendar_uiforms extends calendar_ui
 						if ($event['ical_sender_uid'] && $this->bo->check_status_perms($event['ical_sender_uid'], $existing_event))
 						{
 							$existing_status = $existing_event['participants'][$event['ical_sender_uid']];
+							// check if email matches, in case we have now something like "Name <email>"
+							if (!isset($existing_status) && $event['ical_sender_uid'][0] === 'e')
+							{
+								foreach((array)$existing_event['participant_types']['e'] as $email => $status)
+								{
+									if (preg_match('/<(.*)>$/', $email, $matches)) $email = $matches[1];
+									if (strtolower($email) === strtolower($participant))
+									{
+										$existing_status = $status;
+										break;
+									}
+								}
+							}
+							// warn user about party-crashers (non-participants sending a reply)
+							if (!isset($existing_status))
+							{
+								if (!empty($event['sender_warning'])) $event['sender_warning'] .= "\n";
+								$event['sender_warning'] .= lang('Replying "%1" is NOT a participant of the event! Only continue if you want to add as new participant.', $participant);
+							}
 							calendar_so::split_status($existing_status, $quantity, $role);
 							if ($existing_status != $event['ical_sender_status'])
 							{
@@ -2308,7 +2327,8 @@ class calendar_uiforms extends calendar_ui
 
 			$msg = [];
 			// do we need to update the event itself (user-status is reset to old in event_changed!)
-			if ($button !== 'delete' && !empty($event['old']) && self::event_changed($event, $event['old']))
+			if (strtolower($event['ics_method']) !== 'reply' && // do NOT apply (all) data from participants replying
+				$button !== 'delete' && !empty($event['old']) && self::event_changed($event, $event['old']))
 			{
 				// check if we are allowed to update the event
 				if($this->bo->check_perms(Acl::EDIT, $event['old']) || $event['extern_organizer'])
diff --git a/calendar/lang/egw_de.lang b/calendar/lang/egw_de.lang
index 32c247ada7..4b787b4247 100644
--- a/calendar/lang/egw_de.lang
+++ b/calendar/lang/egw_de.lang
@@ -484,6 +484,7 @@ repetition	calendar	de	Wiederholung
 repetitiondetails (or empty)	calendar	de	Details der Wiederholung (oder leer)
 replacements for inserting events into documents	calendar	de	Platzhalter für das Einfügen von Terminen in Dokumente
 reply to meeting request	calendar	de	Antwort auf Terminanfrage
+replying "%1" is not a participant of the event! only continue if you want to add as new participant.	calendar	de	Der antwortende "%1" ist kein Teilnehmer des Termins! Nur weiter machen, wenn Sie ihn als neuen Teilnehmer hinzufügen wollen.
 requested	calendar	de	Erforderlich
 requested date %1 outside allowed range of %2 days: recurring events obmitted!	calendar	de	Gewünschtes Datum %1 außerhalb des erlauben Bereiches von %2 Tagen: wiederholende Termine ausgelassen!
 requested meeting is in the past!	calendar	de	Termin, zu dem eingeladen wird, ist in der Vergangenheit!
diff --git a/calendar/lang/egw_en.lang b/calendar/lang/egw_en.lang
index 4106c24da2..c0088134a0 100644
--- a/calendar/lang/egw_en.lang
+++ b/calendar/lang/egw_en.lang
@@ -483,6 +483,7 @@ repetition	calendar	en	Repetition
 repetitiondetails (or empty)	calendar	en	Repetition details (or empty)
 replacements for inserting events into documents	calendar	en	Replacements for inserting events into documents
 reply to meeting request	calendar	en	Reply to meeting request
+replying "%1" is not a participant of the event! only continue if you want to add as new participant.	calendar	en	Replying "%1" is NOT a participant of the event! Only continue if you want to add as new participant.
 requested	calendar	en	Requested
 requested date %1 outside allowed range of %2 days: recurring events obmitted!	calendar	en	Requested date %1 outside allowed range of %2 days: recurring events obmitted!
 requested meeting is in the past!	calendar	en	Requested meeting is in the past!