From:	CRDGW2::CRDGW2::MRGATE::"SMTP::CRVAX.SRI.COM::RELAY-INFO-VAX" 23-JUN-1989 21:08
To:	MRGATE::"ARISIA::EVERHART"
Subj:	automatic mail answering service

Received: From KL.SRI.COM by CRVAX.SRI.COM with TCP; Fri, 23 JUN 89 10:45:46 PDT
Received: from ucbvax.Berkeley.EDU by KL.SRI.COM with TCP; Fri, 23 Jun 89 10:23:44 PDT
Received: by ucbvax.Berkeley.EDU (5.61/1.37)
	id AA12397; Fri, 23 Jun 89 10:17:00 -0700
Received: from USENET by ucbvax.Berkeley.EDU with netnews
	for info-vax@kl.sri.com (info-vax@kl.sri.com)
	(contact usenet@ucbvax.Berkeley.EDU if you have questions)
Date: 23 Jun 89 16:39:48 GMT
From: amelia!howells@ames.arc.nasa.gov  (Mr. Neutron)
Organization: Aeroflightdynamics Directorate
Subject: automatic mail answering service
Message-Id: <2373@amelia.nas.nasa.gov>
Sender: info-vax-request@kl.sri.com
To: info-vax@kl.sri.com

Just for kicks, I used a recent example of callable mail (posted here a while
back) as a basis for writing an automatic mail answering utility for when you
go on vacation and don't want to have your senders think you're ignoring them.
The program is called VACATION and requires a DCL command proc to be submitted
as a batch job. Also required is a short text file called VACATION.TXT. This is
all documented in the program header. Hope it's useful...

--------------------------------< cut here >--------------------------------

        Program VACATION
C
C Automatically reply to mail when you are on vacation. Uses the file
C VACATION.TXT. Create a file with this name and fill it with the 
C appropriate text. Use the command file VACATION.COM to run this program
C and resubmit it as a batch job on a daily basis. The log file ANSWER.LOG
C will be created and will include the time of message, sender, and subject.
C
C The VACATION.TXT file could look like this:
C
C----------------------------------------------------------------------------
C Hello. I am on vacation at the moment and so I am unable to get back to
C you. I've left my automatic mail reply system running to let you know
C that I have received your message and will respond as soon as I return.
C
C				John
C----------------------------------------------------------------------------
C
C The VACATION.COM file should look something like this:
C
C----------------------------------------------------------------------------
C $ SUBMIT/AFTER="TOMORROW" VACATION
C $ RUN VACATION
C $ EXIT
C----------------------------------------------------------------------------
C
C Author: 
C
C John Howells, Sterling Software
C
C Adapted from the TMAIL program example posted to INFO-VAX
C
        include '($maildef)'
        character*80 buff, sender, subject
        character*25 ascdate
        integer mail_ctx, msg_ctx, user_ctx, msg_id, sts
        integer msg_select, date_len, status
	integer sender_len, subject_len
        integer*2 msg_number, msg_flag

        volatile msg_select, msg_number, msg_flag, msg_id
	volatile date_len, sender_len, subject_len, len_buff

	parameter logfile = 1

        structure /itemlist/
           integer*2 len
           integer*2 item_code
           integer*4 address
           integer*4 retlen
        end structure

        record /itemlist/ nselect(2), text(2), msgfile(2)
        record /itemlist/ newmsg(2), snewmsg(2)
        record /itemlist/ msg_info(6), select(3), next(2), 
     .   context(3)
        record /itemlist/ null
C
C Blank out the following character strings so that they will format
C properly later
C
	   subject = ' '
	   sender = ' '
	   ascdate = ' '
C
C Set up itemlists for input items
C
C MAIL$_USER_NEW_MESSAGES returns the new message count
C MAIL$_USER_SET_NEW_MESSAGES sets the new message count
C MAIL$_MESSAGE_NEXT returns 1st record of message following current one
C
        call setup ( newmsg, mail$_user_new_messages, 
     .   %descr(msg_number), )
        call setup ( snewmsg, mail$_user_set_new_messages, 
     .   %descr(msg_number), )
        call setup ( next, mail$_message_next, ' ', )
