#! /bin/csh
#========================================================
#========================================================
#==============@lbg[N@vO@==============
#========================================================
#========================================================
#======================== 1991 7/5 ======================
#============================= by p@M ============
#========================================================
#========================= Ver. 1.01 ====== 91/9/13 =====
#
#********************************************************
#**********@C@[`@**************************
#********************************************************
set nonomatch
	set path=(/etc /usr/etc /usr/ucb /bin /usr/bin /usr/sony/bin /usr/new /usr/new/mh /usr/pds/bin /usr/local/bin /usr/hosts)
	set data = "$USER : LOGIN : `date`"
	echo $data >> /home/root/LOG/LOGDATA
	set mail=/usr/spool/mail/$USER
	if (-e $mail && ! -z $mail ) inc
	if ( -f .tmp ) then
		rm .tmp
	endif
	if ( -d .tmp ) then
		goto start
	else
		mkdir .tmp
		chmod 700 .tmp
	endif
start:
	stty erase ^H
	echo "Welcome NCL net."
start00:
	echo -n "Do you want to use japanese? (y/n)"
	set key = $<
	if ( $key == "y" || $key == "Y" ) then
		set lang = j
		stty sjis
		cat /home/root/messjp
		goto start0
	endif
	if ( $key == "n" || $key == "N" ) then
		set lang = e
		stty ascii
		cat /home/root/messen
	else
		goto start00
	endif
start0:
	set lastmail = (`folder`)
	if ( $lastmail[3] == no ) then
		set mailn = 0
	else
		set mailn = $lastmail[3]
		folder -pack >> /dev/null
	endif
start1:
	cd ~
	echo " "
	if ( $lang == j ) then
		echo "  Cj["
		echo "@@@P@["
		echo "@@@Q@["
		echo "@@@R@[Xg"
		echo "@@@S@["
		echo "@@@T@pX[hύX"
		echo "@@@X@I"
		echo -n "  ԍIŉBiP|TAXj>"
	else
		echo "  * Main menue *"
		echo "      1  Send mail"
		echo "      2  Get mail"
		echo "      3  List mail"
		echo "      4  Delete mail"
		echo "      5  Change password"
		echo "      9  Exit"
		echo -n "Please select number. (1-5 or 9) >"
	endif
	set key = $<
	if ( x$key == x ) then
		goto start1
	endif
	set keyn = ` expr $key : '.*' `
	if ( $keyn != 1 ) then
		echo " "
		if ( $lang == j ) then
			echo "P|TAX̔ԍĉB"
		else
			echo "Enter number 1-5 or 9"
		endif
		goto start1
	endif
	switch ( $key )
		case 1:
			goto send
		case 2:
			goto get
		case 3:
			goto dir
		case 4:
			goto delete
		case 5:
			goto passwd
		case 9:
			goto end
		defaults:
	endsw
	echo " "
	if ( $lang == j ) then
		echo "P|TAX̔ԍĉB"
	else
		echo "Enter number 1-5 or 9"
	endif
	goto start1
#
#**********@dmc@C@[`@******************
#
#////////////////////////////////////////////////////////
#//////////@t@C@//////////////////////////
#////////////////////////////////////////////////////////
send:
	echo " "
	cd ~/.tmp
	set c = (*)
	if( $c[1] != * ) then
		ls -l | tail +2
		if ( $lang == j ) then
			echo "ȏ̃t@CcĂ܂B"
			echo -n "ĂłHi^j"
		else
			echo "These file is exist."
			echo -n "Do you want to delete these file(s) ?(y/n)"
		endif
		set key = $<
		if ( $key == "y" || $key == "Y" ) then
			rm *
			if ( $lang == j ) then
				echo "t@C܂B"
			else
				echo "These file(s) are deleted."
			endif
			goto send1
		endif
		if ( $key != "n" && $key != "N" ) then
			goto send
		endif
		if ( $lang == j ) then
			echo -n "t@Cǉ܂Hi^j"
		else
			echo -n "Do you add more file ?(y/n)"
		endif
		set key = $<
		if ( $key == "n" || $key == "N" ) then
			goto sendm
		endif
		if ( $key != "y" && $key != "Y" ) then
			goto send
		endif
	endif
