unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* automatically changing FCC when From changes (or fill FCC only when sending)
@ 2023-09-16  0:18 David Pinto
  2023-09-16 16:17 ` David Bremner
  0 siblings, 1 reply; 6+ messages in thread
From: David Pinto @ 2023-09-16  0:18 UTC (permalink / raw)
  To: notmuch

Hi everyone

I've recently started using notmuch and I've found it works amazing.
It's so fast!  Thank you.

However, I've been struggling a lot with saving sent messages in the
right place (Emacs notmuch-user-agent).  I think I finally got to the
bottom of it and maybe I just had the wrong expectations.  I was
hoping someone could confirm and suggest a workaround.

My case is that I have multiple email accounts and want the sent
messages saved on different directories based on the "From" address.
I've setup 'notmuch-fcc-dirs' accordingly.  Now, when I start
composing a message (notmuch-user-agent), the FCC header is set to
whatever is the default "From" address.  But if I change the "From"
address, the FCC header is not updated.

Is there a way to either have the FCC header changed when the "From"
address changes?  Or maybe only add the FCC header when sending
the message?

Many thanks
David

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

* Re: automatically changing FCC when From changes (or fill FCC only when sending)
  2023-09-16  0:18 automatically changing FCC when From changes (or fill FCC only when sending) David Pinto
@ 2023-09-16 16:17 ` David Bremner
  2023-09-21 23:19   ` David Pinto
  0 siblings, 1 reply; 6+ messages in thread
From: David Bremner @ 2023-09-16 16:17 UTC (permalink / raw)
  To: David Pinto, notmuch

David Pinto <carandraug@gmail.com> writes:

>
> My case is that I have multiple email accounts and want the sent
> messages saved on different directories based on the "From" address.
> I've setup 'notmuch-fcc-dirs' accordingly.  Now, when I start
> composing a message (notmuch-user-agent), the FCC header is set to
> whatever is the default "From" address.  But if I change the "From"
> address, the FCC header is not updated.

That is the expected behaviour, yeah.

> Is there a way to either have the FCC header changed when the "From"
> address changes?  Or maybe only add the FCC header when sending
> the message?

Generally I think people like the ability to hand-edit the header, so I
don't think adding it at send time would work for everyone. I do
something related based on address completion: I update the From header
based on To.

I use message-templ [1], along with
notmuch-address-post-completion-functions. My solution is a bit niche
because message-templ is a bit obscure, but I'm happy to go into details
if you are interested.


[1]: https://git.tethera.net/message-templ.git/

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

* Re: automatically changing FCC when From changes (or fill FCC only when sending)
  2023-09-16 16:17 ` David Bremner
@ 2023-09-21 23:19   ` David Pinto
  2023-09-22 10:25     ` David Bremner
  0 siblings, 1 reply; 6+ messages in thread
From: David Pinto @ 2023-09-21 23:19 UTC (permalink / raw)
  To: David Bremner, notmuch

On Sat, 16 Sept 2023 at 16:17, David Bremner <david@tethera.net> wrote:
>
> David Pinto <carandraug@gmail.com> writes:
>
> [...]
> > Is there a way to either have the FCC header changed when the "From"
> > address changes?  Or maybe only add the FCC header when sending
> > the message?
>
> Generally I think people like the ability to hand-edit the header, so I
> don't think adding it at send time would work for everyone. I do
> something related based on address completion: I update the From header
> based on To.

Thank you for your reply.

I see what you mean, how changing the FCC would prevent the ability to
manually edit the FCC.  But what about updating the FCC when the
"From" changes?

When starting a new message, and assuming that there is more that one
possible "From", the default "From" will often be wrong.  I would also
expect one to set the "From" before any manual changes to "FCC".  If
so, then I think it could make sense to update the "FCC" when the
"From" changes since there would be no manual adjustment to FCC lost.

You mention updating the "From" when the "To" changes with the
notmuch-address-post-completion-functions hook.  Could there be a hook
for when the "From" changes which I could use to change the FCC?

> I use message-templ [1], along with
> notmuch-address-post-completion-functions. My solution is a bit niche
> because message-templ is a bit obscure, but I'm happy to go into details
> if you are interested.

This message-templ seems ideal for another issue of mine.  I will look
more into it.

Thank you
David

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

* Re: automatically changing FCC when From changes (or fill FCC only when sending)
  2023-09-21 23:19   ` David Pinto
@ 2023-09-22 10:25     ` David Bremner
  2023-09-22 10:41       ` David Bremner
  2023-10-02 10:28       ` David Pinto
  0 siblings, 2 replies; 6+ messages in thread
From: David Bremner @ 2023-09-22 10:25 UTC (permalink / raw)
  To: David Pinto, notmuch

