From: brydon@asl.slb.com (Harvey Brydon (918)250-4312)
Newsgroups: comp.os.vms
Subject: Re: MAIL$INIT Logical name doesn't work.
Date: 27 Sep 92 21:09:33 GMT
Reply-To: brydon@dsn.SINet.slb.com
Organization: Schlumberger/Anadrill Sugar Land, TX

In article <1992Sep23.115440.396@dct.ac.uk>, eesb2mm@dct.ac.uk writes:
>
> I have been trying to define the logical MAIL$INIT to point to an 
>initialisation file for the MAIL program. The original idea was to 
>have SET TRANSPORT commands in the file, and have muliple
>files, to help make mailing easier e.g to mail out on the Internet 
>I wrote a file called imail.com of the following format.

It is not clear if you want to do this just for yourself or for a number of
people on your system.  The SET TRANSPORT command only needs to be executed
once.  It is a "set and forget" item, just like mail subdirectory and personal
name.  You don't need to specify it every time you enter mail.  Therefore
there is no need to put this in an initialization file unless you are trying
to get others on your system to SET TRANSPORT as of the next time they
activate mail.

>$ define/nolog MAIL$INIT EES:[B2.MM.MBOX]INTERNET.INI
>$ define /user sys$command sys$input
>$ mail
>$ exit
>
>and INTERNET.INI contains :
>
>set transport cbs%uk.ac.nsfnet-relay::
>define /key/terminate kp1 "SEND/NOTRANSPORT"
>
>MAIL, however, rejects ANY commands in the file pointed to by MAIL$INIT

MAIL$INIT unfortunately can not contain anything but DEFINE/KEY commands.
Since the SET TRANSPORT comes first in your file, the initilization sequence
is probably bombing out and not seeing the DEFINE/KEY command that follows on
line 2...

>Has anyone heard of this before?

Yup.

If you want to effectively SET TRANSPORT for another user on your system, try
running the C program below.  If you want to affect another user on the
system, SYSPRV is required.

_______________________________________________________________
Harvey Brydon         | Internet:   brydon@dsn.SINet.slb.com
Dowell Schlumberger   | P.O.T.S.:   (918)250-4312
       C code.  C code run.  Run, code, run.

----- SET_TRANS.C --------
#include <stdio>
#include <ssdef>
#include <maildef>

/*
++
 This program sets the default mail transport for a user or multiple users. 
 Parameter 1 is the transport to be defined for the username(s) specified. 
 Parameter 2 is the username(s) to be affected.  If parameter 1 is null or not
 specified, a default of 'HM%' is used.  If parameter 2 is not specified, the
 invoking username is affected.  A value of '*' for parameter 2 is a request to
 set the transport for all users in the SYSUAF.  If the program  is run with no
 parameters, it only alters the default transport for the current username. 
 SYSPRV or SYSNAM is required to modify the field of a user other than that of
 the invoker.
--
*/

typedef struct itmlst
{ short  buffer_length;
  short  item_code;
  void  *buffer_address;
  long  *return_length_address;
} ITMLST;

ITMLST nulllist[] = {{0,0,0,0}};

int
  ucontext = 0,
  stat,
  otlen,
  null = 0;

char deftrans[] = "HM%";
char ntrans[65];
char otrans[65];

set_transport_for_myself()  /* USER_CALLS 1506 */
{ ITMLST
    in_il[] = 
      {
     /*{0,              MAIL$_NOSIGNAL,           null,   0},*/
       {0,              MAIL$_USER_CREATE_IF,     null,   0},
       {strlen(ntrans), MAIL$_USER_SET_TRANSPORT, ntrans, 0},
       {0,0,0,0}};

  if(stat = MAIL$USER_BEGIN(&ucontext, nulllist, nulllist) != SS$_NORMAL)
    exit(stat);

  if(stat = MAIL$USER_SET_INFO(&ucontext, in_il, nulllist) != SS$_NORMAL)
    exit(stat);

  return MAIL$USER_END(&ucontext, nulllist, nulllist);
}


