commit 505cb66192e4bcb156af687619fce94afd3bbe84 parent f10990285c2825c97d24021e280c7c7627f8a5ff Author: Christoph Lohmann <20h@r-36.net> Date: Tue, 22 Jan 2019 21:43:37 +0100 Add rpmasssend. Diffstat:
bin/rpmasssend | | | 91 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 91 insertions(+), 0 deletions(-)
diff --git a/bin/rpmasssend b/bin/rpmasssend @@ -0,0 +1,91 @@ +#!/bin/sh + +usage() { + printf "usage: %s [-hd] [-s sent folder] [-m folder] addresses.txt id\n" \ + "$(basename $1)" 2>&1 + exit 1 +} + +dodelete=0 + +folder="" +sentfolder="" +while getopts "hm:ds:" opt; +do + case $opt in + d) + dodelete=1 + ;; + m) + folder="$OPTARG" + ;; + s) + sentfolder="$OPTARG" + ;; + *) + usage $0 + ;; + esac +done +shift $(($OPTIND - 1)) +if [ "$1" = "--" ]; +then + shift 1 +fi + +if [ $# -lt 2 ]; +then + usage $0 +fi + +addresses="$1" +shift 1 + +if [ -z "$folder" ]; +then + folder=$(rpcfg -v fold_drafts) + if [ $? -eq 1 ]; + then + echo "Please specify fold_drafts in rpcfg." + exit 1 + fi +fi + +if [ -z "$sentfolder" ]; +then + sentfolder=$(rpcfg -v fold_sent) +fi + +mailer=$(rpcfg -v send_cmd) +if [ $? -eq 1 ]; +then + echo "Please specify a send_cmd in rpcfg." + exit 1 +fi + +for mid in $(rpids -m $folder -- "$@"); +do + cat "${addresses}" \ + | while read -r address; + do + printf "Sending to: %s\n" "${address}" + { + printf "To: %s\n" "${address}" + rpview -m $folder -r $mid | grep -v To: + } | eval $mailer + [ $? -gt 0 ] && exit 1 + done + + echo "$mid was sent successfully." + continue + if [ ! -z "$sentfolder" ]; + then + rpmv -qm $folder $sentfolder $mid + else + if [ $dodelete -eq 1 ]; + then + rprm -qm $folder $mid + fi + fi +done +