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
_______________________________________________
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-leave@notmuchmail.org