rohrpost

A commandline mail client to change the world as we see it.
git clone git://r-36.net/rohrpost
Log | Files | Refs | README | LICENSE

rpsend (1022B)


      1 #!/bin/sh
      2 
      3 usage() {
      4 	printf "usage: %s [-hd] [-s sent folder] [-m folder] id\n" \
      5 		"$(basename $1)" 2>&1
      6 	exit 1
      7 }
      8 
      9 dodelete=0
     10 
     11 folder=""
     12 sentfolder=""
     13 while getopts "hm:ds:" opt;
     14 do
     15 	case $opt in
     16 	d)
     17 		dodelete=1
     18 		;;
     19 	m)
     20 		folder="$OPTARG"
     21 		;;
     22 	s)
     23 		sentfolder="$OPTARG"
     24 		;;
     25 	*)
     26 		usage $0
     27 		;;
     28 	esac
     29 done
     30 shift $(($OPTIND - 1))
     31 if [ "$1" = "--" ];
     32 then
     33 	shift 1
     34 fi
     35 
     36 if [ $# -lt 1 ];
     37 then
     38 	usage $0
     39 fi
     40 
     41 if [ -z "$folder" ];
     42 then
     43 	folder=$(rpcfg -v fold_drafts)
     44 	if [ $? -eq 1 ];
     45 	then
     46 		echo "Please specify fold_drafts in rpcfg."
     47 		exit 1
     48 	fi
     49 fi
     50 
     51 if [ -z "$sentfolder" ];
     52 then
     53 	sentfolder=$(rpcfg -v fold_sent)
     54 fi
     55 
     56 mailer=$(rpcfg -v send_cmd)
     57 if [ $? -eq 1 ];
     58 then
     59 	echo "Please specify a send_cmd in rpcfg."
     60 	exit 1
     61 fi
     62 
     63 for mid in $(rpids -m $folder -- "$@");
     64 do
     65 	rpview -m $folder -r $mid | eval $mailer
     66 	[ $? -gt 0 ] && exit 1
     67 	echo "$mid was sent successfully."
     68 	if [ ! -z "$sentfolder" ];
     69 	then
     70 		rpmv -qm $folder $sentfolder $mid
     71 	else
     72 		if [ $dodelete -eq 1 ];
     73 		then
     74 			rprm -qm $folder $mid
     75 		fi
     76 	fi
     77 done
     78