Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!rutgers!ucsd!nosc!helios.ee.lbl.gov!pasteur!ucbvax!dadla.la.tek.COM!jamesp From: jamesp@dadla.la.tek.COM ("James T. Perkins") Newsgroups: comp.mail.mh Subject: Re: aliases Message-ID: <8810022200.AA04310@dadla.LA.TEK.COM> Date: 2 Oct 88 22:00:03 GMT References: <9039@teemc.UUCP> Sender: daemon@ucbvax.BERKELEY.EDU Reply-To: jamesp%dadla.la.tek.com@ICS.UCI.EDU Organization: The Internet Lines: 146 > Is there any way that I can have MH expand the alias list BEFORE going into > the editor so that every time I edit a message being sent to an alias > list I get the real destination IN THE FILE that I am editting? I want > to see the actual addresses that the message will be sent to, during the > edit process. Further, I want it to be automatic. > Michael R. Wayne --- TMC & Associates --- wayne@teemc.uucp Well, I would suggest looking into the Editor-next capability. The second editor could then process the message, expanding aliases, before reinvoking the editor on it. For example (I tested this), suppose you want to use vi the first time you edit a message, then the next time (when you answer edit to the what now prompt), you want vi back with the To and Cc lines expanded with aliases from you /usr1/jamesp/.mh_aliases file: Your .mh_profile: Editor: vi vi-next: mhvi ali: -alias /usr1/jamesp/.mh_aliases The mhvi program (actually a UNIX shell script), follows. It is an icky hack done to prove that the desired actions could actually be performed. Caveat Emptor!!! _ ___ | | / _ \ James T. Perkins, jamesp@dadla.la.tek.com, (503)629-1149 | |__ | |_| | Tektronix Logic Analyzers, DAS System Software, Disk Services |____||_| |_| MS 92-725, PO Box 4600, Beaverton OR 97075 This package is sold by weight, not by volume. Some settling of contents may have occurred during shipping and handling. ---- cut here ---- : mhvi -- expands "To:", "Cc:" headers in the message with the aid : of awk, sed and ali, then invokes vi on the message. case $# in 1) file="$1";; *) echo "usage: $0 file" 1>&2; exit 1;; esac # get a list of To: recipients. The awk script reads the To: line and all # following To: lines, and builds up a list of recipients. It then echos # each recipient prepended and postpended with "+". There may be some # spaces inside the +'s that will be eaten out later. ToRecipients="` awk ' BEGIN { recip[""] = ""; } $1 ~ /^[Tt]o:$/ { zero = substr($0, length($1) + 1, length($0)); num = split(zero, recip, ","); flag++; next; } flag != 0 && $0 !~ /^[ \t]/ { flag = 0; next; } flag != 0 { newnum = split($0, newrecip, ","); for (i = 1; i <= newnum; i++) { recip[++num] = newrecip[i]; } } END { for (i in recip) { if (recip[i] ~ /[A-Za-z0-9]/) { printf("+%s+", recip[i]); } } } ' $file`" # Turn "+"'s into true delimiters, with no extra whitespace. ToRecipients=`echo $ToRecipients | sed -e 's/[ ]*++[ ]*/" "/g' -e 's/[ ]*+[ ]*/"/g'` echo To: $ToRecipients # get a list of Cc: recipients. The awk script reads the Cc: line and all # following Cc: lines, and builds up a list of recipients. It then echos # each recipient prepended and postpended with "+". There may be some # spaces inside the +'s that will be eaten out later. CcRecipients="` awk ' BEGIN { recip[""] = ""; } $1 ~ /^[Cc]c:$/ { zero = substr($0, length($1) + 1, length($0)); num = split(zero, recip, ","); flag++; next; } flag != 0 && $0 !~ /^[ \t]/ { flag = 0; next; } flag != 0 { newnum = split($0, newrecip, ","); for (i = 1; i <= newnum; i++) { recip[++num] = newrecip[i]; } } END { for (i in recip) { if (recip[i] ~ /[A-Za-z0-9]/) { printf("+%s+", recip[i]); } } } ' $file`" # Turn "+"'s into true delimiters, with no extra whitespace. CcRecipients=`echo $CcRecipients | sed -e 's/[ ]*++[ ]*/" "/g' -e 's/[ ]*+[ ]*/"/g'` echo Cc: $CcRecipients # Now expand the To and Cc recipients using ali. We write short shell # scripts to call ali to accomplish this (because shell quoting is ugly). echo ali $ToRecipients > /tmp/sh.$$ ToAli=`sh < /tmp/sh.$$ | awk '{ if (NR > 1) printf(", "); printf("%s", $0); }'` echo ToAli: $ToAli # Only expand Cc Aliases if there are any to expand case "$CcRecipients" in \"*) echo ali $CcRecipients > /tmp/sh.$$ CcAli=`sh < /tmp/sh.$$ | awk '{ if (NR > 1) printf(", "); printf("%s", $0); }'` echo CcAli: $CcAli ;; *) echo no CcAli; CcAli="";; esac #Okay, now substitute To and Cc lines in the original document with ToAli and #CcAli. awk ' BEGIN { to = "'"$ToAli"'"; cc = "'"$CcAli"'"; } $1 ~ /^[Cc]c:$/ { print "Cc: " cc; flag++; next; } $1 ~ /^[Tt]o:$/ { print "To: " to; flag++; next; } flag != 0 && $0 ~ /^[ \t]/ { next; } { flag = 0; print $0; } ' $file > /tmp/sh.$$ mv /tmp/sh.$$ $file exec vi $file