X-Git-Url: https://git.notmuchmail.org/git?a=blobdiff_plain;f=emacs%2Fnotmuch-show.el;h=20f89970a00a7008fadf818e5873662c12c48c06;hb=33434d76f3fdb6f0602ab50bd9e72f5f12ce3e4b;hp=d061367e82a3da89db04bdd27ede1ab6ea67604b;hpb=7c6ac9fbae354cf0f5dd1686476a99f2420bc689;p=notmuch diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el index d061367e..20f89970 100644 --- a/emacs/notmuch-show.el +++ b/emacs/notmuch-show.el @@ -203,9 +203,10 @@ For example, if you wanted to remove an \"unread\" tag and add a (let ((id (notmuch-show-get-message-id))) (let ((buf (generate-new-buffer (concat "*notmuch-msg-" id "*")))) (with-current-buffer buf - (call-process notmuch-command nil t nil "show" "--format=raw" id) - ,@body) - (kill-buffer buf))))) + (let ((coding-system-for-read 'no-conversion)) + (call-process notmuch-command nil t nil "show" "--format=raw" id) + ,@body) + (kill-buffer buf)))))) (defun notmuch-show-turn-on-visual-line-mode () "Enable Visual Line mode." @@ -365,9 +366,10 @@ operation on the contents of the current buffer." 'face 'notmuch-tag-face) ")")))))) -(defun notmuch-show-clean-address (address) - "Try to clean a single email ADDRESS for display. Return -unchanged ADDRESS if parsing fails." +(defun notmuch-clean-address (address) + "Try to clean a single email ADDRESS for display. Return a cons +cell of (AUTHOR_EMAIL AUTHOR_NAME). Return (ADDRESS nil) if +parsing fails." (condition-case nil (let (p-name p-address) ;; It would be convenient to use `mail-header-parse-address', @@ -415,12 +417,20 @@ unchanged ADDRESS if parsing fails." (when (string= p-name p-address) (setq p-name nil)) - ;; If no name results, return just the address. - (if (not p-name) - p-address - ;; Otherwise format the name and address together. - (concat p-name " <" p-address ">"))) - (error address))) + (cons p-address p-name)) + (error (cons address nil)))) + +(defun notmuch-show-clean-address (address) + "Try to clean a single email ADDRESS for display. Return +unchanged ADDRESS if parsing fails." + (let* ((clean-address (notmuch-clean-address address)) + (p-address (car clean-address)) + (p-name (cdr clean-address))) + ;; If no name, return just the address. + (if (not p-name) + p-address + ;; Otherwise format the name and address together. + (concat p-name " <" p-address ">")))) (defun notmuch-show-insert-headerline (headers date tags depth) "Insert a notmuch style headerline based on HEADERS for a @@ -747,17 +757,22 @@ message at DEPTH in the current thread." (notmuch-show-insert-part-header nth declared-type content-type (plist-get part :filename)) (insert (with-temp-buffer (insert (notmuch-get-bodypart-content msg part nth notmuch-show-process-crypto)) + ;; notmuch-get-bodypart-content provides "raw", non-converted + ;; data. Replace CRLF with LF before icalendar can use it. (goto-char (point-min)) + (while (re-search-forward "\r\n" nil t) + (replace-match "\n" nil nil)) (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) + (unwind-protect + (progn + (unless (icalendar-import-buffer file t) + (error "Icalendar import error. See *icalendar-errors* for more information")) + (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) @@ -996,23 +1011,62 @@ message at DEPTH in the current thread." "Insert the forest of threads FOREST." (mapc (lambda (thread) (notmuch-show-insert-thread thread 0)) forest)) +(defvar notmuch-id-regexp + (concat + ;; Match the id: prefix only if it begins a word (to disallow, for + ;; example, matching cid:). + "\\\"-parts into buttons for -a corresponding notmuch search." +This also turns id:\"\"-parts and mid: links into +buttons for a corresponding notmuch search." (goto-address-fontify-region start end) (save-excursion - (goto-char start) - (while (re-search-forward "id:\\(\"?\\)[^[:space:]\"]+\\1" end t) - ;; remove the overlay created by goto-address-mode - (remove-overlays (match-beginning 0) (match-end 0) 'goto-address t) - (make-text-button (match-beginning 0) (match-end 0) - 'action `(lambda (arg) - (notmuch-show ,(match-string-no-properties 0))) - 'follow-link t - 'help-echo "Mouse-1, RET: search for this message" - 'face goto-address-mail-face)))) + (let (links) + (goto-char start) + (while (re-search-forward notmuch-id-regexp end t) + (push (list (match-beginning 0) (match-end 0) + (match-string-no-properties 0)) links)) + (goto-char start) + (while (re-search-forward notmuch-mid-regexp end t) + (let* ((mid-cid (match-string-no-properties 1)) + (mid (save-match-data + (string-match "^[^/]*" mid-cid) + (url-unhex-string (match-string 0 mid-cid))))) + (push (list (match-beginning 0) (match-end 0) + (notmuch-id-to-query mid)) links))) + (dolist (link links) + ;; Remove the overlay created by goto-address-mode + (remove-overlays (first link) (second link) 'goto-address t) + (make-text-button (first link) (second link) + 'action `(lambda (arg) + (notmuch-show ,(third link))) + 'follow-link t + 'help-echo "Mouse-1, RET: search for this message" + 'face goto-address-mail-face))))) ;;;###autoload (defun notmuch-show (thread-id &optional parent-buffer query-context buffer-name) @@ -1131,6 +1185,10 @@ reset based on the original query." (let ((inhibit-read-only t) (state (unless reset-state (notmuch-show-capture-state)))) + ;; erase-buffer does not seem to remove overlays, which can lead + ;; to weird effects such as remaining images, so remove them + ;; manually. + (remove-overlays) (erase-buffer) (notmuch-show-build-buffer) (if state