#!/bin/csh -f
# ml1    to organize IIJ mail logs to a html file
#     keep Subject, Date
#     put <hr> between letters
#     take off unnecessary items (after </PRE>)

rm -f top1 top2 all1 temp1

echo "" > temp1
echo "<pre>"  >> temp1

foreach i ($*)

  if(-f ${i}) then

    sed -e  '1,/^$/\!d' ${i} > top1

    cat top1 |grep ^Subject:   > top2
    cat top1 |grep ^Date:      >> top2

    if(-z top2) then
       echo this is not mail file
       goto saigo
    endif    

    echo "<hr>" >> temp1
    cat top2 |nkf -m >> temp1
    echo "" >> temp1
#      body    
    cat ${i} |sed '1,/^$/d' |sed '1,/<\/PRE>/\!d'| sed '/<\/PRE>/d' >>temp1

    echo "" >> temp1
 
    saigo:
    rm -f top1 top2 
  endif
end

echo "</pre>" >> temp1

cat temp1 |nkf -j > all1

