/********************************************************************/
/*	$VER: CarbonCopy.spot 1.1 (9.8.93)			    */
/*	Peter Hanrahan						    */
/*								    */
/*	CC.spot is a utility to allow SPOT to send messages to	    */
/*	multiple  recipients.					    */
/*	When  run from SPOT it  will run  the text editor (set	    */
/*	in  the  script).  The first lines of the message must	    */
/*	contain  the  names and addresses of the recipients in	    */
/*	the  form `CC:  name @ address, name @ address '.	    */
/*	Each  line  of these addresses must start with `CC:  '	    */
/*	and  when  more  than one address is listed on a line,	    */
/*	the address must terminate with a `,'.			    */
/*	                                                      	    */
/*	You  must  be in a message area to use CC.spot, and if	    */
/*	you  are  in  a  netmail  area  the  fido  address  is	    */
/*	neccessary.  If  you  are in  an  echo mail  area, the	    */
/*	address may be omitted as it is not used.		    */
/********************************************************************/




address spot
options results
kludge = '01'x||'Via SpotCC: V1.1'

ed = 'ED -Sticky'			/*Your editor command*/
tmp1='T:CC1.tmp'			/*Name of first temp file*/
tmp2='T:CC2.tmp'			/*Name of second temp file*/
width = 76				/*Text width for CC list*/

ismessages
if rc > 0 then do
  'requestnotify "Must be in a message area!"'
  exit
end

/*trace results*/

CR = '0d'x
QU = '22'x
NL = '0a'x

'gettoaddress'
echo = rc

TOP:

address command ed tmp1

Call open(mas,tmp1,r)
cc = 0
do forever
  cline =readln(mas)
  ccheck = upper(left(cline,3))
  if ccheck ~= 'CC:' then leave
  cline = substr(cline,5)
  do forever
    if cline = '' then leave
    i = index(cline,',')
      if i > 0 then do
      usr = left(cline,i-1)
      cline = substr(cline,i+2)
    end
    else do
      usr = cline
    end
    cc = cc + 1
    user.cc = usr
    at = index(usr,'@')
    if at > 1 then do
      nam.cc = left(usr,at-2)
      addr.cc = substr(usr,at+2)
    end
    else do
      if echo = 0 then do
        'requestnotify PROMPT "You MUST supply an address for all netmail"'
        close(mas)
        call TOP
        EXIT
      end
      nam.cc = usr
    end
    if echo = 5 then user.cc = nam.cc
    if i = 0 then leave
  end
end
mbod = readch(mas,60000)
call close(mas)
if cline~= '' then mbod = cline||CR||mbod

do me = 1 to cc
  call open(meso,tmp2,w)
  call writeln(meso,kludge)
  call writech(meso,mbod)
  if cc > 2 then cclist =NL||NL'(Copies sent to:'NL
  else cclist = NL||NL'(Copy sent to:'NL
  com = 0
  wi = 0
  do ccl = 1 to cc
    if me = ccl then iterate
    if com > 0 then cclist = cclist','
    com = 1
    usr = ' 'user.ccl
    wil = length(usr)+1
    wid = wi + wil
    if wid > width then do
      cclist = cclist||NL||usr
      wi = wil
    end
    else do
      cclist = cclist||usr
      wi = wid
    end
  end
  call writech(meso,cclist)
  call writeln(meso,')'||'0a'x)
  call close(meso)
  if me = 1 then do
    'spot2front'
    'write TO' QU||nam.me||QU 'TOADDR' QU||addr.me||QU 'FILE' QU||tmp2||QU 'NOEDIT'
    'lastmessage'
    'getsubject'
    subj = result
    'progressopen TITLE "Processing mail"'
    preq = result
  end
  else 'write TO' QU||nam.me||QU 'TOADDR' QU||addr.me||QU 'SUBJECT' QU||subj||QU 'FILE' QU||tmp2||QU 'NOEDIT NOGUI'
  'progressupdate' preq me cc
end
'progressclose' preq
address command 'Delete >NIL:' tmp1
address command 'Delete >NIL:' tmp2
