;+
;NAME:
;	Mailfile
;
;PURPOSE:
;	Send e-mail of filename to user on vms or osf machine,
;	ask their address if necessary
;
;Category:
;	GEN, BATSE/ARCHIVE
;INPUTS
;	filename (string)
;	
;KEYWORDS
;	noquery, if set will not ask the user questions about their email
;	address
;
;Modification History
;
;Modified 8/9/94 by Amy Skowronek to display the mail address as the user
; entered it when confirming that something was mailed, rather than displaying
; the fixed version our system needs (i.e., leave out quotes and smtp%)
; Modified 6/20/95 by AES - enabled mailing on OSF systems.
; __Documentation header added by EAC 5/8/96
; 5/8/96 by EAC - added keyword automail for noninteractive operation,
;  if set mailfile will not query the reader unless they forgot to
;  specify and email address
;-
pro mailfile, filename, noquery=noquery, automail=automail
;
@remotecom
;
if keyword_set(noquery) then goto,get_addr
if keyword_set(automail) then automail=1 else automail = 0
answer = ''
print, ' '
read, 'Mail this ASCII file to yourself? (y or n, default is n) ', answer
if (answer ne 'y') and (answer ne 'Y') then goto,getout
;
get_addr:
if (size(mailaddr))(1) eq 0 then prompt=1 else prompt=0

case !version.os of
  'vms': begin
       	fix_mailaddr, mailaddr=mailaddr, prompt=prompt, fixedaddr=fixedaddr,$
          automail=automail 
        spawn, 'mail ' + filename + ' ' + fixedaddr, result
	end
  'OSF':begin
	if  prompt then begin
		print,' '                   
		addr = ' '
		read,'Please enter your e-mail address: ',addr
		mailaddr = addr
		endif 
        spawn,'mail ' + mailaddr + ' <' + filename, result
	end
  else : begin
	print,'Mailing not enabled for this operating system'
	result='File not mailed'
        end
endcase


print, result
print, ' '
;if result(0) eq '' then print, 'Mailed file ', filename, ' to ', fixedaddr
if result(0) eq '' then print, 'Mailed file ', filename, ' to ', mailaddr
getout:
return&end
