unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* Feature request: show destination in tree view when appropriate
@ 2022-07-16  9:36 Jon Hurst
  2022-07-16 11:14 ` David Bremner
  0 siblings, 1 reply; 7+ messages in thread
From: Jon Hurst @ 2022-07-16  9:36 UTC (permalink / raw)
  To: notmuch

Hi,

In the emacs front end, I can specify authors in the format for search
results and trees. This is great when looking at received mail, but when
looking at sent mail it is not optimal. I have used mutt in the past,
and this puts "To: xxx*xxxx.xxx" in this field for sent mail, which is
much more useful.

Is there any way to achieve this behaviour with notmuch, and if not, may
I request it as a feature.

Many thanks,

Jon Hurst

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Feature request: show destination in tree view when appropriate
  2022-07-16  9:36 Feature request: show destination in tree view when appropriate Jon Hurst
@ 2022-07-16 11:14 ` David Bremner
  2022-07-16 13:23   ` Jon Hurst
  0 siblings, 1 reply; 7+ messages in thread
From: David Bremner @ 2022-07-16 11:14 UTC (permalink / raw)
  To: Jon Hurst, notmuch

Jon Hurst <jon@hursts.org.uk> writes:

> Hi,
>
> In the emacs front end, I can specify authors in the format for search
> results and trees. This is great when looking at received mail, but when
> looking at sent mail it is not optimal. I have used mutt in the past,
> and this puts "To: xxx*xxxx.xxx" in this field for sent mail, which is
> much more useful.
>
> Is there any way to achieve this behaviour with notmuch, and if not, may
> I request it as a feature.

For notmuch-search-mode, it is achievable by using a function in
notmuch-search-result-format. Unfortunately this seems only documented
in a commit message, which I append at the end of the message.  A
similar approach should work for notmuch-tree-result-format. I have not
tested either, but I suppose you would need to write a function like
author-or-to that decides for each message which of those to insert.


;; from 4f4ec48df25c8d2963e7124d2781b13e5a7f6a78

If the car of an element in notmuch-search-result-format is a
function, insert the result of calling the function into the buffer.

This allows a user to generate custom fields in the output of a search
result. For example, with:

(defun -notmuch-result-flags (format-string result)
  (let ((tags-to-letters '(("flagged" . "!")
			   ("unread" . "u")
			   ("mine" . "m")
			   ("sent" . "s")
			   ("replied" . "r")))
	(tags (plist-get result :tags)))

    (format format-string
	    (mapconcat (lambda (t2l)
			 (if (member (car t2l) tags)
			     (cdr t2l)
			   " "))
		       tags-to-letters ""))))

(setq notmuch-search-result-format '((-notmuch-result-flags . "%s ")
				     ("date" . "%12s ")
				     ("count" . "%9s ")
				     ("authors" . "%-30s ")
				     ("subject" . "%s ")
				     ("tags" . "(%s)")))

The first few characters on each line of the search result are used to
show information about some significant tags associated with the
thread.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Feature request: show destination in tree view when appropriate
  2022-07-16 11:14 ` David Bremner
@ 2022-07-16 13:23   ` Jon Hurst
  2022-07-16 21:30     ` David Bremner
                       ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Jon Hurst @ 2022-07-16 13:23 UTC (permalink / raw)
  To: David Bremner, notmuch


Many thanks David; just what I needed.

> tested either, but I suppose you would need to write a function like
> author-or-to that decides for each message which of those to insert.

For the record:


