From: 00mjstum@bsu-ucs.uucp (Matthew J. Stum)
Newsgroups: comp.os.vms
Subject: Re: VAX Pascal and callable mail
Date: 14 Sep 92 17:03:52 GMT

> I've been playing -- rather naively -- with Joe Meadows' callable
> mail materials, but with singular lack of success. I don't know C,
> the language his examples are in, and Pascal fails to perform.
> 
> In fact it won't even compile, sticking at the first mention of a
> MAIL$xxx routine, calling it an undeclared identifier. This is
> despite ``inheriting'' STARLET, which contains the definitions of
> all the MAIL$_xxx codes, but not the MAIL$xxx routines. I've gone
> hunting for definitions of the routines in most of the files in
> SYS$LIBRARY, and there don't seem to be any, not even in MAILDEF.H. 
> 
> Can someone give me a hint, please???

The following program (below my sig) is rather specific to a local
application (it extracts SCA Digest messages from NEWMAIL into appropriately
named files), but hopefully you can see how to call the MAIL$ routines
from VAX Pascal.  (I have some nicer, general-purpose VAX Pascal MAIL
routines, but I wrote them before the official documentation came out
so some of the data-structures are seriously gross, but work.)

-- 
Matt Stum                    Gwydion ap Myrddin       Ball State University
00mjstum@leo.bsuvc.bsu.edu   Shire of Afonlyn, MK     Muncie, IN  USA

---------------- CUT HERE ---------------------
[inherit('sys$library:starlet')]
program secretary(input,output);