send1:
	echo " "
	if ( $lang == j ) then
		echo "ǂ̕@Ńt@CAbv[h܂H"
		echo "@@P@wlncdl"
		echo "@@Q@xlncdl"
		echo "@@R@ylncdl"
		echo "@@X@Cj[ɖ߂"
		echo -n "  ԍIŉBiP|RAXj>"
	else
		echo "Select protocol"
		echo "    1  XMODEM"
		echo "    2  YMODEM"
		echo "    3  ZMODEM"
		echo "    9  Goto Main menu"
		echo -n "Please select number. (1-3 or 9) >"
	endif
	set key = $<
	if ( x$key == x ) then
		goto send1
	endif
	set keyn = ` expr $key : '.*' `
	if ( $keyn != 1 ) then
		echo " "
		if ( $lang == j ) then
			echo "P|RAX̔ԍĉB"
		else
			echo "Enter number 1-3 or 9"
		endif
		goto send
	endif
	@ count = 0
	switch ( $key )
		case 1:
			goto xmodem
		case 2:
			goto ymodem
		case 3:
			goto zmodem
		case 9:
			goto start1
		defaults:
	endsw
	echo " "
	if ( $lang == j ) then
		echo "P|RAX̔ԍĉB"
	else
		echo "Enter number 1-3 or 9"
	endif
	goto send
#
#//////////@dmc@t@C@//////////////////
#
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#++++++++++@wlncdl@++++++++++++++++++++++++++++++
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++
xmodem:
	echo " "
	if ( $lang == j ) then
		echo "wlncdlŎM܂B"
	else
		echo "Use Xmodem."
	endif
xmodem1:
	if ( $lang == j ) then
		echo -n "t@CĂB>"
	else
		echo -n "Enter file name. >"
	endif
	set fname = $<
	if ( x$fname == x ) then
		goto xmodem1
	endif
	if ( $lang == j ) then
		echo -n "njHi^j"
	else
		echo -n "Please send file(s) by XMODEM. Ready? (y/n)"
	endif
	set key = $<
	if ( $key == "n" || $key == "N" ) then
		goto send
	endif
	if ( $key == "y" || $key == "Y" ) then
		cd ~/.tmp
		set data = "$USER : SEND XM : `date`"
		echo $data >> /home/root/LOG/LOGDATA
		/usr/local/bin/rx $fname || goto xmerr
		set data = "$USER : SENDEND : `date`"
		echo $data >> /home/root/LOG/LOGDATA
#		set key = $<
		set c = (*)
 		if( $c[1] != * ) then
			if ( $lang == j ) then
				echo "MI"
				echo "ȉ̃t@CM܂B"
			else
				echo "End XMODEM."
				echo "File list :"
			endif
			ls
			cd ~
			goto sendm
		else
			if ( $lang == j ) then
				echo "t@CĂ܂B"
			else
				echo "Error \! There is no file."
			endif
			goto send
		endif
	endif
	goto xmodem
xmerr:
	if ( $lang == j ) then
		echo "wlncdlŃG[܂B"
	else
		echo "XMODEM send Error \!"
	endif
	goto send
#
#++++++++++@dmc@wlncdl@++++++++++++++++++++++
#
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#++++++++++@xlncdl@++++++++++++++++++++++++++++++
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ymodem:
	echo " "
	if ( $lang == j ) then
		echo "xlncdlŎM܂B"
		echo -n "njHi^j"
	else
		echo "Use YMODEM."
		echo -n "Please send file(s) by YMODEM. Ready? (y/n)"
	endif
	set key = $<
	if ( $key == "n" || $key == "N" ) then
		goto send
	endif
	if ( $key == "y" || $key == "Y" ) then
		cd ~/.tmp
		set data = "$USER : SEND YM : `date`"
		echo $data >> /home/root/LOG/LOGDATA
		/usr/local/bin/ry || goto ymerr
		set data = "$USER : SENDEND : `date`"
		echo $data >> /home/root/LOG/LOGDATA
