From 834582b7bd7ca38b2710a1bf7831a0976f1a05d0 Mon Sep 17 00:00:00 2001 From: Christophe Troestler Date: Thu, 18 Apr 2019 23:11:57 +0200 Subject: [PATCH] mu4e (ical): Optionally save ical events to a diary file upon reply --- mu4e/mu4e-icalendar.el | 39 ++++++++++++++++++++++++++++++++------- mu4e/mu4e-vars.el | 16 ++++++++++++++++ 2 files changed, 48 insertions(+), 7 deletions(-) diff --git a/mu4e/mu4e-icalendar.el b/mu4e/mu4e-icalendar.el index fc7cb52b..59ed9bcd 100644 --- a/mu4e/mu4e-icalendar.el +++ b/mu4e/mu4e-icalendar.el @@ -8,6 +8,7 @@ ;; To enable optional iCalendar->Org sync functionality ;; NOTE: both the capture file and the headline(s) inside must already exist +;; (require 'org-agenda) ;; (setq gnus-icalendar-org-capture-file "~/org/notes.org") ;; (setq gnus-icalendar-org-capture-headline '("Calendar")) ;; (gnus-icalendar-org-setup) @@ -58,13 +59,15 @@ (fold-icalendar-buffer) (mu4e-icalendar-reply-ical msg event status (buffer-name))) - ;; Back in article buffer - (setq-local gnus-icalendar-reply-status status) - (when gnus-icalendar-org-enabled-p - (gnus-icalendar--update-org-event event status) - ;; refresh article buffer to update the reply status - (with-current-buffer mu4e~headers-buffer-name - (mu4e-headers-rerun-search))))))) + ;; Back in article buffer + (setq-local gnus-icalendar-reply-status status) + (when gnus-icalendar-org-enabled-p + (gnus-icalendar--update-org-event event status)) + (when mu4e-icalendar-diary-file + (mu4e~icalendar-insert-diary event status mu4e-icalendar-diary-file)) + ;; refresh article buffer to update the reply status + (with-current-buffer mu4e~headers-buffer-name + (mu4e-headers-rerun-search)))))) (defun mu4e~icalendar-delete-citation () (delete-region (point-min) (point-max))) @@ -98,6 +101,28 @@ )) +(defun mu4e~icalendar-insert-diary (event reply-status filename) + "Insert a diary entry for the EVENT with reply STATUS in FILE." + ;; FIXME: handle recurring events + (let* ((beg (gnus-icalendar-event:start-time event)) + (beg-date (format-time-string "%d/%m/%Y" beg)) + (beg-time (format-time-string "%H:%M" beg)) + (end (gnus-icalendar-event:end-time event)) + (end-date (format-time-string "%d/%m/%Y" end)) + (end-time (format-time-string "%H:%M" end)) + (summary (gnus-icalendar-event:summary event)) + (location (gnus-icalendar-event:location event)) + (status (capitalize (symbol-name reply-status))) + (txt (if location + (format "%s (%s)\n %s " summary status location) + (format "%s (%s)" summary status)))) + (with-temp-buffer + (if (string= beg-date end-date) + (insert beg-date " " beg-time "-" end-time " " txt "\n") + (insert beg-date " " beg-time " Start of: " txt "\n") + (insert beg-date " " end-time " End of: " txt "\n")) + (write-region (point-min) (point-max) filename t)))) + (provide 'mu4e-icalendar) ;;; mu4e-icalendar.el ends here diff --git a/mu4e/mu4e-vars.el b/mu4e/mu4e-vars.el index 5a0dd0f8..51c23c4b 100644 --- a/mu4e/mu4e-vars.el +++ b/mu4e/mu4e-vars.el @@ -439,6 +439,22 @@ Useful when this is not equal to the From: address." This is the message being replied to, forwarded or edited; used in `mu4e-compose-pre-hook'. For new messages, it is nil.") +(defgroup mu4e-icalendar nil + "Icalendar related settings." + :group 'mu4e) + +(defcustom mu4e-icalendar-trash-after-reply nil + "If non-nil, trash the icalendar invitation after replying." + :type 'boolean + :group 'mu4e-icalendar) + +(defcustom mu4e-icalendar-diary-file nil + "If non-nil, the file in which to add events upon reply." + :type '(choice (const :tag "Do not insert a diary entry" nil) + (string :tag "Insert a diary entry in this file")) + :group 'mu4e-icalendar) + + ;; Folders (defgroup mu4e-folders nil "Special folders."