diff --git a/bin/calendar b/bin/calendar index 9294aa9..4e6b73a 100755 --- a/bin/calendar +++ b/bin/calendar @@ -31,9 +31,14 @@ function caldavRequest(startDate, endDate) { const url = new URL(`/remote.php/dav/calendars/${USER}/${CALENDAR}/`, BASE_URL); const auth = Buffer.from(`${USER}:${PASS}`).toString('base64'); + // Use calendar-multiget with expand to get expanded recurrences const body = ` - + + + + + @@ -68,15 +73,17 @@ function caldavRequest(startDate, endDate) { function parseEvents(xmlData) { const events = []; + // Strip carriage returns (raw and XML-encoded) from entire response + xmlData = xmlData.replace(/\r/g, '').replace(/ /g, ''); const eventBlocks = xmlData.split('BEGIN:VEVENT'); for (let i = 1; i < eventBlocks.length; i++) { const block = eventBlocks[i].split('END:VEVENT')[0]; const get = (key) => { - // Handle both folded and unfolded lines + // Handle both folded and unfolded lines, strip \r const regex = new RegExp(`${key}[^:]*:(.+?)(?:\\r?\\n(?! ))`, 's'); const m = block.match(regex); - return m ? m[1].replace(/\r?\n\s/g, '').trim() : null; + return m ? m[1].replace(/\r?\n\s/g, '').replace(/\r/g, '').trim() : null; }; const summary = get('SUMMARY');