From a961b9efb6a8178cd537608157904e703ab457d7 Mon Sep 17 00:00:00 2001 From: fpi Date: Sun, 22 Sep 2024 16:53:34 +0200 Subject: Mostly adhere to gnus-ical-event-request data types participants entries should be a list of stringes. Currently I parse them all participants in one string and separate it later --- gnus-icalendar-request-tests.el | 42 ++++++++++---------------- gnus-icalendar-request.el | 66 ++++++++++++++++++++++------------------- 2 files changed, 51 insertions(+), 57 deletions(-) diff --git a/gnus-icalendar-request-tests.el b/gnus-icalendar-request-tests.el index b9a2954..73a001d 100644 --- a/gnus-icalendar-request-tests.el +++ b/gnus-icalendar-request-tests.el @@ -62,31 +62,21 @@ END:VEVENT")) (ert-deftest gnus-icalendar--ical-from-event () "" - (let* ((event-string "\ -BEGIN:VEVENT -DTSTAMP:20240915T120000Z -DTSTART:20240917T080000Z -DTEND:20240917T100000Z -SUMMARY:Party -DESCRIPTION:Lots of reasons to celebrate! -ATTENDEE;PARTSTAT=NEEDS-ACTION;ROLE=REQ-PARTICIPANT;RSVP=TRUE;CN=Required CN:mailto:required@company.invalid -ATTENDEE;PARTSTAT=NEEDS-ACTION;ROLE=REQ-PARTICIPANT;RSVP=TRUE:mailto:required2@company.invalid -ATTENDEE;PARTSTAT=NEEDS-ACTION;ROLE=OPT-PARTICIPANT;RSVP=TRUE:mailto:optional@company.invalid -LOCATION:Party room -ORGANIZER:mailto:organizer@company.invalid -UID:ac44f43e-f5cd-4b0a-878e-add01aeb12dd -SEQUENCE:0 -END:VEVENT") - (vcalendar-string (format "\ -BEGIN:VCALENDAR -PRODID:-//Google Inc//Google Calendar 70.9054//EN -VERSION:2.0 -CALSCALE:GREGORIAN -METHOD:REQUEST -%s -END:VCALENDAR" - event-string)) - (event (gnus-icalendar-tests--get-ical-event vcalendar-string)) + (let* ((event + (gnus-icalendar-event-request + :uid "ac44f43e-f5cd-4b0a-878e-add01aeb12dd" + :recur nil + :location "Party room" + :description "Lots of reasons to celebrate!" + :summary "Party" + :method "REQUEST" + :organizer "organizer@company.invalid" + :start-time (encode-time '(0 0 8 17 9 2024 nil -1 t)) + :end-time (encode-time '(0 0 10 17 9 2024 nil -1 t)) + :rsvp nil + :participation-type 'non-participant + :req-participants '("Required CN " "required2@company.invalid") + :opt-participants '("optional@company.invalid"))) (ical (gnus-icalendar--ical-from-event event))) (should (string-match "^BEGIN:VEVENT$" ical)) (should (string-match "^END:VEVENT$" ical)) @@ -95,7 +85,7 @@ END:VCALENDAR" (should (string-match "^DTEND:20240917T100000Z$" ical)) (should (string-match "^SUMMARY:Party$" ical)) (should (string-match "^DESCRIPTION:Lots of reasons to celebrate!$" ical)) - (should (string-match "^ATTENDEE;PARTSTAT=NEEDS-ACTION;ROLE=REQ-PARTICIPANT;RSVP=TRUE:mailto:required@company.invalid$" ical)) + (should (string-match "^ATTENDEE;PARTSTAT=NEEDS-ACTION;ROLE=REQ-PARTICIPANT;RSVP=TRUE;CN=Required CN:mailto:required@company.invalid$" ical)) (should (string-match "^ATTENDEE;PARTSTAT=NEEDS-ACTION;ROLE=OPT-PARTICIPANT;RSVP=TRUE:mailto:optional@company.invalid$" ical)) (should (string-match "^LOCATION:Party room$" ical)) (should (string-match "^ORGANIZER:mailto:organizer@company.invalid$" ical)) diff --git a/gnus-icalendar-request.el b/gnus-icalendar-request.el index 498e063..8326eca 100644 --- a/gnus-icalendar-request.el +++ b/gnus-icalendar-request.el @@ -37,15 +37,36 @@ (string-replace "\n" "\\n" description)))) (dtstart (format-time-string "DTSTART:%Y%m%dT%H%M%SZ" start-time t)) ;; in UTC -> suffix "Z" (dtend (format-time-string "DTEND:%Y%m%dT%H%M%SZ" end-time t)) - (attendee (mapconcat - (lambda (p) - (format "ATTENDEE%s" - (gnus-icalendar--format-ical-property-parameters p))) - (append req-participants opt-participants) - "\n")) + (attendee + (mapconcat + (lambda (p) + (format + "ATTENDEE%s" + (gnus-icalendar--format-ical-property-parameters p))) + (append + (mapcar (lambda (entry) + (gnus-icalendar--parse-message-email-to-alist + entry + '((PARTSTAT . "NEEDS-ACTION") + (ROLE . "REQ-PARTICIPANT") + (RSVP . "TRUE")))) + (mail-header-parse-addresses (mapconcat #'identity req-participants ", "))) + (mapcar (lambda (entry) + (gnus-icalendar--parse-message-email-to-alist + entry + '((PARTSTAT . "NEEDS-ACTION") + (ROLE . "OPT-PARTICIPANT") + (RSVP . "TRUE")))) + (mail-header-parse-addresses (mapconcat #'identity opt-participants ", ")))) + "\n")) (location (when (and (stringp location) (not (string-empty-p location))) (format "LOCATION:%s" location))) - (organizer (format "ORGANIZER%s" organizer)) + (organizer (format "ORGANIZER%s" + (gnus-icalendar--format-ical-property-parameters + (gnus-icalendar--parse-message-email-to-alist + (car (mail-header-parse-addresses + organizer)) + )))) (uid (format "UID:%s" uid)) (sequence "SEQUENCE:0") ;; TODO: Consider follow-up event modifications. ;; TODO: handle recur @@ -148,36 +169,19 @@ or will be asked for if nil. Same for location." (summary (save-restriction (message-narrow-to-headers) (message-fetch-field "Subject"))) - (organizer (gnus-icalendar--format-ical-property-parameters - (gnus-icalendar--parse-message-email-to-alist - (car (mail-header-parse-addresses - (save-restriction - (message-narrow-to-headers) - (message-fetch-field "From"))))))) + (organizer (save-restriction + (message-narrow-to-headers) + (message-fetch-field "From"))) (rsvp nil) ;; TODO (participation-type 'non-participant) (req-participants - (mapcar (lambda (entry) - (gnus-icalendar--parse-message-email-to-alist - entry - '((PARTSTAT . "NEEDS-ACTION") - (ROLE . "REQ-PARTICIPANT") - (RSVP . "TRUE")))) - (mail-header-parse-addresses - (save-restriction - (message-narrow-to-headers) - (message-fetch-field "To"))))) + (save-restriction + (message-narrow-to-headers) + (message-fetch-field "To"))) (opt-participants - (mapcar (lambda (entry) - (gnus-icalendar--parse-message-email-to-alist - entry - '((PARTSTAT . "NEEDS-ACTION") - (ROLE . "OPT-PARTICIPANT") - (RSVP . "TRUE")))) - (mail-header-parse-addresses (save-restriction (message-narrow-to-headers) - (message-fetch-field "Cc"))))) + (message-fetch-field "Cc"))) (uid (icalendar--create-uid (format "%s%s%s%s" summary description -- cgit v1.2.3