#!/bin/sh
for x in * ; do
 echo "convert $x"
#
# Here is content
#
# I use nkf here but iconv can be used too.  I make UTF-8 and iso-2022-jp version.
# I found Content-Type is needed for UTF-8 when importing to MacBook mail program
# ISO-2022-JP seems to be quite robust and does not need content-type (I dd it anyway)
#
# For mutt, UTF-8 works better but needs to fix title which was OK initially in pst.
# Need some idea but not needed now.  (procmail body filtering?)
#
# This will convert mail box content to UTF-8 and
# -S for shift-jis input
# -w for UTF-8
 nkf -S -w < "$x" | \
 sed -e 's/[Cc]ontent-[Tt]ype:.*text\/plain.*$/Content-Type: text\/plain; charset=UTF-8/' \
     -e 's/[Cc]ontent-[Tt]ype:.*text\/html.*$/Content-Type: text\/html; charset=UTF-8/' \
 > "$x.UTF-8.mbox"
# -S for shift-jis input
# -j for ISO-2022-JP
 nkf -S -j < "$x" | \
 sed -e 's/[Cc]ontent-[Tt]ype:.*text\/plain.*$/Content-Type: text\/plain; charset=iso-2022-jp/' \
     -e 's/[Cc]ontent-[Tt]ype:.*text\/html.*$/Content-Type: text\/html; charset=iso-2022-jp/' \
 > "$x.ISO-2022-JP.mbox"
#
# This is an example of using "iconv" for Western European Windows PST:
#
# iconv -f ISO-8859-1 -t UTF-8 $x | ....
done

