Hi Dirk,
My apologies for the long-delayed reply. I lost track of this message
and then re-discovered it when I encountered the same issue again today.
>> When I compose a mail (C-x m), I am asked to select a context.
>> Sometimes I write part of a message, but don't finish it and leave the
>> frame open for later.
>>
>> Then if I go off do something else that causes me to switch mu4e
>> context, when I return to the draft message the context may no longer be
>> the one that I initially selected. Not realizing this has lead me to
>> accidentally send a few messages using the wrong email account.
>>
>> Is there any way to make the context "stick" to a draft message? Or is
>> that thinking about contexts all wrong?
>
> Before editing a draft message, the context system is consulted about
> the context to use; so it should be possible to make it DTRT based on
> the message.
>
> Or, assuming you have mu4e-compose-context-policy set to 'ask, you could
> have a match function like
>
> --8<---------------cut here---------------start------------->8---
> :match-func
> (lamba (msg)
> (unless (eq mu4e-compose-type 'edit)
> ...
> ))
> --8<---------------cut here---------------end--------------->8---
>
> and you'll be asked before editing your message.
Assuming I understand your reply, it doesn't quite address the issue I'm
encountering. Here's what happens:
1) I compose a new message, pick a context, and start writing. I don't
finish, but leave that frame open. I do not save a draft.
2) I compose a second new message, pick a different context, write the
message and send it. It is sent from the desired address because the
context has appropriately set message-sendmail-extra-arguments for that
account.
3) I return to the frame with the first message, finish it, and then
send it. Because hours or days have elapsed, I forget that I have
switched contexts. Thus it gets sent from the account whose context I
chose in 2) and not from the context I picked in 1).
I tried using mu4e-compose-mode-hook to store a buffer-local variable
with the details of the initial context and then use that to set
message-sendmail-extra-arguments in message-send-mail-hook. But it
appeared that the message buffer changes on the way to being sent such
that the buffer-local value isn't there anymore at that time.
I'm probably just trying to abuse contexts and should go back to
something like inspecting the From address in message-send-mail-hook.
Thanks,
Josiah