unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Ferdinand Pieper <list_gnu@pie.tf>
To: Robert Pluim <rpluim@gmail.com>
Cc: Eli Zaretskii <eliz@gnu.org>, Andrew G Cohen <cohen@andy.bu.edu>,
	Alexandre Duret-Lutz <adl@lrde.epita.fr>,
	72831@debbugs.gnu.org
Subject: bug#72831: [PATCH] gnus-icalendar: Allow comments in event replies
Date: Sat, 31 Aug 2024 16:31:24 +0200	[thread overview]
Message-ID: <87zfossr0j.fsf@pie.tf> (raw)
In-Reply-To: <87o75bvk8q.fsf@gmail.com> (Robert Pluim's message of "Thu, 29 Aug 2024 09:52:37 +0200")

[-- Attachment #1: Type: text/plain, Size: 291 bytes --]

The updated patch contains two tests to check replies with and without a comment. Let me know any feedback on these as I have never contributed tests so far and if you prefer to have code and tests split into two commits instead.

Otherwise the patch should be good to be applied?

Thanks!


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Allow-comments-to-organizer-in-event-replies-bug-728.patch --]
[-- Type: text/x-patch, Size: 10672 bytes --]

From 5f75ab29fd0f0fbed5238ffff63c6ce13ce1f8de Mon Sep 17 00:00:00 2001
From: fpi <git@pie.tf>
Date: Wed, 28 Aug 2024 18:33:20 +0200
Subject: [PATCH] Allow comments to organizer in event replies (bug#72831)

* lisp/gnus/gnus-icalendar.el
(gnus-icalendar-event--build-reply-event-body): Add optional COMMENT
argument to be inserted into the reply.
(gnus-icalendar-event-reply-from-buffer): Add COMMENT argument to be
passed through to gnus-icalendar-event--build-reply-event-body
(gnus-icalendar-reply-accept, gnus-icalendar-reply-tentative,
gnus-icalendar-reply-decline): If interactively called with a prefix
argument ask user for a COMMENT to add to the reply.

* test/lisp/gnus/gnus-icalendar-tests.el
(gnus-icalendar-accept-with-comment,
gnus-icalendar-decline-withouth-changing-comment): New tests.
---
 lisp/gnus/gnus-icalendar.el            | 61 +++++++++++++++-------
 test/lisp/gnus/gnus-icalendar-tests.el | 72 ++++++++++++++++++++++++++
 2 files changed, 115 insertions(+), 18 deletions(-)

diff --git a/lisp/gnus/gnus-icalendar.el b/lisp/gnus/gnus-icalendar.el
index af7284b88e8..85f1aa09a56 100644
--- a/lisp/gnus/gnus-icalendar.el
+++ b/lisp/gnus/gnus-icalendar.el
@@ -309,7 +309,7 @@ gnus-icalendar-event-from-buffer
 ;;; gnus-icalendar-event-reply
 ;;;
 
-(defun gnus-icalendar-event--build-reply-event-body (ical-request status identities)
+(defun gnus-icalendar-event--build-reply-event-body (ical-request status identities &optional comment)
   (let ((summary-status (capitalize (symbol-name status)))
         (attendee-status (upcase (symbol-name status)))
         reply-event-lines)
@@ -319,6 +319,10 @@ gnus-icalendar-event--build-reply-event-body
 	  (if (string-match "^[^:]+:" line)
 	      (replace-match (format "\\&%s: " summary-status) t nil line)
 	    line))
+         (update-comment
+           (line)
+           (if comment (format "COMMENT:%s" comment)
+             line))
 	 (update-dtstamp ()
 			 (format-time-string "DTSTAMP:%Y%m%dT%H%M%SZ" nil t))
 	 (attendee-matches-identity
@@ -341,6 +345,7 @@ gnus-icalendar-event--build-reply-event-body
 		    (cond
 		     ((string= key "ATTENDEE") (update-attendee-status line))
 		     ((string= key "SUMMARY") (update-summary line))
+		     ((string= key "COMMENT") (update-comment line))
 		     ((string= key "DTSTAMP") (update-dtstamp))
 		     ((member key '("ORGANIZER" "DTSTART" "DTEND"
 				    "LOCATION" "DURATION" "SEQUENCE"
@@ -363,16 +368,24 @@ gnus-icalendar-event--build-reply-event-body
                       attendee-status user-full-name user-mail-address)
               reply-event-lines))
 
+      ;; add comment line if not existing
+      (when (and comment (not (gnus-icalendar-find-if (lambda (x) (string-match "^COMMENT" x))
+                                                      reply-event-lines)))
+        (push (format "COMMENT:%s" comment) reply-event-lines))
+
       (mapconcat #'identity `("BEGIN:VEVENT"
                               ,@(nreverse reply-event-lines)
                               "END:VEVENT")
                  "\n"))))
 
-(defun gnus-icalendar-event-reply-from-buffer (buf status identities)
+(defun gnus-icalendar-event-reply-from-buffer (buf status identities &optional comment)
   "Build a calendar event reply for request contained in BUF.
 The reply will have STATUS (`accepted', `tentative' or  `declined').
 The reply will be composed for attendees matching any entry
-on the IDENTITIES list."
+on the IDENTITIES list.
+Optional argument COMMENT will be placed in the comment field of the
+reply.
+"
   (cl-labels
       ((extract-block
 	(blockname)
@@ -396,7 +409,7 @@ gnus-icalendar-event-reply-from-buffer
                               "PRODID:Gnus"
                               "VERSION:2.0"
                               zone
-                              (gnus-icalendar-event--build-reply-event-body event status identities)
+                              (gnus-icalendar-event--build-reply-event-body event status identities comment)
                               "END:VCALENDAR")))
 
           (mapconcat #'identity (delq nil contents) "\n"))))))
@@ -878,13 +891,13 @@ gnus-icalendar-send-buffer-by-mail
       (insert "Subject: " subject)
       (message-send-and-exit))))
 
-(defun gnus-icalendar-reply (data)
+(defun gnus-icalendar-reply (data &optional comment)
   (let* ((handle (car data))
          (status (cadr data))
          (event (caddr data))
          (reply (gnus-icalendar-with-decoded-handle handle
                   (gnus-icalendar-event-reply-from-buffer
-                   (current-buffer) status (gnus-icalendar-identities))))
+                   (current-buffer) status (gnus-icalendar-identities) comment)))
          (organizer (gnus-icalendar-event:organizer event)))
 
     (when reply
@@ -1009,25 +1022,37 @@ gnus-icalendar-save-event
     (when data
       (gnus-icalendar-save-part data))))
 