#		set key = $<
		set c = (*)
 		if( $c[1] != * ) then
			if ( $lang == j ) then
				echo "MI"
				echo "ȉ̃t@CM܂B"
			else
				echo "End YMODEM"
				echo "File list :"
			endif
			ls
			cd ~
			goto sendm
		else
			if ( $lang == j ) then
				echo "t@CĂ܂B"
			else
				echo "Error \! There is no file."
			endif
			goto send
		endif
	endif
	goto ymodem
ymerr:
	if ( $lang == j ) then
		echo "xlncdlŃG[܂B"
	else
		echo "YMODEM send Error \!"
	endif
	goto send
#
#++++++++++@dmc@xlncdl@++++++++++++++++++++++
#
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#++++++++++@ylncdl@++++++++++++++++++++++++++++++
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++
zmodem:
	echo " "
	if ( $lang == j ) then
		echo "ylncdlŎM܂B"
		echo -n "njHi^j"
	else
		echo "Use ZMODEM"
		echo -n "Please send file(s) by ZMODEM. Ready? (y/n)"
	endif
	set key = $<
	if ( $key == "n" || $key == "N" ) then
		goto send
	endif
	if ( $key == "y" || $key == "Y" ) then
		cd ~/.tmp
		set data = "$USER : SEND ZM : `date`"
		echo $data >> /home/root/LOG/LOGDATA
		/usr/local/bin/rz || goto zmerr
		set data = "$USER : SENDEND : `date`"
		echo $data >> /home/root/LOG/LOGDATA
#		set key = $<
		set c = (*)
 		if( $c[1] != * ) then
			if ( $lang == j ) then
				echo "MI"
				echo "ȉ̃t@CM܂B"
			else
				echo "End ZMODEM."
				echo "File list :"
			endif
			ls
			cd ~
			goto sendm
		else
			if ( $lang == j ) then
				echo "t@CĂ܂B"
			else
				echo "Error \! There is no file."
			endif
			goto send
		endif
	endif
	goto zmodem
zmerr:
	if ( $lang == j ) then
		echo "ylncdlŃG[܂B"
	else
		echo "ZMODEM send Error \!"
	endif
	goto send
#
#++++++++++@dmc@ylncdl@++++++++++++++++++++++
#
#--------------------------------------------------------
#----------@C𑗂@------------------------------
#--------------------------------------------------------
sendm:
	echo " "
	if ( $lang == j ) then
		echo -n "͂ĉB>"
	else
		echo -n "Please enter address. >"
	endif
	set address = $<
	if ( x$address == x ) then
		goto sendm
	endif
	cd ~/..
	if ( -d $address ) then
		cd ~
		if ( $lang == j ) then
			echo -n " "$address"łˁHi^j"
		else
			echo -n "Do you want to send these file(s) to "$address" ? (y/n)"
		endif
		set key = $<
		if ( $key == "y" || $key == "Y" ) then
			goto nextsend
		endif
		goto sendm
	else
		if ( $lang == j ) then
			echo "G[I"$address"悪݂܂B"
		else
			echo "Error! There is not "$address"."
		endif
		@ count ++
		if ( $count >= 3 ) then
			if ( $lang == j ) then
				echo -n "~܂Hi^j"
			else
				echo -n "Do you want to stop the job? (y/n)"
			endif
			set key = $<
			if ( $key == "y" || $key == "Y" ) then
				goto start1
			endif
		endif
		goto sendm
	endif
	goto start1
nextsend:
	cd ~/.tmp
	if ( $lang == j ) then
		echo -n "RgĂB"
	else
		echo -n "Please enter comment.>"
	endif
	set comment = $<
	set com = ($comment)
	if ( x$com[1] == x ) then
		goto nextsend
	endif