David Pinto <carandraug@gmail.com> writes:

>
> I see what you mean, how changing the FCC would prevent the ability to
> manually edit the FCC.  But what about updating the FCC when the
> "From" changes?

I don't know how to efficiently detect changes to
From. (notmuch-)message-mode is essentially a text editor buffer,
including the header area, so I think one would have to reparse the
buffer after every keystroke. I think that would be annoyingly slow, but
I haven't tried it. The hook is called "post-command-hook" if you are
feeling adventurous, but see the warnings in the docstring.

> You mention updating the "From" when the "To" changes with the
> notmuch-address-post-completion-functions hook.  Could there be a hook
> for when the "From" changes which I could use to change the FCC?

My partial-solution relies on using completion to change To. If you are
OK with that (i.e. manual editing without completion would not update
Fcc), then the same scheme could work.

Another option that seems technically feasible, but would involve some
elisp programming, would be to write a command that re-applies the
calculation of Fcc from From that already exists, and run that manually
or perhaps opt-in to running it automatically on send.

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

* Re: automatically changing FCC when From changes (or fill FCC only when sending)
  2023-09-22 10:25     ` David Bremner
@ 2023-09-22 10:41       ` David Bremner
  2023-10-02 10:28       ` David Pinto
  1 sibling, 0 replies; 6+ messages in thread
From: David Bremner @ 2023-09-22 10:41 UTC (permalink / raw)
  To: David Pinto, notmuch

David Bremner <david@tethera.net> writes:

>
> Another option that seems technically feasible, but would involve some
> elisp programming, would be to write a command that re-applies the
> calculation of Fcc from From that already exists, and run that manually
> or perhaps opt-in to running it automatically on send.

I guess if you have message-templ installed, there is really not any
programming. My hook usage looks like

(setq notmuch-address-post-completion-functions
      '((lambda (lst) (message-templ-config-exec))))

You could certainly bind #'message-templ-config-exec to a key and
(although then you have to trust it does the right thing) run it when
sending e.g. from message-send-hook.

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

* Re: automatically changing FCC when From changes (or fill FCC only when sending)
  2023-09-22 10:25     ` David Bremner
  2023-09-22 10:41       ` David Bremner
@ 2023-10-02 10:28       ` David Pinto
  1 sibling, 0 replies; 6+ messages in thread
From: David Pinto @ 2023-10-02 10:28 UTC (permalink / raw)
  To: David Bremner; +Cc: notmuch

On Fri, 22 Sept 2023 at 10:25, David Bremner <david@tethera.net> wrote:
> David Pinto <carandraug@gmail.com> writes:
> > [...]
> > You mention updating the "From" when the "To" changes with the
> > notmuch-address-post-completion-functions hook.  Could there be a hook
> > for when the "From" changes which I could use to change the FCC?
>
> My partial-solution relies on using completion to change To. If you are
> OK with that (i.e. manual editing without completion would not update
> Fcc), then the same scheme could work.
>
> Another option that seems technically feasible, but would involve some
> elisp programming, would be to write a command that re-applies the
> calculation of Fcc from From that already exists, and run that manually
> or perhaps opt-in to running it automatically on send.

Thank you for the hints.  I followed your hint and read the code for
notmuch-fcc-header-setup.  Then I wrote a function that updates the
FCC header and I hooked it to the address-post-completion:

    (defun update-fcc-header (addr)
      "Replace FCC header appropriate for given address"
      (let ((subdir (cdr (assoc addr notmuch-fcc-dirs 'string-match-p))))
        (when subdir
          (save-excursion
            (message-goto-fcc)
            (delete-region (line-beginning-position) (point))
            (insert "Fcc: " subdir)))))

    (defun update-fcc-header-when-from-address-completion (addr)
      "To hook on notmuch-address-post-completion-functions"
      (let ((cline (thing-at-point 'line)))
        (when (or (string-prefix-p "From:" cline)
                  (string-prefix-p "Resent-From:" cline))
          (update-fcc-header addr))))

    (setq notmuch-address-post-completion-functions
          '(update-fcc-header-when-from-address-completion))

It's here for anyone interested on the same functionality in the
future.

Do you think this is an interesting feature to be part of notmuch?  If
so, I could improve it and add some checks to cover for the different
notmuch-fcc-dirs types of values.

Best wishes
David

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

end of thread, other threads:[~2023-10-02 10:36 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-16  0:18 automatically changing FCC when From changes (or fill FCC only when sending) David Pinto
2023-09-16 16:17 ` David Bremner
2023-09-21 23:19   ` David Pinto
2023-09-22 10:25     ` David Bremner
2023-09-22 10:41       ` David Bremner
2023-10-02 10:28       ` David Pinto

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).