mirror of https://github.com/djcb/mu.git
mu4e-icalendar: update for new composer
Rework a bit for the new composer; and make the calendar-support "built-in".
This commit is contained in:
parent
b2f3a63a3a
commit
8be95f2616
|
@ -1,4 +1,4 @@
|
||||||
;;; mu4e-icalendar.el --- iCcalendar & diary integration -*- lexical-binding: t; -*-
|
;;; mu4e-icalendar.el --- iCalendar & diary integration -*- lexical-binding: t; -*-
|
||||||
|
|
||||||
;; Copyright (C) 2019-2023 Christophe Troestler
|
;; Copyright (C) 2019-2023 Christophe Troestler
|
||||||
|
|
||||||
|
@ -56,7 +56,6 @@
|
||||||
(require 'mu4e-helpers)
|
(require 'mu4e-helpers)
|
||||||
(require 'mu4e-contacts)
|
(require 'mu4e-contacts)
|
||||||
(require 'mu4e-headers)
|
(require 'mu4e-headers)
|
||||||
(require 'mu4e-view)
|
|
||||||
(require 'mu4e-obsolete)
|
(require 'mu4e-obsolete)
|
||||||
|
|
||||||
|
|
||||||
|
@ -79,21 +78,6 @@
|
||||||
:group 'mu4e-icalendar)
|
:group 'mu4e-icalendar)
|
||||||
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun mu4e-icalendar-setup ()
|
|
||||||
"Perform the necessary initialization to use mu4e-icalendar."
|
|
||||||
(gnus-icalendar-setup)
|
|
||||||
(cl-defmethod gnus-icalendar-event:inline-reply-buttons :around
|
|
||||||
((event gnus-icalendar-event) handle)
|
|
||||||
(if (and (boundp 'mu4e--view-rendering)
|
|
||||||
(gnus-icalendar-event:rsvp event))
|
|
||||||
(let ((method (gnus-icalendar-event:method event)))
|
|
||||||
(when (or (string= method "REQUEST") (string= method "PUBLISH"))
|
|
||||||
`(("Accept" mu4e-icalendar-reply (,handle accepted ,event))
|
|
||||||
("Tentative" mu4e-icalendar-reply (,handle tentative ,event))
|
|
||||||
("Decline" mu4e-icalendar-reply (,handle declined ,event)))))
|
|
||||||
(cl-call-next-method event handle))))
|
|
||||||
|
|
||||||
(defun mu4e--icalendar-has-email (email list)
|
(defun mu4e--icalendar-has-email (email list)
|
||||||
"Check that EMAIL is in LIST."
|
"Check that EMAIL is in LIST."
|
||||||
(let ((email (downcase email)))
|
(let ((email (downcase email)))
|
||||||
|
@ -101,6 +85,14 @@
|
||||||
(and (stringp e) (string= email (downcase e)))))
|
(and (stringp e) (string= email (downcase e)))))
|
||||||
list)))
|
list)))
|
||||||
|
|
||||||
|
(declare-function mu4e--view-mode-p "mu4e-view")
|
||||||
|
(defun mu4e--icalendar-reply (orig data)
|
||||||
|
"Wrapper for using either `mu4e-icalender-reply' or the ORIG function."
|
||||||
|
(funcall (if (mu4e--view-mode-p) #'mu4e-icalendar-reply orig) data))
|
||||||
|
|
||||||
|
(advice-add #'gnus-icalendar-reply :around #'mu4e--icalendar-reply)
|
||||||
|
;;(advice-remove #'gnus-icalendar-reply #'mu4e--icalendar-reply)
|
||||||
|
|
||||||
(defun mu4e-icalendar-reply (data)
|
(defun mu4e-icalendar-reply (data)
|
||||||
"Reply to the text/calendar event present in DATA."
|
"Reply to the text/calendar event present in DATA."
|
||||||
;; Based on `gnus-icalendar-reply'.
|
;; Based on `gnus-icalendar-reply'.
|
||||||
|
@ -118,70 +110,55 @@
|
||||||
(when reply
|
(when reply
|
||||||
(cl-labels
|
(cl-labels
|
||||||
((fold-icalendar-buffer
|
((fold-icalendar-buffer
|
||||||
()
|
()
|
||||||
(goto-char (point-min))
|
(goto-char (point-min))
|
||||||
(while (re-search-forward "^\\(.\\{72\\}\\)\\(.+\\)$" nil t)
|
(while (re-search-forward "^\\(.\\{72\\}\\)\\(.+\\)$" nil t)
|
||||||
(replace-match "\\1\n \\2")
|
(replace-match "\\1\n \\2")
|
||||||
(goto-char (line-beginning-position)))))
|
(goto-char (line-beginning-position)))))
|
||||||
|
|
||||||
(let ((ical-name gnus-icalendar-reply-bufname))
|
(let ((ical-name gnus-icalendar-reply-bufname))
|
||||||
(with-current-buffer (get-buffer-create ical-name)
|
(with-current-buffer (get-buffer-create ical-name)
|
||||||
(delete-region (point-min) (point-max))
|
(delete-region (point-min) (point-max))
|
||||||
(insert reply)
|
(insert reply)
|
||||||
(fold-icalendar-buffer)
|
(fold-icalendar-buffer)
|
||||||
(when (and charset (string= (downcase charset) "utf-8"))
|
(when (and charset (string= (downcase charset) "utf-8"))
|
||||||
(decode-coding-region (point-min) (point-max) 'utf-8)))
|
(decode-coding-region (point-min) (point-max) 'utf-8)))
|
||||||
;; Compose the reply message.
|
|
||||||
(save-excursion
|
(save-excursion ;; Compose the reply message.
|
||||||
(let ((message-signature nil)
|
(let* ((message-signature nil)
|
||||||
(message-cite-function #'mu4e--icalendar-delete-citation)
|
(organizer (gnus-icalendar-event:organizer event))
|
||||||
(mu4e-sent-messages-behavior 'delete)
|
(organizer (when (and organizer
|
||||||
(mu4e-compose-reply-recipients 'sender)
|
(not (string-empty-p organizer)))
|
||||||
(ical-msg (cl-copy-list msg)))
|
organizer))
|
||||||
;; Make sure the reply is sent to email of the organiser with
|
(organizer (or organizer
|
||||||
;; proper name.
|
(car (plist-get msg :reply-to))
|
||||||
(let* ((organizer (gnus-icalendar-event:organizer event))
|
(car (plist-get msg :from))
|
||||||
(reply-to (car (plist-get msg :reply-to)))
|
(mu4e-warn "Cannot find organizer"))))
|
||||||
(from (car (plist-get msg :from)))
|
|
||||||
(name (or (plist-get reply-to :name)
|
|
||||||
(plist-get from :name))))
|
|
||||||
;; Add :reply-to field when incomplete or absent
|
|
||||||
(unless (or (string= organizer "")
|
|
||||||
(mu4e--icalendar-has-email organizer reply-to))
|
|
||||||
(plist-put ical-msg :reply-to
|
|
||||||
`((:name ,name :email ,organizer))))
|
|
||||||
(plist-put ical-msg :subject
|
|
||||||
(concat (capitalize (symbol-name status))
|
|
||||||
": " (gnus-icalendar-event:summary event))))
|
|
||||||
(mu4e--compose-setup
|
(mu4e--compose-setup
|
||||||
'reply ical-msg
|
'reply
|
||||||
`((:buffer-name ,ical-name
|
(lambda (_parent)
|
||||||
:mime-type "text/calendar; method=REPLY; charset=utf-8")))
|
(message-reply organizer)
|
||||||
(message-goto-body)
|
(goto-char (point-max))
|
||||||
(set-buffer-modified-p nil); not yet modified by user
|
(message-goto-body)
|
||||||
(when mu4e-icalendar-trash-after-reply
|
(mml-insert-multipart "alternative")
|
||||||
;; Override `mu4e-sent-handler' set by `mu4e-compose-mode' to
|
(mml-insert-empty-tag 'part 'type "text/plain")
|
||||||
;; also trash the message (thus must be appended to hooks).
|
(mml-attach-buffer ical-name
|
||||||
(add-hook 'message-sent-hook
|
"text/calendar; method=REPLY; charset=UTF-8")
|
||||||
(mu4e--icalendar-trash-message-hook msg)
|
(when mu4e-icalendar-trash-after-reply
|
||||||
90 t)))))
|
;; Override `mu4e-sent-handler' set by `mu4e-compose-mode' to
|
||||||
|
;; also trash the message (thus must be appended to hooks).
|
||||||
|
(add-hook 'message-sent-hook
|
||||||
|
(mu4e--icalendar-trash-message-hook msg) 90 t))))
|
||||||
|
|
||||||
;; Back in article buffer
|
(when gnus-icalendar-org-enabled-p
|
||||||
(setq-local gnus-icalendar-reply-status status)
|
(if (gnus-icalendar-find-org-event-file event)
|
||||||
|
(gnus-icalendar--update-org-event event status)
|
||||||
(when gnus-icalendar-org-enabled-p
|
(gnus-icalendar:org-event-save event status)))
|
||||||
(if (gnus-icalendar-find-org-event-file event)
|
(when mu4e-icalendar-diary-file
|
||||||
(gnus-icalendar--update-org-event event status)
|
(mu4e--icalendar-insert-diary event status
|
||||||
(gnus-icalendar:org-event-save event status)))
|
mu4e-icalendar-diary-file)))))))))
|
||||||
(when mu4e-icalendar-diary-file
|
|
||||||
(mu4e--icalendar-insert-diary event status
|
|
||||||
mu4e-icalendar-diary-file))))))
|
|
||||||
|
|
||||||
(defun mu4e--icalendar-delete-citation ()
|
|
||||||
"Function passed to `mu4e-compose-cite-function' to remove the citation."
|
|
||||||
(message-cite-original-without-signature)
|
|
||||||
(kill-region (point-min) (point-max)))
|
|
||||||
|
|
||||||
|
(declare-function mu4e-view-headers-next "mu4e-view")
|
||||||
(defun mu4e--icalendar-trash-message (original-msg)
|
(defun mu4e--icalendar-trash-message (original-msg)
|
||||||
"Trash the message ORIGINAL-MSG and move to the next one."
|
"Trash the message ORIGINAL-MSG and move to the next one."
|
||||||
(lambda (docid path)
|
(lambda (docid path)
|
||||||
|
@ -201,7 +178,7 @@
|
||||||
(kill-buffer-and-window))))))
|
(kill-buffer-and-window))))))
|
||||||
|
|
||||||
(defun mu4e--icalendar-trash-message-hook (original-msg)
|
(defun mu4e--icalendar-trash-message-hook (original-msg)
|
||||||
"Trash the icalender message ORIGINAL-MSG."
|
"Trash the iCalendar message ORIGINAL-MSG."
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(setq mu4e-sent-func
|
(setq mu4e-sent-func
|
||||||
(mu4e--icalendar-trash-message original-msg))))
|
(mu4e--icalendar-trash-message original-msg))))
|
||||||
|
|
Loading…
Reference in New Issue