set_transport_on_one(char *user)  /* USER_CALLS 1832 */
{ int ulen;

  ITMLST
    iget_il[] =
      {{0,            MAIL$_NOSIGNAL,      null, 0},
       {strlen(user), MAIL$_USER_USERNAME, user, 0},
       {0,0,0,0}},
    oret_il[] =
      {{sizeof(otrans)-1, MAIL$_USER_TRANSPORT, otrans, &otlen},
       {0,0,0,0}},
    set_il[] =
      {
     /*{0,              MAIL$_NOSIGNAL,           null, 0},*/
       {strlen(user),   MAIL$_USER_USERNAME,      user, 0},
       {0,              MAIL$_USER_CREATE_IF,     null, 0},
       {strlen(ntrans), MAIL$_USER_SET_TRANSPORT, ntrans, 0},
       {0,0,0,0}};

  if((stat = MAIL$USER_BEGIN(&ucontext, nulllist, nulllist)) != SS$_NORMAL)
    exit(stat);

  if((stat = MAIL$USER_GET_INFO(&ucontext, iget_il, oret_il)) != SS$_NORMAL)
    exit(stat);

  otrans[otlen]  = '\0';
  printf("Setting transport for %s to %s (was set to \"%s\")\n",
          user, ntrans, otrans);

  MAIL$USER_SET_INFO(&ucontext, set_il, nulllist);

  return MAIL$USER_END(&ucontext, nulllist, nulllist);
}



set_transport_on_everyone()
{ char user[33];
  int ulen;

  ITMLST
    ifirst_il[] =
      {{0, MAIL$_NOSIGNAL,   null, 0},
       {0, MAIL$_USER_FIRST, null, 0},
       {0,0,0,0}},
    inext_il[] =
      {{0, MAIL$_NOSIGNAL,  null, 0},
       {0, MAIL$_USER_NEXT, null, 0},
       {0,0,0,0}},
    set_il[] =
      {{0,              MAIL$_USER_USERNAME,      user,   0},
       {0,              MAIL$_USER_CREATE_IF,     null,   0},
       {strlen(ntrans), MAIL$_USER_SET_TRANSPORT, ntrans, 0},
       {0,0,0,0}},
    oret_il[] =
      {{sizeof(user)-1,   MAIL$_USER_RETURN_USERNAME, user,   &ulen},
       {sizeof(otrans)-1, MAIL$_USER_TRANSPORT,       otrans, &otlen},
       {0,0,0,0}};

  if(stat = MAIL$USER_BEGIN(&ucontext, nulllist, nulllist) != SS$_NORMAL)
    exit(stat);

  if((stat = MAIL$USER_GET_INFO(&ucontext, ifirst_il, oret_il)) != SS$_NORMAL)
    exit(stat);

  while (stat & 1)
  { user[ulen] = '\0';
    otrans[otlen] = '\0';
    printf("Setting transport for %s to %s (was set to \"%s\")\n",
            user, ntrans, otrans);
    set_il[0].buffer_length = ulen;
    if(stat = MAIL$USER_SET_INFO(&ucontext, set_il, nulllist) != SS$_NORMAL)
      exit(stat);
    stat = MAIL$USER_GET_INFO(&ucontext, inext_il, oret_il);
  }
  return MAIL$USER_END(&ucontext, nulllist, nulllist);
}



void uppercase(char *str)
{ while(*str != '\0')
  { *str = toupper(*str);
    str++;
  }
}



main (int argc, char *argv[])
{ char uname[256];
  int stat;

  if (argc < 2) strcpy(ntrans, deftrans);
  else strcpy(ntrans, argv[1]);
  if (ntrans[0] == '\0') strcpy(ntrans, deftrans);
  uppercase(ntrans);

  if (argc < 3) stat = set_transport_for_myself();
  else
  { strcpy(uname, argv[2]);
    uppercase(uname);
    if(strcmp(uname,"*") == 0) stat = set_transport_on_everyone();
    else stat = set_transport_on_one(uname);
  }
  exit (stat);
}