Japanese text support in mutt |
|||
|
Note: this is out of date!
With the release of Mutt 1.4, the stable version of mutt has
much improved support for internationalization. The hacks described
below are no longer necessary. Make sure that $charset is set
appropriately (typically to EUC-JP), and add the directive: For older versions of muttAs of version 1.2.5i, the stock mutt does not support Japanese text very well. However, with a few filters and a dirty hack or two, it can be made to support it "well enough" to get some work done. This page describes that process. I'm going to assume from this point on that you have Japanese input working properly, and that you have kterm or some other multibyte-capable terminal emulator. If you don't, you'll need to deal with that before proceeding. Reading MailThe first real problem is that mutt's internal pager will not properly display Japanese text even in a kterm. This appears to be because it pretty-prints many of the binary characters required for some encodings as well as the ESCs used by the popular iso-2022-jp. In order to handle this, we need to tell mutt to use your .mailcap settings to view text/plain emails, and set up the .mailcap appropriately. Telling mutt to use .mailcap for text/plain is trivial; add the line auto_view text/plain to your .muttrc, /etc/Muttrc, or other favorite place to configure mutt. (Note that if you're setting this up for many users and wish to use a system-wide Muttrc, you will also have to create system-wide mailcap settings or this will break mutt for numerous unsuspecting users.) The next step in getting beautiful Japanese text in mutt is to update your .mailcap (or /etc/mailcap as noted above) to handle text/plain. Most mailcap files have no contingency for this, as practically anything can handle text/plain. In addition, we want to do some selective encoding changes. It turns out that euc-jp seems to be more robust in mutt's internal pager than iso-2022-jp, which is the encoding of most emails. I hypothesize that this is because euc-jp is less stateful; however, I really have no idea and that's a bunch of crap. While we're in there setting up mailcap entries for text/plain, we'll go ahead and use iconv (not that you will need iconv for this, but most distributions seem to install it by default) to convert the encodings. The completed addtions to .mailcap look like this:
text/plain; iconv -f iso-2022-jp -t euc-jp; test=charset=%{charset} \
&& test x`echo \"$charset\" | tr a-z A-Z` = xISO-2022-JP; copiousoutput
text/plain; cat; copiousoutput
Note that the ticks in that test command are in fact backticks, and that the backslash at the end of the first line is required. With these simple settings, you should now be able to successfully read Japanese text in mutt!
Writing MailIf you thought reading mail was a little ugly, writing mail is worse. The good news is that, despite the ugliness, it does work. The first thing you'll need is an editor that can create Japanese text in some encoding supported by iconv. If you're using a terminal-based editor in kterm (I use jed), you will be editing in euc-jp. Other editors may allow you to use alternate encodings such as Shift-JIS. If this is the case, simple replace euc-jp with shift-jis (or the appropriate encoding) in the examples below. Assuming that you have taken care of the editor problem and can edit Japanese text in some encoding, you will want a way to convert that text to iso-2022-jp before sending your mail. I put the following macro definitions in my .muttrc to facilitate this:
macro compose "j" "<filter-entry>iconv -f euc-jp -t iso-2022-jp\ny" \
"Convert to ISO-2022-JP"
macro compose "J" "<filter-entry>iconv -f iso-2022-jp -t euc-jp\ny" \
"Convert to EUC-JP"
This makes the j key convert to iso-2022-jp, and the J key convert back. The reverse-encoding macro is there to facilitate editing; once the message has been converted, you cannot edit it without converting it back to your editor's native encoding. In addition to these macros, you will likely want to put the command unset wait_key in your .muttrc to prevent mutt from asking you to press enter after conversion.The final step in sending your mail is to change its MIME-type to reflect the new character set. The best way I have found to do this is to press ^T, then replace us-ascii (or whatever your default character set is) with ISO-2022-JP (Note that case does seem to be case sensitive). If you know of a better way, please let me know... At this point you should have successfully created an email that can be decoded and viewed in any Japanese-capable mailreader, including your converted mutt. |