]> git.notmuchmail.org Git - notmuch/blobdiff - emacs/notmuch-show.el
emacs: Optionally show all parts in multipart/alternative.
[notmuch] / emacs / notmuch-show.el
index a6a43bb568914dada6bc6497b477ec0bef39bf57..3d8431a6e90f5f04b571ba5e8ce7bbe6f608d39e 100644 (file)
@@ -26,6 +26,7 @@
 (require 'message)
 (require 'mm-decode)
 (require 'mailcap)
 (require 'message)
 (require 'mm-decode)
 (require 'mailcap)
+(require 'icalendar)
 
 (require 'notmuch-lib)
 (require 'notmuch-query)
 
 (require 'notmuch-lib)
 (require 'notmuch-query)
@@ -82,6 +83,18 @@ any given message."
             notmuch-wash-elide-blank-lines
             notmuch-wash-excerpt-citations))
 
             notmuch-wash-elide-blank-lines
             notmuch-wash-excerpt-citations))
 
+;; Mostly useful for debugging.
+(defcustom notmuch-show-all-multipart/alternative-parts nil
+  "Should all parts of multipart/alternative parts be shown?"
+  :group 'notmuch
+  :type 'boolean)
+
+(defcustom notmuch-show-indent-multipart nil
+  "Should the sub-parts of a multipart/* part be indented?"
+  ;; dme: Not sure which is a good default.
+  :group 'notmuch
+  :type 'boolean)
+
 (defmacro with-current-notmuch-show-message (&rest body)
   "Evaluate body with current buffer set to the text of current message"
   `(save-excursion
 (defmacro with-current-notmuch-show-message (&rest body)
   "Evaluate body with current buffer set to the text of current message"
   `(save-excursion
@@ -305,25 +318,34 @@ current buffer, if possible."
 (defun notmuch-show-insert-part-multipart/alternative (msg part content-type nth depth declared-type)
   (notmuch-show-insert-part-header nth declared-type content-type nil)
   (let ((chosen-type (car (notmuch-show-multipart/alternative-choose (notmuch-show-multipart/*-to-list part))))
 (defun notmuch-show-insert-part-multipart/alternative (msg part content-type nth depth declared-type)
   (notmuch-show-insert-part-header nth declared-type content-type nil)
   (let ((chosen-type (car (notmuch-show-multipart/alternative-choose (notmuch-show-multipart/*-to-list part))))
-       (inner-parts (plist-get part :content)))
+       (inner-parts (plist-get part :content))
+       (start (point)))
     ;; This inserts all parts of the chosen type rather than just one,
     ;; but it's not clear that this is the wrong thing to do - which
     ;; should be chosen if there are more than one that match?
     (mapc (lambda (inner-part)
            (let ((inner-type (plist-get inner-part :content-type)))
     ;; This inserts all parts of the chosen type rather than just one,
     ;; but it's not clear that this is the wrong thing to do - which
     ;; should be chosen if there are more than one that match?
     (mapc (lambda (inner-part)
            (let ((inner-type (plist-get inner-part :content-type)))
-             (if (string= chosen-type inner-type)
+             (if (or notmuch-show-all-multipart/alternative-parts
+                     (string= chosen-type inner-type))
                  (notmuch-show-insert-bodypart msg inner-part depth)
                (notmuch-show-insert-part-header (plist-get inner-part :id) inner-type inner-type nil " (not shown)"))))
                  (notmuch-show-insert-bodypart msg inner-part depth)
                (notmuch-show-insert-part-header (plist-get inner-part :id) inner-type inner-type nil " (not shown)"))))
-         inner-parts))
+         inner-parts)
+
+    (when notmuch-show-indent-multipart
+      (indent-rigidly start (point) 1)))
   t)
 
 (defun notmuch-show-insert-part-multipart/* (msg part content-type nth depth declared-type)
   t)
 
 (defun notmuch-show-insert-part-multipart/* (msg part content-type nth depth declared-type)
-  (let ((inner-parts (plist-get part :content)))
-    (notmuch-show-insert-part-header nth declared-type content-type nil)
+  (notmuch-show-insert-part-header nth declared-type content-type nil)
+  (let ((inner-parts (plist-get part :content))
+       (start (point)))
     ;; Show all of the parts.
     (mapc (lambda (inner-part)
            (notmuch-show-insert-bodypart msg inner-part depth))
     ;; Show all of the parts.
     (mapc (lambda (inner-part)
            (notmuch-show-insert-bodypart msg inner-part depth))
-         inner-parts))
+         inner-parts)
+
+    (when notmuch-show-indent-multipart
+      (indent-rigidly start (point) 1)))
   t)
 
 (defun notmuch-show-insert-part-message/rfc822 (msg part content-type nth depth declared-type)
   t)
 
 (defun notmuch-show-insert-part-message/rfc822 (msg part content-type nth depth declared-type)
@@ -357,6 +379,24 @@ current buffer, if possible."
        (run-hook-with-args 'notmuch-show-insert-text/plain-hook depth))))
   t)
 
        (run-hook-with-args 'notmuch-show-insert-text/plain-hook depth))))
   t)
 
+(defun notmuch-show-insert-part-text/x-vcalendar (msg part content-type nth depth declared-type)
+  (notmuch-show-insert-part-header nth declared-type content-type (plist-get part :filename))
+  (insert (with-temp-buffer
+           (insert (notmuch-show-get-bodypart-content msg part nth))
+           (goto-char (point-min))
+           (let ((file (make-temp-file "notmuch-ical"))
+                 result)
+             (icalendar--convert-ical-to-diary
+              (icalendar--read-element nil nil)
+              file t)
+             (set-buffer (get-file-buffer file))
+             (setq result (buffer-substring (point-min) (point-max)))
+             (set-buffer-modified-p nil)
+             (kill-buffer (current-buffer))
+             (delete-file file)
+             result)))
+  t)
+
 (defun notmuch-show-insert-part-application/octet-stream (msg part content-type nth depth declared-type)
   ;; If we can deduce a MIME type from the filename of the attachment,
   ;; do so and pass it on to the handler for that type.
 (defun notmuch-show-insert-part-application/octet-stream (msg part content-type nth depth declared-type)
   ;; If we can deduce a MIME type from the filename of the attachment,
   ;; do so and pass it on to the handler for that type.