shithub: 9bbs

ref: b1387b2b58854f371d10d6dbcd85ac6eba802a76
dir: /bin/9bbs2nostromo/

View raw version
#!/bin/rc
# convert old message format to new message format.
rfork e
fn checkdir{
	if(! test -d $1){
		echo $1 does not exist >[1=2]
		exit checkdir
	}
}
fn seconds2rfc822{ date `{cat} | awk '{print $1 ", " $3 " " $2 " " $6 " " $4 " " $5}' }
fn usage{
	echo usage: 9bbs2nostromo src dst post >[1=2]
	exit usage
}
if(~ $#2 0 || ~ $#4 1)
	usage
src=$1
dst=$2
post=$3
checkdir $src
checkdir $dst
builtin cd $src
if(~ $#post 0 || ! ~ $post [0-9]*)
	post=1
for(i in `{ls | grep -e '^[0-9]'}){
	{
		echo From: `{cat $i/from}
		echo X-Room: `{cat name}
		echo Date: `{echo $i | seconds2rfc822}
		echo X-Date-N: $i
		echo
		cat $i/body
	} >$dst/$post
	echo $i '->' $post
	post=`{echo $post^+1 | bc}
}