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
275 stars 58 forks source link

Replying to a message in a different charset is wonky #80

Closed znewman01 closed 3 years ago

znewman01 commented 3 years ago

Sorry for the unspecific issue title, but it's a little tricky to describe.

I use utf8 for everything. Org-mode works, org-msg mostly works.

I've worked around this with the following hack (wrapping org-msg-build and fixing the content attribute:

(defun force-utf8 (xml)
  (when (eq (car xml) 'meta)
    (let ((content (assq 'content (cadr xml))))
      (when content
        (setcdr content "text/html; charset=utf-8")))))

(advice-add 'org-msg-build :filter-return (lambda (xml) (org-msg-xml-walk xml #'force-utf8) xml))

This means that the quoted reply is messed up due to an encoding mismatch.

I'm not sure what the right thing to do here is.

jeremy-compostella commented 3 years ago

Yeah I noticed that too but never really looked at most of time it was fine for me. I spent some time trying to understand if we should do some conversion and the conclusion is that apparently it is not needed. The Emacs internal format is derived from utf-8 which mean that the string loaded from the original email are likely already in utf-8. The only real issue is indeed that the meta tag is not updated appropriately. There may be an extra work to do if for some reason the Emacs user is not using utf-8 as its default encoding but I am not even sure.

I pushed a patch on the experimental branch which basically does what you do. Let me know if it works for you.

morganwillcock commented 3 years ago

I noticed the same issue issue. I cannot comment on what the correct fix should be, but the experimental branch change fixes it for me.

znewman01 commented 3 years ago

Thanks for the response! I'll test out replacing my workaround with yours, bug me if I haven't updated a week from now

Your conclusion also sounds quite reasonable.

jeremy-compostella commented 3 years ago

I have improved the patch, it should be more robust now.

znewman01 commented 3 years ago

Okay, had a chance to test this. It seems to tod the trick (both for previews and sending messages). Both the original message and the reply render correctly.

The more I think about it, the more I think "just make sure everything is utf8" is a reasonable behavior that does the right thing for 99% of what I need. I can't speak for anybody else, but this seems quite reasonable to me.

Thanks again for the quick response!

jeremy-compostella commented 3 years ago

fix pushed to master.