Setting up Japanese e-mail for Debian users

I was looking for a Japanese e-mail solution using pine, with pico as the editor, because I am not a fan of Emacs/Mule. We need a Japanese kana/kanji conversion engine (Canna); we do not need (for this application) an ‘input engine’ (kinput2) because its functions are built into the Japanized version of pine which we will use.

1. Installing Canna

This just involves installing the Debian packages canna and libcanna1g, available in standard Debian distributions.

2. Compiling pico and pine

There is no Debian package for Japanese-capable pine/pico, not even in the Debian-JP project. You can use sources from FreeBSD, but to make them work requires some tweaking.

  1. Get the files
    into your home directory, from, ja-pine-3.95, sources.
  2. Do tar xfvz pine3.95.tar.gz. This creates a directory pine3.95 with lots of stuff in it. Move into this directory.
  3. Do tar xfvz ../pine3.95lj1.1b2.tar.gz. This creates (inside the pine3.95 directory) a new directory called japan .
  4. Do (from inside the pine3.95 directory) patch -p0 <japan/pine3.95lj1.1b2.diff .
  5. Do (from inside the pine3.95 directory) patch -p0 <../pine3.95lj1.1b2-b3.diff
  6. Edit pico/makefile.lnx; change the following:
    • DASHO should be -O2 (normal build).
    • -DKANJI -DCANNA should be added to CFLAGS
    • I removed the -DMOUSE flag because the mouse did not work in pine/pico anyway.
    • LIBS= $(EXTRALIBES) -ltermcap
      should be changed to
      LIBS= $(EXTRALIBES) -lcanna -lncurses
    • To the OFILES/CFILES/HFILES sections you should add kanji, jctype, and canna, of course with extensions .o, .c, and .h respectively.
    • Do a global replace, changing tcap everywhere to tinfo (otherwise some of your keys, in particular the END key, will not work).
  7. Edit pico/kanji.h. Change the definitions (line 37)
       #define DEF_KFILECODE K_EUC
       #define DEF_KFILECODE K_JIS
  8. Edit pico/os_unix.h. Add || defined(lnx) to the line after /* Machine/OS definition */.
  9. Edit pico/os_unix.c. Comment out the declaration
    extern char *sys_errlist[];.
  10. Edit pine/makefile.lnx; change the following:
    • OPTIMIZE should be -O2 (remove comment)
    • Comment out the line beginning with DEBUG.
    • In the line STDLIBES you should replace -ltermcap with -lncurses -lcanna -lcrypt
    • -DKANJI -DCANNA should be added to CFLAGS .
    • I removed the -DMOUSE flag because the mouse did not work in pine/pico anyway.
  11. Edit pine/osdep/os-lnx.h. Comment out the 2 lines under System V terminal driver; uncomment the two lines under POSIX terminal driver. Uncomment
    #define USE_TERMINFO.
  12. Edit pine/osdep/os-lnx.ic. Change the line
  13. Edit imap/ANSI/c-client/Makefile.There is a section called lnx:. To the last line of this section, add LDFLAGS="-lcrypt" .

Now (finally) everything will compile OK when you type ./build lnx . You can install the binaries in place of your existing pine (if you have it), or rename them (e.g. picoj and pinej) and install them in /usr/local/bin . That is what I did. Then in /usr/local/bin I also made a script xjpine containing:

kterm -e pinej -p $HOME/.pinercj

Then in /etc/menu a file xjpine containing:

?package(local.mystuff):needs="X11" section="Apps/Net" icon="none" \
title="Pine (Japanese)" command="/usr/local/bin/xjpine"

Then I ran update-menus as root, and restarted fvwm95 . Now in the Debian X menus, under Applications/Net, both pine and pine (Japanese) are present. Each will have its own resource file for every user (.pinerc and .pinercj respectively). The ‘normal’ pine will have the Western European charset (iso-8859-1) specified, while the Japanese pine will have iso-2022-jp.

3. Using Canna

This version of pico has Canna support built-in, without needing kinput2. You must of course run pico (or pine) in a kanji display (kon or kterm). Then, to start Canna, you press control-SPACE. A hiragana “a” will be displayed at the bottom left.

If Canna is running, anything you type is converted into hiragana and placed between ‘fenceposts’ (vertical bars) as follows:

  1. Type a phrase, e.g. noboribetsuhahokkaidouniarimasu.
  2. Text between fenceposts: |のぼりべつはほっかいどうにあります。
  3. Press SPACE; the text is converted: |登別は 北海道にあります。| The first part of the phrase is highlighted (indicated by red in this example).
  4. If the conversion is OK, press ENTER; the fenceposts disappear and the phrase becomes part of your text. This is what you will do most of the time.
  5. If the conversion (step 3) is only partly OK, you can manipulate the highlighted part using control-F, control-I, and control-O. Let’s say that for some reason we want the word 北海道 to be spelled in katakana. Control-F now moves the highlighted part:
    This is not quite what we want. The highlighted part can be made shorter by pressing control-I:
    (the highlighted part can also be made longer by pressing control-O). The selection is now exactly what we want; pressing SPACE does a new conversion for the selection only. In the meantime Canna has changed into (this, IMHO, is a bug). By pressing control-F again to highlight , this can again be corrected (press SPACE). To accept the result, press ENTER.
  6. Finding out how to use Canna takes some experimenting. It is in general not so different from Japanese ‘wapros’ or the conversion system used in Japanese Win95. Some keys have special functions: e.g. control-L changes the text inside the fenceposts into lower-case double-width Romaji: double width (control-U changes the text into uppercase).

4. Permission problem with Canna

After an upgrade I got a problem with Canna in jpico with several messages appearing like

[ iroha ] をモウントできませんでした

This does not occur when running jpico as root. So a permission problem.

5. Canna and kinput2

Japanese pine, as described above, contains machinery to query the Canna conversion server directly. In other situations kinput2 must be used as an intermediary. For instance when kinput2 has been started (by means of kinput2 &) you can open kterm and then use Canna in any program (even non-Japanese ones such as joe). This only works if kterm is started with the X Input Method enabled:

kterm -xim

This, of course, took me ages to find out. The conversion start key is shift-space.

6. Canna and Mozilla

It is possible to use Canna in Mozilla (for search engine input and e-mail). This, of course, also took me ages to find out. It seems to be important that the environment variables XMODIFIERS and @im are set as follows:

export XMODIFIERS=@im=kinput2

Also the locale has to be set somehow; that means that LANG, or LC_CTYPE, or LC_ALL has to be set to ja_JP or something similar. What the minimum requirement / safest general solution is, I do not know. This I still have to sort out. Anyway, it is then possible to call up the Japanese conversion system with shift-space, and to write Japanese e-mails in Mozilla.

Simplue WordPress theme, Copyright © 2013 Simplue WordPress theme is licensed under the GPL.