(defun -notmuch-authors-or-to (format-string result)
  (let* ((headers (plist-get result :headers))
         (match (plist-get result :match))
         (to (plist-get headers :To))
         (author (notmuch-tree-clean-address (plist-get headers :From)))
	 (len (length (format format-string "")))
	 (face (if match
		   'notmuch-tree-match-author-face
		 'notmuch-tree-no-match-author-face)))
    (if (string= author "Jon Hurst")
        (setq author (concat "To:" (notmuch-tree-clean-address to))))
    (when (> (length author) len)
      (setq author (substring author 0 len)))
    (propertize (format format-string author) 'face face)))


(setq notmuch-tree-result-format
   '(("date" . "%12s  ")
     (-notmuch-authors-or-to . "%-25s")
     ((("tree" . "%s")
       ("subject" . "%s"))
      . " %-54s ")
     ("tags" . "(%s)")))

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Feature request: show destination in tree view when appropriate
  2022-07-16 13:23   ` Jon Hurst
@ 2022-07-16 21:30     ` David Bremner
  2022-07-19  9:22     ` inwit
  2022-07-21 11:30     ` Jon Hurst
  2 siblings, 0 replies; 7+ messages in thread
From: David Bremner @ 2022-07-16 21:30 UTC (permalink / raw)
  To: Jon Hurst, notmuch

Jon Hurst <jon@hursts.org.uk> writes:

> Many thanks David; just what I needed.
>
>> tested either, but I suppose you would need to write a function like
>> author-or-to that decides for each message which of those to insert.
>
> For the record:
>
>
> (defun -notmuch-authors-or-to (format-string result)
>   (let* ((headers (plist-get result :headers))
>          (match (plist-get result :match))
>          (to (plist-get headers :To))
>          (author (notmuch-tree-clean-address (plist-get headers :From)))
> 	 (len (length (format format-string "")))
> 	 (face (if match
> 		   'notmuch-tree-match-author-face
> 		 'notmuch-tree-no-match-author-face)))
>     (if (string= author "Jon Hurst")
>         (setq author (concat "To:" (notmuch-tree-clean-address to))))
>     (when (> (length author) len)
>       (setq author (substring author 0 len)))
>     (propertize (format format-string author) 'face face)))
>
>
> (setq notmuch-tree-result-format
>    '(("date" . "%12s  ")
>      (-notmuch-authors-or-to . "%-25s")
>      ((("tree" . "%s")
>        ("subject" . "%s"))
>       . " %-54s ")
>      ("tags" . "(%s)")))

Nice. I hope you don't mind, but I used a modified version of this code
as an example for the the documentation:

https://nmbug.notmuchmail.org/nmweb/show/20220716212228.56432-5-david%40tethera.net

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Feature request: show destination in tree view when appropriate
  2022-07-16 13:23   ` Jon Hurst
  2022-07-16 21:30     ` David Bremner
@ 2022-07-19  9:22     ` inwit
  2022-07-19  9:56       ` Jon Hurst
  2022-07-21 11:30     ` Jon Hurst
  2 siblings, 1 reply; 7+ messages in thread
From: inwit @ 2022-07-19  9:22 UTC (permalink / raw)
  To: Jon Hurst, David Bremner, notmuch

On Sat Jul 16, 2022 at 3:23 PM CEST, Jon Hurst wrote:
> For the record:
>
> (defun -notmuch-authors-or-to (format-string result) (let* ((headers
> (plist-get result :headers)) (match (plist-get result :match)) (to (plist-get
> headers :To)) (author (notmuch-tree-clean-address (plist-get headers :From)))
> (len (length (format format-string ""))) (face (if match
> 'notmuch-tree-match-author-face 'notmuch-tree-no-match-author-face))) (if
> (string= author "Jon Hurst") (setq author (concat "To:"
> (notmuch-tree-clean-address to)))) (when (> (length author) len) (setq author
> (substring author 0 len))) (propertize (format format-string author) 'face
> face)))
>
>
> (setq notmuch-tree-result-format '(("date" . "%12s  ")
> (-notmuch-authors-or-to . "%-25s") ((("tree" . "%s") ("subject" . "%s")) . "
> %-54s ") ("tags" . "(%s)")))
Yay!! I've been hoping for this functionality, which also has been discussed
over at IRC. Thanks, Jon!

With my very basic elisp knowledge, I've tried to adapt this to the search (and
unthreaded) views, with no luck. I have trouble understanding the face part.
Since afaik in the search and unthreaded views there's no change in face for
matching messages, I thought I could get away by removing that part. But this
doesn't work:

(defun inwit/notmuch-search-authors-or-to (format-string result)
  (let* ((headers (plist-get result :headers))
         (to (plist-get headers :To))
         (author (plist-get headers :From)))
   (format format-string
        (if (string-match "inwit" author)
        (concat "To: " (notmuch-tree-clean-address to))
                      author))))

(setq notmuch-search-result-format
     '(("date" . "%12s ")
       ("count" . "%-7s ")
       (inwit/notmuch-search-authors-or-to . "%-20s")
       ("subject" . "%s ")
       ("tags" . "(%s)")))

Any help would be greatly appreciated.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Feature request: show destination in tree view when appropriate
  2022-07-19  9:22     ` inwit
@ 2022-07-19  9:56       ` Jon Hurst
  0 siblings, 0 replies; 7+ messages in thread
From: Jon Hurst @ 2022-07-19  9:56 UTC (permalink / raw)
  To: inwit

> (defun inwit/notmuch-search-authors-or-to (format-string result)
>   (let* ((headers (plist-get result :headers))
>          (to (plist-get headers :To))
>          (author (plist-get headers :From)))
>    (format format-string
>         (if (string-match "inwit" author)
>         (concat "To: " (notmuch-tree-clean-address to))
>                       author))))
> Any help would be greatly appreciated.

Your problem is that the result argument has this sort of form:

(:thread "00000000000029c5"
 :timestamp 1658007025
 :date_relative "Sat. 22:30"
 :matched 3
 :total 5
 :authors "David Bremner, Jon Hurst| inwit"
 :subject "Feature request: show destination in tree view when
 appropriate"
 :query ("id:87ilnx5mxq.fsf@tethera.net id:877d4dry2i.fsf@hursts.org.uk
         id:87cze468zy.fsf@tethera.net" "id:87a699e6wn.fsf@hursts.org.uk
         id:CLJIU9081RIS.3M4YBKDJ2UJ3O@bisio")
 :tags ("inbox" "replied")
 :orig-tags ("inbox" "replied"))

So there is no :headers and :authors has multiple entries. I guess what
you are looking for is that if the only author is yourself, replace the
author with the "To: ..." version, in which case you would have to use
the :query section to find that.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Feature request: show destination in tree view when appropriate
  2022-07-16 13:23   ` Jon Hurst
  2022-07-16 21:30     ` David Bremner
  2022-07-19  9:22     ` inwit
@ 2022-07-21 11:30     ` Jon Hurst
  2 siblings, 0 replies; 7+ messages in thread
From: Jon Hurst @ 2022-07-21 11:30 UTC (permalink / raw)
  To: David Bremner, notmuch


I'll just add this to the record as well in case it is useful to someone
searching for examples of how to use this functionality:

(defun -notmuch-flag (format-string msg)
  (let ((tags (plist-get msg :tags)))
    (format format-string
            (cond
             ((member "deleted" tags) "D")
             ((member "unread" tags) "U")
             ((member "inbox" tags) "I")
             (t " ")))))


(setq notmuch-tree-result-format
      '(("date" . "%12s ")
        (-notmuch-flag . "%s ")
     (-notmuch-authors-or-to . "%-25s")
     ((("tree" . "%s")
       ("subject" . "%s"))
      . " %s")))

It's a single letter status flag to indicate what stage of processing an
email is at -- obviously targeted for the peculiarities of my personal
workflow but should be easy to adapt.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-07-21 11:30 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-16  9:36 Feature request: show destination in tree view when appropriate Jon Hurst
2022-07-16 11:14 ` David Bremner
2022-07-16 13:23   ` Jon Hurst
2022-07-16 21:30     ` David Bremner
2022-07-19  9:22     ` inwit
2022-07-19  9:56       ` Jon Hurst
2022-07-21 11:30     ` Jon Hurst

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).