jeremy-compostella / org-msg

OrgMsg is a GNU/Emacs global minor mode mixing up Org mode and Message mode to compose and reply to emails in a Outlook HTML friendly style.
GNU General Public License v3.0
280 stars 60 forks source link

preview/send message not possible "org-msg-build: Wrong type argument: consp, nil" #19

Closed gyhor closed 4 years ago

gyhor commented 4 years ago

mail-agent mu4e emacs 26.3 spacemacs developer distribution

Message could not send or preview, if the original reply message does not contain a "

"-tag.

error message is:

org-msg-build: Wrong type argument: consp, nil

backtrace:

Debugger entered--Lisp error: (wrong-type-argument consp nil) org-msg-improve-reply-header((html nil (head nil (meta ((http-equiv . "Content-Type") snip ""))) ...)) org-msg-build() org-msg-preview(nil) funcall-interactively(org-msg-preview nil) call-interactively(org-msg-preview nil nil) command-execute(org-msg-preview)

--text follows this line--
#+OPTIONS: html-postamble:nil H:5 num:nil ^:{} toc:nil \n:t d:nil
#+STARTUP: hidestars indent inlineimages
:PROPERTIES:
:reply-to: ("/tmp/rt-4.0.8-7237")
:attachment: nil
:END:

If the file /tmp/rt-4.0.8-7237 does not include a "

"-tag the error happens. After I manually inserted the tag org-msg could send/preview the message.

not working:

cat /tmp/rt-4.0.8-7237
from: asdfs
asdfasdf
asdfasdfsadf
asdfasdfasdf

working:

cat /tmp/rt-4.0.8-7237
from: asdfs
asdfasdf
asdfasdfsadf
asdfasdfasdf
<div></div>

The problem is that sometimes I reply need to message which does not have a

-tag.

jeremy-compostella commented 4 years ago

Hi,

The <div>...</div> should be present because:

  1. with the gnus mail user agent this is added by the gnus-article-browse-html-article
  2. with mu4e Mail User Agent, the org-msg-save-article-for-reply-mu4e function should have added the <div>...</div> (see below).

    326 (defun org-msg-save-article-for-reply-mu4e () 327 "Export the currently visited mu4e article as HTML." 328 (with-current-buffer mu4e~view-buffer-name 329 (let ((msg (mu4e-message-at-point)) 330 (html (mu4e-message-field msg :body-html)) 331 (file (concat "/tmp/" (mu4e-message-field msg :message-id)))) 332 (cl-flet ((mails2str (l) 333 (mapconcat (lambda (m) 334 (format "%S <%s>" (car m) (cdr m))) 335 l ", ")) 336 (field2str (f) 337 (let ((value (funcall (cdr f) 338 (mu4e-message-field msg (car f))))) 339 (when value 340 (format "%s: %s
    \n" 341 (capitalize (substring (symbol-name (car f)) 1)) 342 value))))) 343 (with-temp-buffer 344 (save-excursion 345 (insert html)) 346 ;; Remove everything before html tag 347 (save-excursion 348 (when (re-search-forward "^<html\(.?\)>" nil t) 349 (delete-region (point-min) (match-beginning 0)))) 350 ;; Insert reply header after body tag 351 (when (re-search-forward "<body\(.?\)>" nil t) 352 (goto-char (match-end 0)) 353 (insert "<div align=\"left\">\n" 354 (mapconcat #'field2str 355 `((:from . ,#'mails2str) 356 (:subject . identity) 357 (:to . ,#'mails2str) 358 (:cc . ,#'mails2str) 359 (:date . message-make-date)) 360 "") 361 "

\n
\n")) 362 (write-file file)) 363 (list file)))))

Unless you are trying to answer an non-HTML email but in that case the org-msg-edit-mode should not even enable itself. Otherwise, we are left with:

  1. the original email is malformed
  2. there is a bug in org-msg-save-article-for-reply-mu4e or the error management is not strong enough (which is certainly the case but I am not the original author of this function).

If this #2, please share send me the file by email so that I can try to fix this function.

FYI, I use the gnus backend ⇒ I don't exercise the mu4e myself but many people around the world are using it.

Regards,

-- Jeremy
One Emacs to rule them all

gyhor commented 4 years ago

Hi, thanks for the fast response. The original message is generated from a ticket system (Request Tracker). The mime part with html is this:

------------=_1574156543-7237-6
Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8

<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Dutf-8">Ko=
mmentar zu <a href=3D"*snip*">Ti=
cket 34708</a>:<br><br>
*snip* some text with <br> tags

------------=_1574156543-7237-6--

org-msg saves the reply file in /tmp like above - without any

surrounding. I wil try to debug 'org-msg-save-article-for-reply-mu4e'.

I receive a lot oh html mails from ticket-systems where only a html-part is included - without or tags. Maybe org-msg does have a workaround for that?

regards

jeremy-compostella commented 4 years ago

Hi,

It looks like an invalid html content to me. I don't even see the html or body tag. Also it looks like base64 encorded mime content. The file extracted by mu4e should not have fields like Content-Type:. It should be the de-encoded html content.

Regards, Jeremy

gyhor commented 4 years ago

hi,

ah.. I see my mistake. I should it better. The mime part above is from the original mail:

------------=_1574156543-7237-6
Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8

<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Dutf-8">Ko=
mmentar zu <a href=3D"*snip*">Ti=
cket 34708</a>:<br><br>
*snip* some text with <br> tags

------------=_1574156543-7237-6--

'org-msg-save-article-for-reply-mu4e' save that to /tmp/messageid :

<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Dutf-8">Kommentar zu <a href=3D"*snip*">Ticket 34708</a>:<br><br>
*snip* some text with <br> tags

Maybe there is any workaround possible? Because that are automated Mails, where I have to reply to :/ Maybe 'org-msg-save-article-for-reply-mu4e' recognize the missing the -tag and insert it?

regards

jeremy-compostella commented 4 years ago

Hi Gyhor,

Maybe there is any workaround possible?

Of course, this is possible. I pushed two experimental patches on the experimental branch to handle this situation. Could you test them ? And also review them ?

Regards,

Jeremy
One Emacs to rule them all

gyhor commented 4 years ago

Hi Jeremy, the firsts tests are positive. Everything is working fine. I will try more the next days. thank you for your fast response and help!

regards

jeremy-compostella commented 4 years ago

Hi Gyhor,

Take your time, try to validate with as many use-cases as possible, we are not in a hurry. Come back to me sometime next week with your feedback. If you do not find any issue, I will push experimental as the new master.

Regards, Jeremy

jeremy-compostella commented 4 years ago

Is it stable enough ?

jeremy-compostella commented 4 years ago

I assume that it works now. I have pushed the experimental branch as the new master branch.

gyhor commented 4 years ago

thank you!