Multiple Drafts and Contexts

66 views
Skip to first unread message

Josiah Schwab

unread,
Mar 18, 2017, 11:02:16 PM3/18/17
to mu-discuss
Hi All,

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?


In the pre-context days, I used to use something like the function
choose-msmtp-account

https://groups.google.com/d/msg/mu-discuss/ju8h8ONXblI/uDr5ONufa6cJ

which picks which account to send with based on the From. I could go
back to something like that. (Though that had its own troubles; if I
attached a git patch that had a "From:" in it to my message, things
would sometimes end up confused.)


Josiah

Dirk-Jan C. Binnema

unread,
Mar 19, 2017, 8:47:40 AM3/19/17
to mu-di...@googlegroups.com
Hi Josiah,
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.

Kind regards,
Dirk.

--
Dirk-Jan C. Binnema Helsinki, Finland
e:dj...@djcbsoftware.nl w:www.djcbsoftware.nl
pgp: D09C E664 897D 7D39 5047 A178 E96A C7A1 017D DA3C

Josiah Schwab

unread,
Sep 28, 2017, 8:27:44 PM9/28/17
to mu-di...@googlegroups.com
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

Dirk-Jan C. Binnema

unread,
Oct 2, 2017, 3:25:11 PM10/2/17
to mu-di...@googlegroups.com

On Friday Sep 29 2017, Josiah Schwab wrote:

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

Ah, indeed, a context is just a bundle of global emacs settings; it's
not "message-local" in any way.

Perhaps there should be something for that, but it gets complicated
quickly, esp. when you want to have it persist across emacs sessions.
I'll think about it.

Josiah Schwab

unread,
Oct 3, 2017, 1:07:41 PM10/3/17
to mu-di...@googlegroups.com
Hi Dirk,

> Perhaps there should be something for that, but it gets complicated
> quickly, esp. when you want to have it persist across emacs sessions.
> I'll think about it.

Thanks for the reply.

Since the From header is always OK, I should go back to choosing the
sending options based on the From: instead of trying to set them in the
context. That approach will be fine even across sessions.

No need to over complicate things.

Josiah

John Goerzen

unread,
Oct 18, 2017, 9:08:28 AM10/18/17
to mu-discuss
On Monday, October 2, 2017 at 2:25:11 PM UTC-5, djcb wrote:

Perhaps there should be something for that, but it gets complicated
quickly, esp. when you want to have it persist across emacs sessions.
I'll think about it.

Two questions here.

First, does this imply anything in particular regarding queueing?  https://www.djcbsoftware.nl/code/mu/mu4e/Queuing-mail.html   It is pretty unclear to me how that works (especially since I use sendmail, not SMTP submission, and it is very vague to me how smtpmail and sendmail interact with each other and mu4e).

In other words, if queueing is turned on and I am composing new messages in multiple contexts, will they all be sent from the correct accounts when the queue is later run?
 
Second, would the solution at https://notanumber.io/2016-10-03/better-email-with-mu4e/ be a proper workaround?  They're using (add-hook 'message-send-mail-hook 'choose-msmtp-account) and then that choose-msmtp-account looks like this:

  (defun choose-msmtp-account ()
    (if (message-mail-p)
(save-excursion
 (let*
     ((from (save-restriction
      (message-narrow-to-headers)
      (message-fetch-field "from")))
      (account
(cond
((string-match "nzh...@digitalocean.com" from) "do")
((string-match "n...@nine27.com" from) "nine27"))))
   (setq message-sendmail-extra-arguments (list '"-a" account))))))

I guess in this particular case, he's selecting accounts by changing sendmail paramaters, but I would assume a person could setq any number of variables there just like with contexts.  Or perhaps even mu4e-context-switch?




Kind regards,
Dirk.

--
Dirk-Jan C. Binnema                  Helsinki, Finland
Reply all
Reply to author
Forward
0 new messages