nextinp:
	if ( $lang == j ) then
		echo -n "L[[hĂB"
	else
		echo -n "Please enter keyword.>"
	endif
	set keyword = $<
	set keyw = ($keyword)
	if ( x$keyw[1] == x ) then
		goto nextinp
	endif
sendm1:
	echo " "
	if ( $lang == j ) then
		echo " ----->"$address
		echo "Rg --->"$comment
		echo "L[[h ->"$keyword
		echo -n "ȏł낵łHi^j"
	else
		echo "Address --->"$address
		echo "Comment --->"$comment
		echo "Keyword --->"$keyword
		echo -n "OK?(y/n)"
	endif
	set key = $<
	if ( $key == "n" || $key == "N" ) then
		goto sendm
	endif
	if ( $key != "y" && $key != "Y" ) then
		goto sendm1
	endif
	tarmail1 "$keyword" $address "$comment" . || goto sendmerr
	set data = "$USER : SEND : $address : $keyword : `date`"
	echo $data >> /home/root/LOG/LOGDATA
	if ( $lang == j ) then
		echo "[𑗂܂B"
	else
		echo "You sent mail."
	endif
	rm ~/.tmp/*
	goto start1
sendmerr:
	echo 'mail send error.'
	goto sendm
#
#----------@dmc@C𑗂@----------------------
#
#////////////////////////////////////////////////////////
#//////////@t@C@////////////////////////////
#////////////////////////////////////////////////////////
get:
	echo " "
	if ( $mailn == 0 ) then
		if ( $lang == j ) then
			echo "[͂܂B"
		else
			echo "There is no mail."
		endif
		goto start1
	endif
	cd ~/.tmp
	set c = (*)
	if( $c[1] != * ) then
		rm *
	endif
get1:
	scan
	echo " "
	if ( $lang == j ) then
		echo "肽[io[͂ĂB"
		echo -n "iŝ݃LZj >"
	else
		echo 'Please Enter a mail number.(1-'$mailn')'
		echo -n "(If you want to cancel, push return key only) >"
	endif
	set num = $<
	if ( x$num == x ) then
		goto start1
	endif
	set n = `expr length $num`
	while ( $n )
		set nn = `expr substr $num $n 1`
		if ( $n == 1 ) then
			set str = 123456789
		else
			set str = 0123456789
		endif
		set flg = `expr index $nn $str`
		if ( $flg == 0  ) then
			if ( $lang == j ) then
				echo "ĂB"
			else
				echo "That is not a valid command."
			endif
			goto get1
		endif
		@ n = $n - 1
	end
	if ( $mailn < $num ) then
		if ( $lang == j ) then
			echo "Ⴂ܂B"
		else
			echo "That is not a valid command."
		endif
		goto get1
	endif
get4:
	scan $num
	if ( $lang == j ) then
		echo -n "̃[܂Hi^j"
	else
		echo -n "Do you want to get this mail ? (y/n)"
	endif
	set key = $<
	if ( $key == "n" || $key == "N" ) then
		goto get1
	endif
	if ( $key != "y" && $key != "Y" ) then
		goto get4
	endif
	show $num > abc
	set mailnum = $num
get2:
	if ( $lang == j ) then
		echo -n "L[[hĂB"
	else
		echo -n "Please enter keyword. >"
	endif
	set keyword = $<
	set keyw = ($keyword)
	if ( x$keyw[1] == x ) then
		goto get2
	endif
	untarmail1 -k "$keyword" abc || goto geterr
	set c = (*)
 	if( $c[1] == * ) then
		if ( $lang == j ) then
			echo "𓀎sI"
		else
			echo "Mail format is bad \!"
		endif
		goto get1
	endif
#
get3:
	echo " "
	if ( $lang == j ) then
		echo "ǂ̕@Ńt@C_E[h܂H"
		echo "@@P@wlncdl"
		echo "@@Q@xlncdl"
		echo "@@R@ylncdl"
		echo "@@X@Cj[ɖ߂"
		echo -n "  ԍIŉBiP|RAXj>"
	else
		echo "Please select protocol"
		echo "    1  XMODEM"
		echo "    2  YMODEM"
		echo "    3  ZMODEM"
		echo "    9  Goto Main menu"
		echo -n "Please select number. (1-3 or 9) >"
	endif
	set key = $<
	if ( x$key == x ) then
		goto get3
	endif
	set keyn = ` expr $key : '.*' `
	if ( $keyn != 1 ) then
		echo " "
		if ( $lang == j ) then
			echo "P|RAX̔ԍĉB"
		else
			echo "Enter 1-3 or 9."
		endif
		goto get3
	endif
	switch ( $key )
		case 1:
			goto sxmodem
		case 2:
			goto symodem
		case 3:
			goto szmodem
		case 9:
			cd ~/.tmp
			rm *
			goto start1
		defaults:
	endsw
	echo " "
	if ( $lang == j ) then
		echo "P|RAX̔ԍĉB"
	else
		echo "Enter 1-3 or 9."
	endif
	goto get3
geterr:
	if ( $lang == j ) then
		echo "[𓀏o܂B"
	else
		echo 'File Error \!'
	endif
	rm abc
	goto get
#
#//////////@dmc@t@C@////////////////////
#
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#++++++++++@rwlncdl@++++++++++++++++++++++++++++
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++
sxmodem:
	foreach  c (*)
		echo " "
		if ( $lang == j ) then
			echo $c' wlncdlőM܂B'
			echo -n "njHi^j"
		else
			echo "We send file $c"
			echo "Please get file by XMODEM."
			echo -n "Ready? (y/n)"
		endif
		set key = $<
		if ( $key == "n" || $key == "N" ) then
			goto get
		endif
		if ( $key == "y" || $key == "Y" ) then
			set data = "$USER : GET XM : $mailnum : `date`"
			echo $data >> /home/root/LOG/LOGDATA
			/usr/local/bin/sx $c || goto sxerr
			set data = "$USER : GETEND : `date`"
			echo $data >> /home/root/LOG/LOGDATA
			if ( $lang == j ) then
				echo "MI"
			else
				echo "End XMODEM"
			endif
		endif
	end
	rm *
	goto start1
sxerr:
	if ( $lang == j ) then
		echo "wlncdlŃG[܂B"
	else
		echo "XMODEM send Error \!"
	endif
	goto get3
#
#++++++++++@dmc@rwlncdl@++++++++++++++++++++
#
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#++++++++++@rxlncdl@++++++++++++++++++++++++++++
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++
symodem:
	echo " "
	if ( $lang == j ) then
		echo "xlncdlőM܂B"
		echo -n "njHi^j"
	else
		echo "Please get file by YMODEM."
		echo -n "Ready? (y/n)"
	endif
	set key = $<
	if ( $key == "n" || $key == "N" ) then
		goto get
	endif
	if ( $key == "y" || $key == "Y" ) then
		set data = "$USER : GET YM : $mailnum : `date`"
		echo $data >> /home/root/LOG/LOGDATA
		/usr/local/bin/sy * || goto syerr
		set data = "$USER : GETEND : `date`"
		echo $data >> /home/root/LOG/LOGDATA
		if ( $lang == j ) then
			echo "MI"
		else
			echo "End ZMODEM"
		endif
	endif
	rm *
	goto start1
syerr:
	if ( $lang == j ) then
		echo "xlncdlŃG[܂B"
	else
		echo "YMODEM send Error \!"
	endif
	goto get3
#
#++++++++++@dmc@rxlncdl@++++++++++++++++++++
#
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#++++++++++@rylncdl@++++++++++++++++++++++++++++
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++
szmodem:
	echo " "
	if ( $lang == j ) then
		echo "ylncdlőM܂B"
		echo -n "njHi^j"
	else
		echo "Please get file by ZMODEM."
		echo -n "Ready? (y/n)"
	endif
	set key = $<
	if ( $key == "n" || $key == "N" ) then
		goto get
	endif
	if ( $key == "y" || $key == "Y" ) then
		set data = "$USER : GET ZM : $mailnum : `date`"
		echo $data >> /home/root/LOG/LOGDATA
		/usr/local/bin/sz * || goto szerr
		set data = "$USER : GETEND : `date`"
		echo $data >> /home/root/LOG/LOGDATA
		if ( $lang == j ) then
			echo "MI"
		else
			echo "End ZMODEM"
		endif
	endif
	rm *
	goto start1
szerr:
	if ( $lang == j ) then
		echo "ylncdlŃG[܂B"
	else
		echo "ZMODEM send Error \!"
	endif
	goto get3
#
#++++++++++@dmc@rylncdl@++++++++++++++++++++
#
#////////////////////////////////////////////////////////
#//////////@fBNg[@//////////////////////
#////////////////////////////////////////////////////////
dir:
	echo " "
	if ( $mailn == 0 ) then
		if ( $lang == j ) then
			echo "[͂܂B"
		else
			echo "There is no mail."
		endif
		goto start1
	endif
	scan
	if ( $lang == j ) then
		echo "sL[ĉ"
	else
		echo "Push return key."
	endif
	set key = $<
goto start1
#
#//////////@dmc@fBNg[@//////////////
#
#////////////////////////////////////////////////////////
#//////////@t@C@////////////////////////////
#////////////////////////////////////////////////////////
delete:
	set lastmail = (`folder`)
	if ( $lastmail[3] == no ) then
		set mailn = 0
	else
		set mailn = $lastmail[3]
		folder -pack >> /dev/null
	endif
	echo " "
	if ( $mailn == 0 ) then
		if ( $lang == j ) then
			echo "[͂܂B"
		else
			echo "There is no mail."
		endif
		goto start1
	endif
del1:
	scan
	if ( $lang == j ) then
		echo "郁[io[͂ĂB"
		echo -n "iŝ݃LZj>"
	else
		echo "Enter mail number."
		echo -n "(If you want cancel, push return key only.) >"
	endif
	set num = $<
	if ( x$num == x ) then
		goto start1
	endif
	set n = `expr length $num`
	while ( $n )
		set nn = `expr substr $num $n 1`
		if ( $n == 1 ) then
			set str = 123456789
		else
			set str = 0123456789
		endif
		set flg = `expr index $nn $str`
		if ( $flg == 0  ) then
			if ( $lang == j ) then
				echo "ĂB"
			else
				echo "That is not a valid command."
			endif
			goto del1
		endif
		@ n = $n - 1
	end
	if ( $mailn < $num ) then
		if ( $lang == j ) then
			echo "Ⴂ܂B"
		else
			echo "That is not a valid command."
		endif
		goto del1
	endif
del2:
	scan $num
	if ( $lang == j ) then
		echo -n "̃[Ă낵Hi^j"
	else
		echo -n "Do you delete this mail really? (y/n)"
	endif
	set key = $<
	if ( $key == "n" || $key == "N" ) then
		goto del1
	endif
	if ( $key == "y" || $key == "Y" ) then
		rmm $num
		set data = "$USER : DEL : $num : `date`"
		echo $data >> /home/root/LOG/LOGDATA
		if ( $lang == j ) then
			echo "[ $num ܂B"
		else
			echo "You delete mail # $num"
		endif
		goto delete
	endif
	goto del2
#
#//////////@dmc@t@C@////////////////////
#
#////////////////////////////////////////////////////////
#//////////@pX[hύX@////////////////////////////
#////////////////////////////////////////////////////////
passwd:
	echo " "
	if ( $lang == j ) then
		passwd || echo "pX[h͕ύX܂łB" ; goto start1
		echo "pX[hύX܂B"
	else
		passwd || echo "Password was not changed." ; goto start1
		echo "Password was changed."
	endif
	goto start1
#
#//////////@dmc@pX[hύX@////////////////////
#
end:
	set data = "$USER : LOGOUT : `date`"
	echo $data >> /home/root/LOG/LOGDATA
	echo " "
	if ( $lang == j ) then
		echo "悤ȂB"
	else
		echo "Good by."
	endif
	exit
