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

rpedit (877B)


      1 #!/bin/sh
      2 
      3 usage() {
      4 	printf "usage: %s [-h] [-m folder] id\n" "$(basename $1)" 2>&1
      5 	exit 1
      6 }
      7 
      8 folder=""
      9 
     10 while getopts "hm:" opt;
     11 do
     12 	case $opt in
     13 	m)
     14 		folder="$OPTARG"
     15 		;;
     16 	*)
     17 		usage $0
     18 		;;
     19 	esac
     20 done
     21 shift $(expr $OPTIND - 1)
     22 
     23 if [ "$1" = "--" ];
     24 then
     25 	shift 1
     26 fi
     27 
     28 if [ $# -lt 1 ];
     29 then
     30 	usage $0
     31 fi
     32 
     33 if [ -z "$folder" ];
     34 then
     35 	folder=$(rpsel)
     36 fi
     37 
     38 id=$(rpids -m $folder -- $* | awk -F' ' '{print $1}')
     39 if [ -z "$id" ];
     40 then
     41 	usage $0
     42 fi
     43 
     44 tmpfile=$(mktemp /tmp/rpedit.XXXXXXX.eml)
     45 signalh() {
     46 	rm -f $tmpfile
     47 }
     48 trap 'signalh' 3 6 9 15
     49 
     50 rpview -m $folder -r $id > $tmpfile
     51 md5before=$(md5sum $tmpfile)
     52 eval $EDITOR $tmpfile
     53 md5after=$(md5sum $tmpfile)
     54 
     55 if [ "$md5before" != "$md5after" ];
     56 then
     57 	rprm -qm $folder $id
     58 	mid=$(rpadd -m $folder -f seen $tmpfile)
     59 	if [ $? -eq 0 ];
     60 	then
     61 		PAGER= rpscan -m $folder $mid
     62 	fi
     63 else
     64 	echo "Nothing changed. Aborting."
     65 fi
     66 
     67 signalh
     68