Composing in utf8 from latin1 terminal

nunojsilva at ist.utl.pt nunojsilva at ist.utl.pt
Tue Oct 23 21:31:45 UTC 2018


On 2017-10-12, nunojsilva at ist.utl.pt wrote:

> Recently, I have tried to use mutt on a non-utf8 terminal.  Everything
> works as expected in an utf8 environment, but when I compose new e-mails
> in a latin1/ISO-8859-1 terminal, mutt will expect the file to be in the
> same encoding as the terminal, while my text editor will save the file
> in utf8. The result is that non-ASCII characters get misinterpreted,
> which can affect the message headers as well (e.g. real names in To: and
> Cc:).
[...]
> Is there some way to configure mutt so that it always uses utf8 to read
> the new message after I exit the editor? Or a way to enable some
> encoding autodetection that can tell utf8 apart from latin1?

So far I did not find a way to change this on the mutt side, but I made
a new major mode for mutt messages in Emacs (the editor I use with
mutt), with a hook that changes the file encoding to latin1 if the file
was opened in a latin1 terminal and Emacs cannot detect a non-ASCII file
encoding.

It appears to work here. I'm sure someone who is more versed in Emacs
than me would be able to come up with a more elegant solution, but I'm
sharing mine here just in case it is useful to somebody else someday:


(define-derived-mode my-mutt-message-mode message-mode "MuttMSG")
(add-hook
 'my-mutt-message-mode-hook
 (lambda ()
   (when (equal (terminal-coding-system) 'iso-latin-1-unix)
     (let ((encoding (detect-coding-region (point-min) (point-max))))
       (when (or
              (equal encoding '(undecided-unix))
              (equal encoding '(undecided)))
         (setq buffer-file-coding-system 'iso-latin-1-unix))))))
(add-to-list 'auto-mode-alist '("/mutt" . my-mutt-message-mode))

-- 
Nuno Silva



More information about the Mutt-users mailing list