diff options
-rw-r--r-- | gnus-icalendar-request-tests.el | 23 | ||||
-rw-r--r-- | gnus-icalendar-request.el | 31 |
2 files changed, 28 insertions, 26 deletions
diff --git a/gnus-icalendar-request-tests.el b/gnus-icalendar-request-tests.el index d92ef2e..413cbd3 100644 --- a/gnus-icalendar-request-tests.el +++ b/gnus-icalendar-request-tests.el @@ -29,7 +29,7 @@ (require 'ert) (require 'gnus-icalendar-request) -(ert-deftest gnus-icalendar--create-vcalendar () +(ert-deftest gnus-icalendar--build-vcalendar-from-vevent () "" (let ((tz (getenv "TZ")) (event "\ @@ -86,7 +86,7 @@ METHOD:REQUEST END:VCALENDAR" event-string)) (event (gnus-icalendar-tests--get-ical-event vcalendar-string)) - (ical (gnus-icalendar-event--ical-from-event event))) + (ical (gnus-icalendar--ical-from-event event))) (should (string-match "^BEGIN:VEVENT$" ical)) (should (string-match "^END:VEVENT$" ical)) (should (string-match "^DTSTAMP:" ical)) @@ -101,13 +101,13 @@ END:VCALENDAR" (should (string-match "^UID:ac44f43e-f5cd-4b0a-878e-add01aeb12dd$" ical)) (should (string-match "^SEQUENCE:0$" ical)))) -(ert-deftest gnus-icalendar-event--create-attendee-list () +(ert-deftest gnus-icalendar--create-attendee-list () "" (let* ((req-part '("Colleague1 <required@company.invalid>" - "Cool Colleague <required2@company.invalid>")) - (opt-part '("My boss <required@company.invalid>")) - (attendees (gnus-icalendar-event--create-attendee-list req-part opt-part)) - (expected-attendee-entry "^ATTENDEE.*;ROLE=%s-PARTICIPANT.*;RSVP=TRUE:mailto:%s.*$")) + "Cool Colleague <required2@company.invalid>")) + (opt-part '("My boss <required@company.invalid>")) + (attendees (gnus-icalendar--create-attendee-list req-part opt-part)) + (expected-attendee-entry "^ATTENDEE.*;ROLE=%s-PARTICIPANT.*;RSVP=TRUE:mailto:%s.*$")) (should (string-match (format expected-attendee-entry "REQ" (nth 0 req-part)) attendees)) @@ -117,12 +117,13 @@ END:VCALENDAR" (should (string-match (format expected-attendee-entry "OPT" (nth 0 opt-part)) attendees)))) -(ert-deftest gnus-icalendar-event--create-empty-required-attendee-list () +(ert-deftest gnus-icalendar--create-empty-required-attendee-list () "" (let* ((req-part nil) - (opt-part '("My boss <required@company.invalid>")) - (attendees (gnus-icalendar-event--create-attendee-list req-part opt-part)) - (expected-attendee-entry "^ATTENDEE.*;ROLE=%s-PARTICIPANT.*;RSVP=TRUE:mailto:%s.*$")) + (opt-part '("My boss <required@company.invalid>")) + (attendees (gnus-icalendar--create-attendee-list req-part opt-part)) + (expected-attendee-entry "^ATTENDEE.*;ROLE=%s-PARTICIPANT.*;RSVP=TRUE:mailto:%s.*$")) (should (string-match (format expected-attendee-entry "OPT" (nth 0 opt-part)) attendees)))) + diff --git a/gnus-icalendar-request.el b/gnus-icalendar-request.el index 67cb927..6942279 100644 --- a/gnus-icalendar-request.el +++ b/gnus-icalendar-request.el @@ -1,6 +1,6 @@ ;;; gnus-icalendar-request.el --- Create icalendar events -*- lexical-binding: t; -*- -;; Copyright (C) 2020 Ferdinand Pieper +;; Copyright (C) 2020,2024 Ferdinand Pieper ;; Author: Ferdinand Pieper <mail@pie.tf> ;; Keywords: mail, icalendar @@ -27,11 +27,11 @@ (require 'gnus-icalendar) -(defun gnus-icalendar-event--format-attendee (attendee role) +(defun gnus-icalendar--format-attendee (attendee role) (when (member role '("req" "opt")) (format "ATTENDEE;PARTSTAT=NEEDS-ACTION;ROLE=%s-PARTICIPANT;RSVP=TRUE:mailto:%s" (upcase role) attendee))) -(defun gnus-icalendar-event--create-attendee-list (req &optional opt role) +(defun gnus-icalendar--create-attendee-list (req &optional opt role) "Format a list of event attendees. REQ is a list of required attendees emails, OPT of optional @@ -39,14 +39,15 @@ attendees and ROLE can be used to override the REQ attendees role." (concat (when req - (mapconcat (lambda (req) (gnus-icalendar-event--format-attendee req (or role "req"))) req "\n")) + (mapconcat + (lambda (req) (gnus-icalendar--format-attendee req (or role "req"))) + req "\n")) (when opt - (concat "\n" - (gnus-icalendar-event--create-attendee-list opt nil "opt")) - ;; (mapconcat (lambda (opt) (gnus-icalendar-event--format-attendee opt "opt")) opt "\n") - ))) + (concat + "\n" + (gnus-icalendar--create-attendee-list opt nil "opt"))))) -(defun gnus-icalendar-event--ical-from-event (event) +(defun gnus-icalendar--ical-from-event (event) (with-slots (summary description location organizer recur uid start-time end-time req-participants opt-participants) event (let ((dtstamp (format-time-string "DTSTAMP:%Y%m%dT%H%M%SZ" nil t)) ;; current UTC time (summary (format "SUMMARY:%s" summary)) @@ -60,7 +61,7 @@ role." (buffer-string))))) ;; TODO: How to do this properly? (dtstart (format-time-string "DTSTART:%Y%m%dT%H%M%SZ" start-time t)) ;; start-time in UTC (dtend (format-time-string "DTEND:%Y%m%dT%H%M%SZ" end-time t)) ;; end-time in UTC - (attendee (gnus-icalendar-event--create-attendee-list req-participants opt-participants)) + (attendee (gnus-icalendar--create-attendee-list req-participants opt-participants)) (location (when (and (stringp location) (not (string-empty-p location))) (format "LOCATION:%s" location))) (organizer (format "ORGANIZER:mailto:%s" organizer)) @@ -97,15 +98,15 @@ role." ,event "END:VCALENDAR") "\n")) -(defun gnus-icalendar-event-message-insert-request (event) +(defun gnus-icalendar-message-insert-request (event) "Insert text/calendar part into message with request for VEVENT specified in EVENT." (when (provided-mode-derived-p major-mode 'message-mode) (mml-insert-part "text/calendar; method=\"REQUEST\"; charset=UTF-8") (insert (gnus-icalendar--build-vcalendar-from-vevent - (gnus-icalendar-event--ical-from-event event))))) + (gnus-icalendar--ical-from-event event))))) -(defun gnus-icalendar-event-from-message-and-insert (&optional date location) +(defun gnus-icalendar-from-message-and-insert (&optional date location) "Create a event request based on the current message. Direct recipients of the message (in To header) are interpreted @@ -162,7 +163,7 @@ or will be asked for if nil. Same for location." location organizer) (format "DTSTART:%s" start-time))) - (event (gnus-icalendar-event-request :uid uid + (event (gnus-icalendar-request :uid uid :recur recur :location location :description description @@ -182,7 +183,7 @@ or will be asked for if nil. Same for location." (mml-insert-part "text/plain") (insert description "\n") (re-search-forward "<#/part>\n")) - (gnus-icalendar-event-message-insert-request event)))) + (gnus-icalendar-message-insert-request event)))) (provide 'gnus-icalendar-request) ;;; gnus-icalendar-request.el ends here |