const
  MAIL$_NOMOREREC = 8314792; {can't find this anywhere}

type
  uword = [word] 0..65535;
  u255word = [byte] 0..255;
  itmrec_mail = record
                  buf_len : uword;
                  item_code : uword;
                  buf_adr : unsigned;
                  ret_len_adr : unsigned;
                end;
  itmlst_mail = array [1..10] of itmrec_mail;
  v255string = varying [255] of char;

var

  stat : unsigned;
  in_itmlst,out_itmlst,null : itmlst_mail;
  mfc,mc,uc : unsigned;
  line : array [1..6] of record
                           line : v255string;
                           a,b:uword;
                         end;
  junk : unsigned;
  i,j : integer;

  new_messages : uword;
  messages : integer;
  filename : v255string;
  outfile : text;

[external] function mail$mailfile_begin(var context:unsigned;
                    var in_item_list:itmlst_mail;
                    var out_item_list:itmlst_mail):unsigned; extern;
[external] function mail$mailfile_open(var context:unsigned;
                    var in_item_list:itmlst_mail;
                    var out_item_list:itmlst_mail):unsigned; extern;
[external] function mail$mailfile_close(var context:unsigned;
                    var in_item_list:itmlst_mail;
                    var out_item_list:itmlst_mail):unsigned; extern;
[external] function mail$mailfile_end(var context:unsigned;
                    var in_item_list:itmlst_mail;
                    var out_item_list:itmlst_mail):unsigned; extern;


[external] function mail$message_begin(var context:unsigned;
                    var in_item_list:itmlst_mail;
                    var out_item_list:itmlst_mail):unsigned; extern;
[external] function mail$message_delete(var context:unsigned;
                    var in_item_list:itmlst_mail;
                    var out_item_list:itmlst_mail):unsigned; extern;
[external] function mail$message_get(var context:unsigned;
                    var in_item_list:itmlst_mail;
                    var out_item_list:itmlst_mail):unsigned; extern;
[external] function mail$message_select(var context:unsigned;
                    var in_item_list:itmlst_mail;
                    var out_item_list:itmlst_mail):unsigned; extern;
[external] function mail$message_copy(var context:unsigned;
                    var in_item_list:itmlst_mail;
                    var out_item_list:itmlst_mail):unsigned; extern;
[external] function mail$message_end(var context:unsigned;
                    var in_item_list:itmlst_mail;
                    var out_item_list:itmlst_mail):unsigned; extern;

[external] function mail$user_begin(var context:unsigned;
                    var in_item_list:itmlst_mail;
                    var out_item_list:itmlst_mail):unsigned; extern;
[external] function mail$user_set_info(var context:unsigned;
                    var in_item_list:itmlst_mail;
                    var out_item_list:itmlst_mail):unsigned; extern;
[external] function mail$user_end(var context:unsigned;
                    var in_item_list:itmlst_mail;
                    var out_item_list:itmlst_mail):unsigned; extern;

begin

  null[1] := zero;
  mfc := 0; {MESSAGE FILE CONTEXT}
  mc := 0;  {MESSAGE CONTEXT}
  uc := 0;  {USER CONTEXT}
  stat := mail$mailfile_begin(mfc,null,null);
  stat := mail$mailfile_open(mfc,null,null);
  in_itmlst[1].buf_len := 4;
  in_itmlst[1].item_code := MAIL$_MESSAGE_FILE_CTX;
  in_itmlst[1].buf_adr := iaddress(mfc);
  in_itmlst[1].ret_len_adr := 0;
  in_itmlst[2] := zero;
  stat := mail$message_begin(mc,in_itmlst,null);

  line[1].line := 'NEWMAIL';
  in_itmlst[1].buf_len := line[1].line.length;
  in_itmlst[1].item_code := MAIL$_MESSAGE_FOLDER;
  in_itmlst[1].buf_adr := iaddress(line[1].line.body);
  in_itmlst[1].ret_len_adr := 0;

  line[2].line := 'IN%"SCA@mc.lcs.mit.edu"';
  in_itmlst[2].buf_len := line[2].line.length;
  in_itmlst[2].item_code := MAIL$_MESSAGE_FROM_SUBSTRING;
  in_itmlst[2].buf_adr := iaddress(line[2].line.body);
  in_itmlst[2].ret_len_adr := 0;

  line[3].line := 'IN%"SCA@mc.lcs.mit.edu"';
  in_itmlst[3].buf_len := line[3].line.length;
  in_itmlst[3].item_code := MAIL$_MESSAGE_TO_SUBSTRING;
  in_itmlst[3].buf_adr := iaddress(line[3].line.body);
  in_itmlst[3].ret_len_adr := 0;

  line[4].line := 'SCA Digest V';
  in_itmlst[4].buf_len := line[4].line.length;
  in_itmlst[4].item_code := MAIL$_MESSAGE_SUBJ_SUBSTRING;
  in_itmlst[4].buf_adr := iaddress(line[4].line.body);
  in_itmlst[4].ret_len_adr := 0;

  in_itmlst[5] := zero;

  out_itmlst[1].buf_len := 4;
  out_itmlst[1].item_code := MAIL$_MESSAGE_SELECTED;
  out_itmlst[1].buf_adr := iaddress(messages);
  out_itmlst[1].ret_len_adr := iaddress(junk);

  out_itmlst[2] := zero;

  stat := mail$message_select(mc,in_itmlst,out_itmlst);

writeln('Processing ',messages:1,' messages...');

  for i := 1 to messages do
    begin
      in_itmlst[1].buf_len := 0;
      in_itmlst[1].item_code := MAIL$_MESSAGE_NEXT;
      in_itmlst[1].buf_adr := 0;
      in_itmlst[1].ret_len_adr := 0;

      in_itmlst[2] := zero;

      out_itmlst[1].buf_len := 255;
      out_itmlst[1].item_code := MAIL$_MESSAGE_DATE;
      out_itmlst[1].buf_adr := iaddress(line[1].line.body);
      out_itmlst[1].ret_len_adr := iaddress(line[1].a);

      out_itmlst[2].buf_len := 255;
      out_itmlst[2].item_code := MAIL$_MESSAGE_SUBJECT;
      out_itmlst[2].buf_adr := iaddress(line[2].line.body);
      out_itmlst[2].ret_len_adr := iaddress(line[2].a);

      out_itmlst[3] := zero;

      stat := mail$message_get(mc,in_itmlst,out_itmlst);
      line[1].line.length := line[1].a;
      line[2].line.length := line[2].a;

      filename := 'RIALTO$ARCHIVE:DIGEST_V';
      {line[2].line should be "SCA Digest Vn #nnn"}
      line[2].line:=substr(line[2].line,13,line[2].line.length-12);
      j := index(line[2].line,' ');
      if j=2 then filename:=filename+'0';
      filename := filename+substr(line[2].line,1,j-1)+'_';
      j := index(line[2].line,'#');
      line[2].line := substr(line[2].line,j+1,line[2].line.length-j);
      if line[2].line.length=1 then filename:=filename+'000';
      if line[2].line.length=2 then filename:=filename+'00';
      if line[2].line.length=3 then filename:=filename+'0';
      filename := filename+line[2].line+'.TXT';

      open(file_name := filename,
           file_variable := outfile,
           history := new);
      rewrite(outfile);

      writeln(outfile,'Date:   ',line[1].line);

      in_itmlst[1].buf_len := 0;
      in_itmlst[1].item_code := MAIL$_MESSAGE_CONTINUE;
      in_itmlst[1].buf_adr := 0;
      in_itmlst[1].ret_len_adr := 0;

      in_itmlst[2].buf_len := 0;
      in_itmlst[2].item_code := MAIL$_MESSAGE_AUTO_NEWMAIL;
      in_itmlst[2].buf_adr := 0;
      in_itmlst[2].ret_len_adr := 0;

      in_itmlst[3] :=  zero;

      out_itmlst[1].buf_len := 255;
      out_itmlst[1].item_code := MAIL$_MESSAGE_RECORD;
      out_itmlst[1].buf_adr := iaddress(line[1].line.body);
      out_itmlst[1].ret_len_adr := iaddress(line[1].a);

      out_itmlst[2] := zero;

      repeat
          stat := MAIL$MESSAGE_GET(mc,in_itmlst,out_itmlst);
          if stat<>MAIL$_NOMOREREC then
            begin
              line[1].line.length := line[1].a;
              writeln(outfile,line[1].line);
            end;
      until stat=MAIL$_NOMOREREC;
      close(outfile);

      out_itmlst[1].buf_len := 2;
      out_itmlst[1].item_code := MAIL$_USER_NEW_MESSAGES;
      out_itmlst[1].buf_adr := iaddress(new_messages);
      out_itmlst[1].ret_len_adr := iaddress(junk);

      out_itmlst[2] := zero;

      stat := mail$user_begin(uc,null,out_itmlst);
      new_messages := new_messages - 1;

      in_itmlst[1].buf_len := 2;
      in_itmlst[1].item_code := MAIL$_USER_SET_NEW_MESSAGES;
      in_itmlst[1].buf_adr := iaddress(new_messages);
      in_itmlst[1].ret_len_adr := 0;

      in_itmlst[2] :=  zero;

      stat := mail$user_set_info(uc,in_itmlst,null);
      stat := mail$user_end(uc,null,null);
    end;

  stat := mail$message_end(mc,null,null);
  stat := mail$mailfile_end(mfc,null,null);

end.
Newsgroups: comp.os.vms