FUNCTION LONG Send_Mail (STRING To_name, STRING Carbon_copy, STRING Subject, STRING Message, STRING Message_type) OPTION TYPE = EXPLICIT, SIZE = INTEGER LONG ! ! This function can send either a file or a line of text to a user ! (or a list of users) via DEC's MAIL utility. It uses functions which ! shipped with V5.0 but are neither documented nor supported as of the ! time this is written. This routine is a somewhat simplified translation ! of a FORTRAN subroutine I received from Jim Geier of General Instrument ! (DECUServe to the rescue yet again). ! ! To_name can be 1 username or a username list with no embedded spaces, ! separated by commas. Carbon_copy can be null, or 1 username, or a list ! like To_name. These two lists are concatenated during processing, and ! the total length of the two (including commas) cannot exceed 80 characters. ! Note that distribution lists are currently not supported by this ! function. ! ! Subject is limited to 80 characters in length ! ! Message is also limited to 80 characters in length. If you want to ! send a single line of text longer than that, you'll just have to write ! it to a file and send IT. ! ! If one of the function calls within this code results in anything but ! SS$_NORMAL, we abort the sending and return the return_status value to ! the calling routine. If all goes well, we return SS$_NORMAL as the ! function value. ! ! February, 1989 Alan Bruns ! %include "$maildef" %from %library "sys$library:basic$starlet" %include "$jpidef" %from %library "sys$library:basic$starlet" EXTERNAL LONG FUNCTION MAIL$Send_Add_Address, & MAIL$Send_Add_Attribute, & MAIL$Send_Add_Bodypart, & MAIL$Send_Begin, & MAIL$Send_End, & MAIL$Send_Message, & SYS$GETJPIW EXTERNAL LONG CONSTANT SS$_NORMAL DECLARE LONG CONSTANT True = -1, & False = 0 DECLARE LONG context, & return_status, & starting_point, & comma_position, & more RECORD item_list_3 WORD buffer_length WORD item_code LONG buffer_address LONG return_length_address END RECORD DECLARE item_list_3 input_block(4), & output_block, & null_block, & jpi_block(1) RECORD data_storage STRING text = 80 LONG length END RECORD data_storage DECLARE data_storage to_line, & from_line, & cc_line, & subject_line, & file_name, & message_line, & address RECORD io_status_block ! for the JPI call... LONG io_status END RECORD io_status_block DECLARE io_status_block iosb to_line::text = EDIT$(to_name,6) ! Take a look at the params to_line::length = LEN(EDIT$(to_name,6)) ! What's the length? cc_line::text = EDIT$(Carbon_copy,6) cc_line::length = LEN(EDIT$(Carbon_copy,6)) subject_line::text = EDIT$(Subject,130) subject_line::length = LEN(EDIT$(Subject,130)) ! Identify the sender using $GETJPI jpi_block(0)::buffer_length = 12 jpi_block(0)::item_code = JPI$_Username jpi_block(0)::buffer_address = LOC(from_line::text) jpi_block(0)::return_length_address = LOC(from_line::length) jpi_block(1) = null_block return_status = sys$getjpiw(,,,jpi_block() BY REF,iosb,,) return_status = iosb::io_status IF return_status GOTO error_trap IF (return_status <> SS$_NORMAL) from_line::length = LEN(EDIT$(from_line::text,6)) null_block::item_code = 0 null_block::buffer_length = 0 null_block::buffer_address = 0 null_block::return_length_address = 0 ! Set up the send context return_status = MAIL$SEND_BEGIN(context, null_block, null_block) GOTO error_trap IF (return_status <> SS$_NORMAL) ! Set the message header info into place input_block(0)::buffer_length = to_line::length input_block(0)::item_code = MAIL$_SEND_TO_LINE input_block(0)::buffer_address = LOC(to_line::text) input_block(0)::return_length_address = 0 input_block(1)::buffer_length = cc_line::length input_block(1)::item_code = MAIL$_SEND_CC_LINE input_block(1)::buffer_address = LOC(cc_line::text) input_block(1)::return_length_address = 0 input_block(2)::buffer_length = from_line::length input_block(2)::item_code = MAIL$_SEND_FROM_LINE input_block(2)::buffer_address = LOC(from_line::text) input_block(2)::return_length_address = 0 input_block(3)::buffer_length = subject_line::length input_block(3)::item_code = MAIL$_SEND_SUBJECT input_block(3)::buffer_address = LOC(subject_line::text) input_block(3)::return_length_address = 0 input_block(4) = null_block ! item list end marker output_block = null_block return_status = MAIL$SEND_ADD_ATTRIBUTE(context, input_block() BY REF, output_block BY REF) GOTO error_trap IF (return_status <> SS$_NORMAL) ! Send in either the filespec or the one-line message SELECT EDIT$(Message_type,32) CASE "FILE" file_name::text = EDIT$(Message,6) file_name::length = LEN(EDIT$(Message,6)) input_block(0)::buffer_length = file_name::length input_block(0)::item_code = MAIL$_SEND_FILENAME input_block(0)::buffer_address = LOC(file_name::text) input_block(0)::return_length_address = 0 input_block(1) = null_block CASE "TEXT" message_line::text = EDIT$(Message,6) message_line::length = LEN(EDIT$(Message,6)) input_block(0)::buffer_length = message_line::length input_block(0)::item_code = MAIL$_SEND_RECORD input_block(0)::buffer_address = LOC(message_line::text) input_block(0)::return_length_address = 0 input_block(1) = null_block END SELECT return_status = MAIL$SEND_ADD_BODYPART(context, input_block() BY REF, output_block BY REF) GOTO error_trap IF (return_status <> SS$_NORMAL) ! Put in the addresses to whom we'll send the message to_line::text = SEG$(to_line::text,1,to_line::length) + "," + & SEG$(cc_line::text,1,cc_line::length) & IF cc_line::length <> 0 to_line::length = LEN(EDIT$(to_line::text,6)) ! If we're supposed to send CC, append that line to the to: line starting_point = 1 comma_position = POS(to_line::text,",",starting_point) IF comma_position = 0 THEN ! Sending to input_block(0)::buffer_length = to_line::length ! just 1 user input_block(0)::item_code = MAIL$_SEND_USERNAME input_block(0)::buffer_address = LOC(to_line::text) input_block(0)::return_length_address = 0 input_block(1) = null_block return_status = MAIL$SEND_ADD_ADDRESS(context, input_block() BY REF, output_block BY REF) GOTO error_trap IF (return_status <> SS$_NORMAL) ELSE more = True address::text = SEG$(to_line::text,starting_point,comma_position-1) Sending_to_a_list: address::length = LEN(EDIT$(address::text,6)) input_block(0)::buffer_length = address::length input_block(0)::item_code = MAIL$_SEND_USERNAME input_block(0)::buffer_address = LOC(address::text) input_block(0)::return_length_address = 0 input_block(1) = null_block return_status = MAIL$SEND_ADD_ADDRESS(context, input_block() BY REF, output_block BY REF) GOTO error_trap IF (return_status <> SS$_NORMAL) GOTO No_more IF NOT more starting_point = comma_position+1 comma_position = POS(to_line::text,",",starting_point) more = (comma_position > 0) SELECT more CASE True address::text = SEG$(to_line::text,starting_point,comma_position-1) CASE False address::text = SEG$(to_line::text,starting_point,to_line::length) END SELECT GOTO Sending_to_a_list No_more: END IF ! Send the message return_status = MAIL$SEND_MESSAGE(context, null_block, null_block) GOTO error_trap IF (return_status <> SS$_NORMAL) ! And close out the context return_status = MAIL$SEND_END(context, null_block, null_block) GOTO error_trap IF (return_status <> SS$_NORMAL) Send_Mail = SS$_NORMAL GOTO Finish error_trap: Send_Mail = return_status Finish: END FUNCTION