]> git.notmuchmail.org Git - notmuch/blobdiff - emacs/notmuch-show.el
Make `notmuch-show-clean-address' parsing-error-proof.
[notmuch] / emacs / notmuch-show.el
index 6c498ab1b8cff9cd53bb8620fb34b2448b7cd81b..fb91c83856eb5e248d7bd64ab7a9522593822550 100644 (file)
@@ -224,22 +224,25 @@ same as that of the previous message."
                                 ")"))))))
 
 (defun notmuch-show-clean-address (address)
-  "Clean a single email address for display."
-  (let* ((parsed (mail-header-parse-address address))
-        (address (car parsed))
-        (name (cdr parsed)))
-    ;; Remove double quotes. They might be required during transport,
-    ;; but we don't need to see them.
-    (when name
-      (setq name (replace-regexp-in-string "\"" "" name)))
-    ;; If the address is 'foo@bar.com <foo@bar.com>' then show just
-    ;; 'foo@bar.com'.
-    (when (string= name address)
-      (setq name nil))
-
-    (if (not name)
-       address
-      (concat name " <" address ">"))))
+  "Try to clean a single email ADDRESS for display.  Return
+unchanged ADDRESS if parsing fails."
+  (condition-case nil
+    (let* ((parsed (mail-header-parse-address address))
+          (address (car parsed))
+          (name (cdr parsed)))
+      ;; Remove double quotes. They might be required during transport,
+      ;; but we don't need to see them.
+      (when name
+        (setq name (replace-regexp-in-string "\"" "" name)))
+      ;; If the address is 'foo@bar.com <foo@bar.com>' then show just
+      ;; 'foo@bar.com'.
+      (when (string= name address)
+        (setq name nil))
+
+      (if (not name)
+        address
+        (concat name " <" address ">")))
+    (error address)))
 
 (defun notmuch-show-insert-headerline (headers date tags depth)
   "Insert a notmuch style headerline based on HEADERS for a
@@ -280,18 +283,23 @@ message at DEPTH in the current thread."
   'face 'message-mml)
 
 (defun notmuch-show-insert-part-header (nth content-type declared-type &optional name comment)
-  (insert-button
-   (concat "[ "
-          (if name (concat name ": ") "")
-          declared-type
-          (if (not (string-equal declared-type content-type))
-              (concat " (as " content-type ")")
-            "")
-          (or comment "")
-          " ]\n")
-   :type 'notmuch-show-part-button-type
-   :notmuch-part nth
-   :notmuch-filename name))
+  (let ((button))
+    (setq button
+         (insert-button
+          (concat "[ "
+                  (if name (concat name ": ") "")
+                  declared-type
+                  (if (not (string-equal declared-type content-type))
+                      (concat " (as " content-type ")")
+                    "")
+                  (or comment "")
+                  " ]")
+          :type 'notmuch-show-part-button-type
+          :notmuch-part nth
+          :notmuch-filename name))
+    (insert "\n")
+    ;; return button
+    button))
 
 ;; Functions handling particular MIME parts.
 
@@ -306,10 +314,11 @@ message at DEPTH in the current thread."
                   "Filename to save as: "
                   (or mailcap-download-directory "~/")
                   nil nil
-                  filename))
-           (require-final-newline nil)
-           (coding-system-for-write 'no-conversion))
-       (write-region (point-min) (point-max) file)))))
+                  filename)))
+       ;; Don't re-compress .gz & al.  Arguably we should make
+       ;; `file-name-handler-alist' nil, but that would chop
+       ;; ange-ftp, which is reasonable to use here.
+       (mm-write-region (point-min) (point-max) file nil nil nil 'no-conversion t)))))
 
 (defun notmuch-show-mm-display-part-inline (msg part content-type content)
   "Use the mm-decode/mm-view functions to display a part in the