message.el and browse-url.el interaction [was: Re: BUG: notmuch-emacs-mua wrong signing MML placement]

Tomi Ollila tomi.ollila at iki.fi
Thu Dec 12 23:33:11 PST 2019


On Fri, Dec 13 2019, Tomi Ollila wrote:

> On Thu, Dec 12 2019, David Edmondson wrote:
>
>> On Wednesday, 2019-12-11 at 13:55:16 -05, Robbie Harwood wrote:
>>
>>> My emacs config contains `(add-hook 'message-setup-hook
>>> 'mml-secure-sign-pgpmime)` as recommended in the emacstips
>>> https://notmuchmail.org/emacstips/#index14h2
>>>
>>> However, when I run (something like):
>>>
>>>     notmuch-emacs-mua 'mailto:testto?body=testbody'
>>>
>>> I get an email in which the requested body contents appear *before* the
>>> signing MML.  If I understand correctly how this all fits together, that
>>> won't do the right thing - but at any rate, it's unexpected.
>>
>> This is an unfortunate interaction between message.el and browse-url.el
>> and isn't specific to notmuch or notmuch-emacs-mua.
>>
>> You can see the same behaviour in “emacs -Q -q” if you execute:
>>
>> (progn
>>  (add-hook 'message-setup-hook 'mml-secure-sign-pgpmime)
>>  (browse-url-mail "mailto:fred?body=testbody"))
>>
>> Given that, it's not something that we should be fixing in notmuch
>> itself, as it's an emacs bug.
>>
>> The problem is that `browse-url-mail' always inserts the body after the
>> header separator, which in this case happens after
>> `mml-secure-sign-pgpmime' has already inserted the MML header.
>>
>> Having `browse-url-mail' insert the body at the end of the message would
>> work for this case, but would presumably make a mess of situations where
>> someone inserts their signature block via `message-setup-hook'.
>>
>> Perhaps `browse-url-mail' should skip past any MML headers before
>> inserting the body? That's a bit messy, as browse-url.el currently
>> doesn't know anything about MML.
>
> I've never found `browse-url-mail' adequate for handling mailto: links,
> so couple of years ago I wrote mailto: "wrapper" of my own (*). It,
> among other things, spits the following elisp for emacs to swallow:
>
> (with-demoted-errors
> (require 'notmuch)
> (notmuch-mua-mail "fred" nil nil nil
>                   (notmuch-mua-get-switch-function))
>  (cd "/home/too/vc/projects/nottoomuch")
>  (message-goto-body) (insert "testbody")
>  (goto-char (point-max))
>  (if (/= (point) (line-beginning-position))
>     (newline))
>  (set-buffer-modified-p nil) (message-goto-to))

Small update from my front -- looked message.el and (message-setup-1)
there in particular, and then tested the following code:

(with-demoted-errors
 (require 'notmuch)
 (let ((message-signature-setup-hook message-signature-setup-hook))
   (add-hook 'message-signature-setup-hook
     (lambda () (message-goto-body) (insert "testbody")
                (if (/= (point) (line-beginning-position))
                  (newline))))
   (notmuch-mua-mail "fred" nil nil nil
      (notmuch-mua-get-switch-function))
))

This has moderate chance of working, so I'll have to think it a bit
further (and clean up the code =D)...

>
> Surprise! this has exactly the same problems as David explains above; I
> could add code to check for this [#part sign=pgpmime] (**) and skip it if
> it exists (and, as first step, not look for anything else to skip). That
> is just so hacky and error prone I would not like to do so (at least as
> a general solution)...
>
>>
>> The nicest fix would perhaps be to have `compose-mail' accept the
>> initial body as a parameter, which would eventually flow into the
>> relevant code in message.el which could do the right thing (which I
>> think would just be to skip past MML headers before inserting the body).
>
> This suggestion of an optional parameter to take initial body sounds
> very good solution (as first sight =D), so if I don't come up with
> any other suggestions +1 for that..
>
>>
>> Any advice from emacs-devel on how to move forward? I'm happy to produce
>> a patch for whatever solution is considered most appropriate.
>>
>> dme.
>> -- 
>> If the girls start moving the boys will start moving.
>
> Tomi
>
> (*) https://github.com/domo141/nottoomuch/blob/master/nottoomuch-emacs-mailto.rst
>
> (**) replace [...] with <...> 


More information about the notmuch mailing list