From 7e8380698a0ad3f1516736dbc4314ecf81c2c526 Mon Sep 17 00:00:00 2001 From: nathan Date: Fri, 10 Nov 2023 10:33:19 -0700 Subject: [PATCH] Calendar: Process multiple VCALENDAR in the same file when importing iCal files --- api/src/CalDAV/IcalIterator.php | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/api/src/CalDAV/IcalIterator.php b/api/src/CalDAV/IcalIterator.php index ba519fbbaf..0abecbd40d 100644 --- a/api/src/CalDAV/IcalIterator.php +++ b/api/src/CalDAV/IcalIterator.php @@ -166,8 +166,29 @@ class IcalIterator extends Horde_Icalendar implements \Iterator // check if end of container reached if ($this->container && $line && substr($line,0,4+strlen($this->base)) === 'END:'.$this->base) { - $this->unread_line($line); // put back end-of-container, to continue to return false - $line = false; + // But maybe there's another one after? + // Try to advance to beginning of next container + $just_checking = []; + while(($next_line = $this->read_line()) && substr($next_line, 0, 6 + strlen($this->base)) !== 'BEGIN:' . $this->base) + { + $just_checking[] = $next_line; + } + if(!$next_line) + { + // No containers after + $this->unread_line($line); // put back end-of-container, to continue to return false + foreach($just_checking as $check_line) + { + $this->unread_line($check_line); + } + return false; + } + // Found start of another container, quietly cross into it and advance + while(($line = $this->read_line()) && strcasecmp(substr($line, 0, 6), 'BEGIN:') !== 0) + { + // ignore it + } + return $line; } //error_log(__METHOD__."() returning ".($line === false ? 'FALSE' : "'$line'"));