今日は3年ぶりの皆既月食。
空は晴れたし、仕事も早めに切り上げられて、なんとか月をみあげることができました。
気が向いたら更新なダラダラブログ
#!/bin/bash -f
#メール変換のメイン処理ループ
function mailconv_main()
{
# カウンター設定
max=`ls *.eml|wc -l`
cnt=1
# ファイルがなければリターン
if [ $max -eq 0 ] ; then
return
fi
#出力mboxファイル名の設定
arc="`pwd`".mbox
rm -f "$arc"
#カレントディレクトリemlファイル読み込み
for item in *.eml
do
#ファイルが存在しなければ次のループへ
if [ ! -f $item ] ; then
continue
fi
opt=""
#メールからContent-Type text/plain; charset=の行を取得
contenttype=`perl -p -e 's/;\r\n//g' < "$item" | grep -i 'Content-Type:.*charset=' | head -1`
if [ ! -z "$contenttype" ] ; then
#charsetの指定から文字コードを取得
charset=`echo $contenttype | sed -e 's/.* charset=\(.*\)/\1/' | sed -s 's/"//g' | tr [A-Z] [a-z]`
#文字コードに併せてnkfのオプションを設定
if [[ "$charset" =~ utf-8 ]]; then
opt="-w";
elif [[ "$charset" =~ iso-2022-jp ]]; then
opt="-j";
elif [[ "$charset" =~ us-ascii ]]; then
opt="-j";
elif [[ "$charset" =~ iso-8859-1 ]]; then
opt="-j";
elif [[ "$charset" =~ shift_jis ]]; then
opt="-s";
elif [[ "$charset" =~ windows-31j ]]; then
opt="-s";
elif [[ "$charset" =~ cp932 ]]; then
opt="-s";
elif [[ "$charset" =~ euc-jp ]]; then
opt="-e";
else
echo "Unknown Charset : $item : $contenttype : $charset"
fi
fi
if [ -z "$opt" ] ; then
# jis, shift_jis, utf-8に当てはまらない場合はjisを指定
opt="-j"
fi
#変換対象の表示
echo "$arc : $cnt/$max $opt"
# nkfを使用して文字コードを変更 -m0を指定する
nkf -m0 -Lu $opt $item | formail >> $arc
#カウントアップ
cnt=`expr $cnt + 1`
done
return 0
}
#カレントディレクトリ以下のディレクトリを検索
find . -type d | while read directory
do
pushd "$directory"
#変換メインをコール
mailconv_main
popd
done
---------------------------------------------------------