C
C Set up itemlists for characteristics of the mail message
C
C MAIL$_MESSAGE_FOLDER specifies name of target folder
C MAIL$_NOSIGNAL disables error signalling
C 
	call setup ( select(1), mail$_message_folder, 'NEWMAIL', )
        call setup ( select(2), mail$_nosignal, ' ', )
C
C Set up itemlists for message context
C
C MAIL$_MESSAGE_CONTINUE returns the next text record of current message
C MAIL$_MESSAGE_AUTO_NEWMAIL automatically moves new messages to MAIL folder
C
        call setup ( context(1), mail$_message_continue, ' ', )
        call setup ( context(2), mail$_message_auto_newmail, ' ', )
C
C Set up itemlists for output items (only needed to clear out the message 
C context)
C
C MAIL$_MESSAGE_SELECTED returns the number of selected messages
C MAIL$_MESSAGE_RECORD returns a record from the current message
C
	call setup ( nselect,
     .   mail$_message_selected, %descr(msg_select), )
        call setup ( text, mail$_message_record, buff, 
     .   len_buff )
C
C Set up itemlists for information items
C
C MAIL$_MESSAGE_CURRENT_ID returns id number of the current message
C MAIL$_MESSAGE_DATE returns the message creation date string
C MAIL$_MESSAGE_SENDER returns address of the sender of the message
C MAIL$_MESSAGE_SUBJECT returns the subject text field
C MAIL$_MESSAGE_RETURN_FLAGS returns flag value of the current message
C
        call setup ( msg_info(1), mail$_message_current_id,
     .   %descr(msg_id), )
        call setup ( msg_info(2), mail$_message_date,
     .   ascdate, date_len )
        call setup ( msg_info(3), mail$_message_sender, 
     .   %descr(sender), sender_len )
        call setup ( msg_info(4), mail$_message_subject, 
     .   %descr(subject), subject_len )
        call setup ( msg_info(5), mail$_message_return_flags,
     .   %descr(msg_flag), )
C
C Get number of new messages
C
C MAIL$USER_BEGIN initiates user processing
C MAIL$USER_GET_INFO gets information from user profile
C
        call mail$user_begin ( user_ctx, null, null )
        call mail$user_get_info ( user_ctx, null, newmsg )
C
C Open the mailfile
C
C MAIL$MAILFILE_BEGIN initiates mail file processing
C MAIL$MAILFILE_OPEN opens the mail file
C
        call mail$mailfile_begin ( mail_ctx, null, null )
        call mail$mailfile_open ( mail_ctx, null, null )
C
C Select the context to read messages
C
C MAIL$_MESSAGE_FILE_CTX specifies mail file context from MAIL$MAILFILE_BEGIN
C MAIL$MESSAGE_BEGIN initiates message processing
C
        call setup ( msgfile, mail$_message_file_ctx,
     .   %descr(mail_ctx), )
        call mail$message_begin ( msg_ctx, msgfile, null )
C
C select the messages that we want to read, and find out how many we got
C
C MAIL$MESSAGE_SELECT selects a message from open mail file
C
        sts = mail$message_select ( msg_ctx, select, nselect )
        if(.not.sts) goto 100  ! NEWMAIL folder doesn't exist
C
C Open the logfile. If it does not exist, create a new one.
C
	open (unit=logfile, file='ANSWER.LOG', status='old',
     .   form='formatted', carriagecontrol='list', access='append',
     .   iostat=status)
C
C Logfile doesn't exist, create a new one
C
	if (status .ne. 0) then
	   open (unit=logfile, file='ANSWER.LOG', status='new',
     .      form='formatted', carriagecontrol='list', iostat=status)
	   if (status .ne. 0) then
	      write (6,*) 'unable to open log file'
	      call exit
	   endif
	   write (logfile, '(t1,a,t20,a,t50,a)') 
     .      'Date:','From:','Subject:'
  	   write (logfile,'(a)') '------------------------------'//
     .      '--------------------------------------------------'
	endif
