unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [WIP PATCH] emacs: show: reply to calendar parts
@ 2016-07-15 21:31 Mark Walters
  2019-01-14 19:18 ` Gregor Zattler
  0 siblings, 1 reply; 2+ messages in thread
From: Mark Walters @ 2016-07-15 21:31 UTC (permalink / raw)
  To: notmuch

This allows the user to reply to calendar parts. To reply go to the
text/calendar part and use ". c", then select accept, decline, or
tentative. Notmuch gives a reply buffer ready to send as the response.
For the moment this must be sent manually (C-c C-c as normal).
---

This is a first pass at allowing the user to reply to calendar
invites. Emacs (at least emacs 24) has gnus-icalendar which contains
all the things necessary for gnus to reply to calendar parts. This
wraps some of the functions for gnus-icalendar so they work from notmuch.

This version does not send the reply automatically, so it is possible
to review the reply before sending.

It appears to work with google calendar and outlook invites, but is
not heavily tested. Please do not use for "important" things!

If people find it works then I will think about how to polish
it. Feedback of any sort very gratefully received!

Best wishes

Mark



 emacs/notmuch-show.el | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 58 insertions(+)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 6d3149b..1de4ca8 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -30,6 +30,7 @@
 (require 'mailcap)
 (require 'icalendar)
 (require 'goto-addr)
+(eval-when-compile (require 'gnus-icalendar))
 
 (require 'notmuch-lib)
 (require 'notmuch-tag)
@@ -1403,6 +1404,7 @@ reset based on the original query."
     (define-key map "v" 'notmuch-show-view-part)
     (define-key map "o" 'notmuch-show-interactively-view-part)
     (define-key map "|" 'notmuch-show-pipe-part)
+    (define-key map "c" 'notmuch-show-calendar-reply-part)
     (define-key map "?" 'notmuch-subkeymap-help)
     map)
   "Submap for part commands")
@@ -2399,6 +2401,62 @@ is destroyed when FN returns."
   (interactive)
   (notmuch-show-apply-to-current-part-handle #'mm-pipe-part))
 
+;; The following are modelled on the corresponding functions in
+;; gnus-icalendar.el
+(defun notmuch-show-icalendar-send-buffer-by-mail (calendar-reply status)
+  (let ((message-signature nil))
+    (notmuch-show-reply-sender)
+    (message-goto-body)
+    (delete-region (point) (point-max))
+    (mml-insert-multipart "alternative")
+    (mml-insert-empty-tag 'part 'type "text/plain")
+    (mml-insert-part "text/calendar; method=REPLY; charset=UTF-8")
+    (insert calendar-reply "\n")
+
+    (let* ((re-subject
+	    (save-restriction
+	      (message-narrow-to-headers-or-head)
+	      (message-fetch-field "subject")))
+	   (subject (concat (capitalize (symbol-name status))
+			    (substring re-subject 2))))
+      (message-goto-subject)
+      (delete-region (line-beginning-position) (line-end-position))
+      (insert "Subject: " subject)
+      (message-goto-body))))
+
+(defun notmuch-show-icalendar-reply (status handle)
+  (let* ((reply (gnus-icalendar-with-decoded-handle handle
+                  (gnus-icalendar-event-reply-from-buffer
+                   (current-buffer) status (notmuch-user-emails)))))
+    (when reply
+      (with-temp-buffer
+	(insert reply)
+	(goto-char (point-min))
+	(while (re-search-forward "^\\(.\\{72\\}\\)\\(.+\\)$" nil t)
+	  (replace-match "\\1\n \\2")
+	  (goto-char (line-beginning-position)))
+	(buffer-substring-no-properties (point-min) (point-max))))))
+
+(defun notmuch-show-calendar-reply-part ()
+  "Reply to calendar invite."
+  (interactive)
+  (let* ((part (notmuch-show-get-part-properties))
+	 (computed-type (plist-get part :computed-type)))
+    (unless (notmuch-match-content-type computed-type "text/calendar")
+      (error "Not a calendar part!"))
+    (require 'gnus-icalendar)
+    (let* ((str-status (completing-read "Accept, decline or tentative? "
+					(list "accept" "decline" "tentative") nil 't))
+	   (status (pcase str-status
+		     ("accept" 'accepted)
+		     ("decline" 'declined)
+		     ("tentative" 'tentative))))
+      (when status
+	(let ((calendar-part
+	       (notmuch-show-apply-to-current-part-handle
+		(apply-partially #'notmuch-show-icalendar-reply status))))
+	  ;; Back in show buffer
+	  (notmuch-show-icalendar-send-buffer-by-mail calendar-part status))))))
 
 (provide 'notmuch-show)
 
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [WIP PATCH] emacs: show: reply to calendar parts
  2016-07-15 21:31 [WIP PATCH] emacs: show: reply to calendar parts Mark Walters
@ 2019-01-14 19:18 ` Gregor Zattler
  0 siblings, 0 replies; 2+ messages in thread
From: Gregor Zattler @ 2019-01-14 19:18 UTC (permalink / raw)
  To: Mark Walters; +Cc: notmuch

Hi Mark,
* Mark Walters <markwalters1009@gmail.com> [2016-07-15; 22:31]:
> This allows the user to reply to calendar parts. To reply go to the
> text/calendar part and use ". c", then select accept, decline, or
> tentative. Notmuch gives a reply buffer ready to send as the response.
> For the moment this must be sent manually (C-c C-c as normal).
> ---
>
> This is a first pass at allowing the user to reply to calendar
> invites. Emacs (at least emacs 24) has gnus-icalendar which contains
> all the things necessary for gnus to reply to calendar parts. This
> wraps some of the functions for gnus-icalendar so they work from notmuch.
>
> This version does not send the reply automatically, so it is possible
> to review the reply before sending.
>
> It appears to work with google calendar and outlook invites, but is
> not heavily tested. Please do not use for "important" things!
>
> If people find it works then I will think about how to polish
> it. Feedback of any sort very gratefully received!

I sent me an calendar invitation via the Open Exchange web
interface, was able to reply within notmuch, Open Exchange
recognised the reply as containing a date.  Open Exchange showed
a button to accept changes to the calendar, when I click on this
button a notification appears, stating that the appointment was
actualised.

So I think your patch mostly works.

But sadly in Open Exchenge the calendar the status of the
appointment stays the same: There is no hint, that the invitation
was replied to, neither "accept" nor "decline" appear there: The
person who created the appointment is shown with a checked
checkbox in color green, such a sign does not show up for the
person who was invited.
I cannot say who is to blame for this, since I don't know the
first thing about this.

I could provide the accept/decline mails if needed.



Thanks for your patch, I wished for such functionality in
notmuch.


Ciao; Gregor 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-01-14 19:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-15 21:31 [WIP PATCH] emacs: show: reply to calendar parts Mark Walters
2019-01-14 19:18 ` Gregor Zattler

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.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).