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

repl.sh (2499B)


      1 #!/bin/bash
      2 
      3 usage() {
      4 	printf "usage: $(basename $1) [-hal] mailid\n" >&2
      5 }
      6 
      7 doall=0
      8 dolist=0
      9 
     10 while getopts "hal" opt;
     11 do
     12 	case $opt in
     13 	a)
     14 		doall=1
     15 		;;
     16 	l)
     17 		dolist=1
     18 		;;
     19 	*)
     20 		usage $0
     21 		exit 1
     22 		;;
     23 	esac
     24 done
     25 shift $(expr $OPTIND - 1)
     26 
     27 if [ "$1" = "--" ];
     28 then
     29 	shift 1
     30 fi
     31 
     32 if [ $# -lt 1 ];
     33 then
     34 	usage $0
     35 	exit 1
     36 fi
     37 
     38 ids="$@"
     39 if [ -z "$ids" ];
     40 then
     41 	usage $0
     42 	exit 1
     43 fi
     44 
     45 nsubject=$(rpview -ve Subject -- "$ids")
     46 if [ -z "$nsubject" ];
     47 then
     48 	nsubject="Subject"
     49 else
     50 	case "$nsubject" in
     51 	Re:*)
     52 		;;
     53 	*)
     54 		nsubject="Re: ${nsubject}"
     55 		;;
     56 	esac
     57 fi
     58 
     59 from=$(rpview -ve ^From -- "$ids" | sed 's/\n//')
     60 cc=$(rpview -ve ^Cc -- "$ids" | sed 's/\n//')
     61 references=$(rpview -ve ^References -- "$ids" | sed 's/\n//')
     62 msgid=$(rpview -ve ^Message-ID -- "$ids" | sed 's/\n//')
     63 inreplyto=$(rpview -ve ^In-Reply-To -- "$ids" | sed 's/\n//')
     64 listpost=$(rpview -ve ^List-Post -- "$ids" \
     65 	| sed -e 's/.*mailto:\([^> ]*\).*/\1/')
     66 
     67 replytohdrs=$(rpview -ve ^Reply-To -- "$ids" | sed 's/\n//')
     68 replyto=""
     69 IFS='
     70 '
     71 for rt in $replytohdrs;
     72 do
     73 	if [ -z "$replyto" ];
     74 	then
     75 		replyto="$rt"
     76 	else
     77 		replyto="$replyto, $rt"
     78 	fi
     79 done
     80 
     81 if [ -n "$references" ] && [ -n "$msgid" ];
     82 then
     83 	references="$references $msgid"
     84 fi
     85 if [ -z "$references" ] && [ -n "$msgid" ];
     86 then
     87 	if [ -n "$inreplyto" ];
     88 	then
     89 		references="$inreplyto $msgid"
     90 	else
     91 		references="$msgid"
     92 	fi
     93 fi
     94 
     95 nto=""
     96 ncc=""
     97 if [ $dolist -eq 1 ] && [ -n "$listpost" ];
     98 then
     99 	nto="$listpost"
    100 fi
    101 if [ $doall -eq 1 ];
    102 then
    103 	if [ -z "$replyto" ];
    104 		if [ -z "$nto" ];
    105 		then
    106 			nto="$from"
    107 			ncc="$cc"
    108 		else
    109 			ncc="$from, $cc"
    110 		fi
    111 	then
    112 		if [ -z "$nto" ];
    113 		then
    114 			nto="$replyto"
    115 			ncc="$from, $cc"
    116 		else
    117 			ncc="$replyto, $from, $cc"
    118 		fi
    119 	fi
    120 fi
    121 if [ -z "$nto" ];
    122 then
    123 	if [ -z "$replyto" ];
    124 	then
    125 		nto="$from"
    126 	else
    127 		nto="$replyto"
    128 	fi
    129 fi
    130 
    131 printf "Date: $(LC_ALL=C date "+%a, %d %b %Y %T %z")\n"
    132 
    133 if [ -n "$msgid" ];
    134 then
    135 	printf "In-Reply-To: ${msgid}\n"
    136 fi
    137 if [ -n "$references" ];
    138 then
    139 	printf "References: ${references}\n"
    140 fi
    141 
    142 printf "User-Agent: rohrpost\n"
    143 printf "MIME-Version: 1.0\n"
    144 printf "Content-Type: text/plain; charset=utf-8\n"
    145 printf "Content-Transfer-Encoding: 8bit\n"
    146 printf "From: $(rpcfg -v defaultfrom)\n"
    147 printf "To: ${nto}\n"
    148 printf "Cc: ${ncc}\n"
    149 printf "Bcc:\n"
    150 printf "Subject: ${nsubject}\n"
    151 [ -e "$HOME/.mailheaders" ] && cat "$HOME/.mailheaders"
    152 printf "\n"
    153 
    154 printf "On $(LC_ALL=C date "+%a, %d %b %Y %T %z") ${from} wrote:\n"
    155 rpview -nb -- "$ids" | sed 's/^/> /' 
    156 printf "\n"
    157 
    158 [ -e $HOME/.signature ] && cat $HOME/.signature
    159