Re: automatically changing FCC when From changes (or fill FCC only when sending)

2023-10-02 Thread David Pinto
On Fri, 22 Sept 2023 at 10:25, David Bremner  wrote:
> David Pinto  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
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


Re: automatically changing FCC when From changes (or fill FCC only when sending)

2023-09-22 Thread David Bremner
David Bremner  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.

___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


Re: automatically changing FCC when From changes (or fill FCC only when sending)

2023-09-22 Thread David Bremner
David Pinto  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.
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


Re: automatically changing FCC when From changes (or fill FCC only when sending)

2023-09-21 Thread David Pinto
On Sat, 16 Sept 2023 at 16:17, David Bremner  wrote:
>
> David Pinto  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
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


Re: automatically changing FCC when From changes (or fill FCC only when sending)

2023-09-16 Thread David Bremner
David Pinto  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/
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


automatically changing FCC when From changes (or fill FCC only when sending)

2023-09-16 Thread David Pinto
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
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org