-(defun gnus-icalendar-reply-accept ()
-  "Accept invitation in the current article."
-  (interactive nil gnus-article-mode gnus-summary-mode)
+(defun gnus-icalendar-reply-accept (&optional comment-p)
+  "Accept invitation in the current article.
+
+Optional argument COMMENT-P (interactively the `\\[universal-argument]')
+means prompt for a comment to include in the reply."
+  (interactive "P" gnus-article-mode gnus-summary-mode)
   (with-current-buffer gnus-article-buffer
-    (gnus-icalendar-reply (list gnus-icalendar-handle 'accepted gnus-icalendar-event))
+    (gnus-icalendar-reply (list gnus-icalendar-handle 'accepted gnus-icalendar-event)
+                          (when comment-p (read-string "Comment: ")))
     (setq-local gnus-icalendar-reply-status 'accepted)))
 
-(defun gnus-icalendar-reply-tentative ()
-  "Send tentative response to invitation in the current article."
-  (interactive nil gnus-article-mode gnus-summary-mode)
+(defun gnus-icalendar-reply-tentative (&optional comment-p)
+  "Send tentative response to invitation in the current article.
+
+Optional argument COMMENT-P (interactively the `\\[universal-argument]')
+means prompt for a comment to include in the reply."
+  (interactive "P" gnus-article-mode gnus-summary-mode)
   (with-current-buffer gnus-article-buffer
-    (gnus-icalendar-reply (list gnus-icalendar-handle 'tentative gnus-icalendar-event))
+    (gnus-icalendar-reply (list gnus-icalendar-handle 'tentative gnus-icalendar-event)
+                          (when comment-p (read-string "Comment: ")))
     (setq-local gnus-icalendar-reply-status 'tentative)))
 
-(defun gnus-icalendar-reply-decline ()
-  "Decline invitation in the current article."
-  (interactive nil gnus-article-mode gnus-summary-mode)
+(defun gnus-icalendar-reply-decline (&optional comment-p)
+  "Decline invitation in the current article.
+
+Optional argument COMMENT-P (interactively the `\\[universal-argument]')
+means prompt for a comment to include in the reply."
+  (interactive "P" gnus-article-mode gnus-summary-mode)
   (with-current-buffer gnus-article-buffer
-    (gnus-icalendar-reply (list gnus-icalendar-handle 'declined gnus-icalendar-event))
+    (gnus-icalendar-reply (list gnus-icalendar-handle 'declined gnus-icalendar-event)
+                          (when comment-p (read-string "Comment: ")))
     (setq-local gnus-icalendar-reply-status 'declined)))
 
 (defun gnus-icalendar-event-export ()
diff --git a/test/lisp/gnus/gnus-icalendar-tests.el b/test/lisp/gnus/gnus-icalendar-tests.el
index 08c85013d17..9b4ba383d5a 100644
--- a/test/lisp/gnus/gnus-icalendar-tests.el
+++ b/test/lisp/gnus/gnus-icalendar-tests.el
@@ -255,5 +255,77 @@ gnus-icalendary-weekly-byday
 <2020-09-21 14:00-14:30 +1w>")))
       (setenv "TZ" tz))))
 
+(ert-deftest gnus-icalendar-accept-with-comment ()
+  ""
+  (let ((event "BEGIN:VEVENT
+DTSTART;TZID=Europe/Berlin:20200915T140000
+DTEND;TZID=Europe/Berlin:20200915T143000
+RRULE:FREQ=WEEKLY;BYDAY=FR,MO,TH,TU,WE
+DTSTAMP:20200915T120627Z
+ORGANIZER;CN=anon@anoncompany.com:mailto:anon@anoncompany.com
+UID:7b6g3m7iftuo90ei4ul00feqn_R20200915T120000@google.com
+ATTENDEE;CUTYPE=INDIVIDUAL;PARTSTAT=NEEDS-ACTION;RSVP=TRUE
+ ;CN=participant@anoncompany.com;X-NUM-GUESTS=0:mailto:participant@anoncompany.com
+CREATED:20200325T095723Z
+DESCRIPTION:Coffee talk
+LAST-MODIFIED:20200915T120623Z
+LOCATION:
+SEQUENCE:0
+STATUS:CONFIRMED
+SUMMARY:Casual coffee talk
+TRANSP:OPAQUE
+END:VEVENT")
+        (icalendar-identities '("participant@anoncompany.com")))
+    (unwind-protect
+        (progn
+          (let* ((reply (with-temp-buffer
+                         (insert event)
+                         (gnus-icalendar-event-reply-from-buffer
+                          (current-buffer)
+                          'accepted
+                          icalendar-identities
+                          "Can not stay long."))))
+            (should (string-match "^ATTENDEE;.*?\\(PARTSTAT=[^;]+\\)" reply))
+            (should (string-equal (match-string 1 reply) "PARTSTAT=ACCEPTED"))
+            (should (string-match "^COMMENT:\\(.*\\)$" reply))
+            (should (string-equal (match-string 1 reply) "Can not stay long.")))))))
+
+(ert-deftest gnus-icalendar-decline-withouth-changing-comment ()
+  ""
+  (let ((event "BEGIN:VEVENT
+DTSTART;TZID=Europe/Berlin:20200915T140000
+DTEND;TZID=Europe/Berlin:20200915T143000
+RRULE:FREQ=WEEKLY;BYDAY=FR,MO,TH,TU,WE
+DTSTAMP:20200915T120627Z
+ORGANIZER;CN=anon@anoncompany.com:mailto:anon@anoncompany.com
+UID:7b6g3m7iftuo90ei4ul00feqn_R20200915T120000@google.com
+ATTENDEE;CUTYPE=INDIVIDUAL;PARTSTAT=NEEDS-ACTION;RSVP=TRUE
+ ;CN=participant@anoncompany.com;X-NUM-GUESTS=0:mailto:participant@anoncompany.com
+CREATED:20200325T095723Z
+DESCRIPTION:Coffee talk
+LAST-MODIFIED:20200915T120623Z
+COMMENT:Only available at 2pm
+LOCATION:
+SEQUENCE:0
+STATUS:CONFIRMED
+SUMMARY:Casual coffee talk
+TRANSP:OPAQUE
+END:VEVENT")
+        (icalendar-identities '("participant@anoncompany.com")))
+    (unwind-protect
+        (progn
+          (let* ((reply (with-temp-buffer
+                        (insert event)
+                        (gnus-icalendar-event-reply-from-buffer
+                         (current-buffer)
+                          'declined
+                          icalendar-identities
+                          nil))))
+            (should (string-match "^ATTENDEE;.*?\\(PARTSTAT=[^;]+\\)" reply))
+            (should (string-equal (match-string 1 reply) "PARTSTAT=DECLINED"))
+            (should (string-match "^COMMENT:\\(.*\\)$" reply))
+            (should (string-equal (match-string 1 reply) "Only available at 2pm"))
+                        )))))
+
 (provide 'gnus-icalendar-tests)
 ;;; gnus-icalendar-tests.el ends here
-- 
2.44.1


[-- Attachment #3: Type: text/plain, Size: 1692 bytes --]


Robert Pluim <rpluim@gmail.com> writes:

>>>>>> On Wed, 28 Aug 2024 18:35:55 +0200, Ferdinand Pieper
> <list_gnu@pie.tf> said:
>     >> So if the event was sent with a COMMENT the receiver canʼt add their
>     >> own? That doesnʼt match my conception of 'reply with comment'. Iʼm
>     >> hazy on whatʼs exactly allowed in ical, can you have more than one
>     >> COMMENT line? Or we could combine the comments?
>
>     Ferdinand> If it already exists it is replaced by the prior
>     >> >> ((string= key "COMMENT") (update-comment line))
>     Ferdinand> Just if it does not exist the `(string= key "COMMENT")`
>     Ferdinand> never matches and we have to add the field.
>
> Sorry, I missed that bit.
>
>     >> I think we tend to word this as
>     >> 
>     >> "Optional argument COMMENT-P (interactively the prefix argument) means
>     >> prompt for a comment to include in the reply."
>
>     Ferdinand> Updated using `\\[universal-argument]'. Or does that
>     Ferdinand> not matter here and just "prefix argument" would be
>     Ferdinand> fine?
>
> Either one is fine I think.
>
>     >> Ideally youʼd add test cases for this to
>     >> "test/lisp/gnus/gnus-icalendar-tests.el". But thatʼs not mandatory.
>
>     Ferdinand> I looked into it and will add a few tests for
>     Ferdinand> accepting/declining events with and without comments. I
>     Ferdinand> will followup on this in a couple days.
>     Ferdinand> It might also make sense to extend the parsing of
>     Ferdinand> events to recognize comments (and potentially display
>     Ferdinand> them inside emacs.
>
> That would be good as a followup patch.
>
> Robert

  reply	other threads:[~2024-08-31 14:31 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-27  9:58 bug#72831: [PATCH] gnus-icalendar: Allow comments in event replies Ferdinand Pieper
2024-08-28 11:02 ` Eli Zaretskii
2024-08-28 13:45   ` Robert Pluim
2024-08-28 15:47     ` Eli Zaretskii
2024-08-28 16:35     ` Ferdinand Pieper
2024-08-29  7:52       ` Robert Pluim
2024-08-31 14:31         ` Ferdinand Pieper [this message]
2024-09-07 12:22           ` Ferdinand Pieper
2024-09-07 14:55             ` Eli Zaretskii
2024-09-07 15:05               ` Ferdinand Pieper
2024-09-11  8:13                 ` Robert Pluim

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87zfossr0j.fsf@pie.tf \
    --to=list_gnu@pie.tf \
    --cc=72831@debbugs.gnu.org \
    --cc=adl@lrde.epita.fr \
    --cc=cohen@andy.bu.edu \
    --cc=eliz@gnu.org \
    --cc=rpluim@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).