C
C Loop through and reply to all messages in NEWMAIL folder
C
C MAIL$MESSAGE_GET retrieves a message
C
        do messcnt = 1,msg_select
           call mail$message_get ( msg_ctx, next, msg_info(1) )
C
C Write info to the logfile
C
	   write (logfile, '(t1,a,t20,a,t50,a)') ascdate(1:12), 
     .      sender(1:25), subject(1:30)
C
C Actually send the file VACATION.TXT to the sender (using the send_mail
C subroutine)
C
	   call send_mail ( 'Re: '//subject(1:subject_len), 
     .      sender(1:sender_len) )
C
C We have to keep track of the number of new messages ourself.
C
           if (iand(msg_flag,mail$m_newmsg).ne.0) 
     .      msg_number = msg_number - 1
           call mail$message_get ( msg_ctx, context, text )
C
C Clear out the character strings so that the logfile will be nicely
C formatted
C
	   subject = ' '
	   sender = ' '
	   ascdate = ' '
        end do
C
C All done, do clean up
C
C MAIL$MESSAGE_END terminates message processing
C MAIL$USER_SET_INFO modifies the user profile entry
C MAIL$USER_END terminates user processing
C MAIL$MAILFILE_CLOSE closes the mail file
C MAIL$MAILFILE_END terminates mail file processing
C
100     call mail$message_end ( msg_ctx, null, null )
        call mail$user_set_info ( user_ctx, snewmsg, null )
        call mail$user_end ( user_ctx, null, null )
        call mail$mailfile_close ( mail_ctx, null, null )
        call mail$mailfile_end ( mail_ctx, null, null )
C
C Close the logfile
C
	close (logfile)

        end

C************************************************************************

        Subroutine SEND_MAIL ( subject, sender )
C
C Send a reply to the sender explaining that I'm not here
C
        include '($maildef)'
        character*(*) subject, sender

        structure /itemlist/
           integer*2 len
           integer*2 item_code
           integer*4 address
           integer*4 retlen
        end structure

        record /itemlist/ msg_info(2), null, body(2), address(2)
C
C Start by setting up the itemlists.
C
C MAIL$_SEND_USERNAME specifies the user to send to
C MAIL$_SEND_SUBJECT specifies the subject line
C MAIL$_SEND_FILENAME specifies the input file to be opened
C
        call setup ( address, mail$_send_username, sender, )
        call setup ( msg_info, mail$_send_subject, subject, )
        call setup ( body, mail$_send_filename, 'VACATION.TXT', )
C
C Send the file to the originator of the message
C
C MAIL$SEND_BEGIN initiates send processing
C MAIL$SEND_ADD_ATTRIBUTE constructs the message header
C MAIL$SEND_ADD_BODYPART constructs the body of the message
C MAIL$SEND_ADD_ADDRESS adds the address of the originator
C MAIL$SEND_MESSAGE sends the actual message
C MAIL$SEND_END terminates send processing
C
        call mail$send_begin ( send_ctx, null, null )
        call mail$send_add_attribute ( send_ctx, msg_info, null )
        call mail$send_add_bodypart ( send_ctx, body, null )
        call mail$send_add_address ( send_ctx, address, null )
        call mail$send_message ( send_ctx, null, null )
        call mail$send_end ( send_ctx, null, null )

	return

        end

C************************************************************************

        Subroutine SETUP ( item, code, string, ret_len )
C
C This subroutine is called in order to set up the itemlists needed by
C the main program
C
        character*(*) string
        integer ret_len
        integer code

        structure /itemlist/
           integer*2 len
           integer*2 item_code
           integer*4 address
           integer*4 retlen
        end structure

        record /itemlist/ item

        item.len = len(string)
        item.item_code = code
        item.address = %loc(string)
        item.retlen = %loc(ret_len)

        return

        end

-----------------------------< cut here >-----------------------------------

--------------------------------------------------------------------------------
John Howells           |  "Science does not     | howells@pioneer.arc.nasa.gov
Sterling Software      |   remove the terror    | howells@krypton.arc.nasa.gov
Palo Alto, Ca.         |   of the Gods"         | howells%kry@ames-io.arpa

