]> git.cworth.org Git - notmuch-wiki/commitdiff
emacstips: my/notmuch-unthreaded-show-recipient-if-sent master
authorWillForan <willforan@gmail.com>
Sun, 16 Nov 2025 02:50:35 +0000 (21:50 -0500)
committerWillForan <willforan@gmail.com>
Sun, 16 Nov 2025 02:50:35 +0000 (21:50 -0500)
  * use `user-mail-address` which hopefully already stores the email
    address to check against
  * if-is-author extra else component (duplicated true line?) removed
  * add note `notmuch-tree-clean-address` doesn't work well on To:
  * add doc string

emacstips.mdwn

index 288690c0c165211436bb7c9348544d91b2dd8d58..64004443260c3be6b418ecfb363de7f002b5e820 100644 (file)
@@ -994,19 +994,28 @@ arbitrary address, whatever@mail.address.com in the example) is included in the
 From field.
 
     (defun my/notmuch-unthreaded-show-recipient-if-sent (format-string result)
-    (let* ((headers (plist-get result :headers))
-           (to (plist-get headers :To))
-           (author (plist-get headers :From))
-           (face (if (plist-get result :match)
-                     'notmuch-tree-match-author-face
-                   'notmuch-tree-no-match-author-face)))
-      (propertize
-       (format format-string
-               (if (string-match "whatever@mail.address.com" author)
-                   (concat "↦ " (notmuch-tree-clean-address to))
-                   (notmuch-tree-clean-address to)
-                 author))
-       'face face)))
+      "Custom function for `notmuch-unthreaded-result-format' to use instead of \"authors\".
+    Show \"From:\" address from RESULT, unless we sent the message. Then show \"To:\".
+    Formatted with FORMAT-STRING.
+    Example on wiki https://notmuchmail.org/emacstips/"
+
+      (let* ((headers (plist-get result :headers))
+             (to (plist-get headers :To))
+             (author (plist-get headers :From))
+             ;; NOTE: `user-mail-address` has to be set correctly
+             (is-me? (string-match user-mail-address author))
+             (face (if (plist-get result :match)
+                       'notmuch-tree-match-author-face
+                     'notmuch-tree-no-match-author-face)))
+        (propertize
+         (format format-string
+                 (if is-me?
+                      ;; NOTE: "To:" may have more than one address.
+                      ;;  `notmuch-tree-clean-address` will pull
+                      ;;  all but the last address combined as name
+                      (concat "↪" (notmuch-tree-clean-address to))
+                      (notmuch-tree-clean-address author)))
+         'face face)))
 
     (setq notmuch-unthreaded-result-format
           '(("date" . "%12s  ")