rohrpost

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

rpmasssend (1387B)


      1 #!/bin/sh
      2 
      3 usage() {
      4 	printf "usage: %s [-hd] [-s sent folder] [-m folder] addresses.txt 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 2 ];
     37 then
     38 	usage $0
     39 fi
     40 
     41 addresses="$1"
     42 shift 1
     43 
     44 if [ -z "$folder" ];
     45 then
     46 	folder=$(rpcfg -v fold_drafts)
     47 	if [ $? -eq 1 ];
     48 	then
     49 		echo "Please specify fold_drafts in rpcfg."
     50 		exit 1
     51 	fi
     52 fi
     53 
     54 if [ -z "$sentfolder" ];
     55 then
     56 	sentfolder=$(rpcfg -v fold_sent)
     57 fi
     58 
     59 mailer=$(rpcfg -v send_cmd)
     60 if [ $? -eq 1 ];
     61 then
     62 	echo "Please specify a send_cmd in rpcfg."
     63 	exit 1
     64 fi
     65 
     66 for mid in $(rpids -m $folder -- "$@");
     67 do
     68 	totalnum="$(wc -l "${addresses}" | cut -d' ' -f 1)"
     69 	nownum=0
     70 	cat "${addresses}" \
     71 	| while read -r address;
     72 	do
     73 		[ -z "${address}" ] && continue
     74 
     75 		nownum=$(($nownum + 1))
     76 		printf "Sending to (%d/%d): %s\n" "${nownum}" "${totalnum}" "${address}"
     77 		{
     78 			printf "To: %s\n" "${address}"
     79 			rpview -m $folder -r $mid | grep -v To:
     80 		} | eval $mailer
     81 		[ $? -gt 0 ] && exit 1
     82 	done
     83 
     84 	echo "$mid was sent successfully."
     85 	continue
     86 	if [ ! -z "$sentfolder" ];
     87 	then
     88 		rpmv -qm $folder $sentfolder $mid
     89 	else
     90 		if [ $dodelete -eq 1 ];
     91 		then
     92 			rprm -qm $folder $mid
     93 		fi
     94 	fi
     95 done
     96