From:	CSBVAX::CSBVAX::MRGATE::"SMTP::CRVAX.SRI.COM::RELAY-INFO-VAX" 21-JAN-1989 09:14
To:	MRGATE::"ARISIA::EVERHART"
Subj:	Listing all mail users


Received: From KL.SRI.COM by CRVAX.SRI.COM with TCP; Wed,  4 JAN 89 21:56:44 PDT
Received: from uwavm.acs.washington.edu (oly.acs.washington.edu) by KL.SRI.COM with TCP; Wed, 4 Jan 89 21:25:02 PST
Received: from UWAVM.ACS.WASHINGTON.EDU by uwavm.acs.washington.edu ; Wed, 04 Jan 89 13:28:26 PST
Received: from FHCRCVAX.BITNET (JOE) by UWAVM.ACS.WASHINGTON.EDU (Mailer X1.25)
 with BSMTP id 4438; Wed, 04 Jan 89 13:26:32 PST
Date: Wed, 4 Jan 89 13:26 PST
From: Joe Meadows <JOE%FHCRCVAX.BITNET@uwavm.acs.washington.edu>
Subject: Listing all mail users
To: info-vax@kl.sri.COM
X-VMS-To: IN%"info-vax@kl.sri.com"


There have been a few postings regarding doing things for all mail users,
the following tidbit of code retrieves a list of all mail users, their
mail directories, and their forwarding address. This only works under
VMS V5.n as it uses the callable interface. There are a few caveats,
an entry in the mail profile database isn't always completely legit,
for example, in ours, several entries refer to accounts that do not exist,
hence they do not have a mail directory. Two of our entries return a mail
directory like "DISK:[USER   ]", I'm not sure what causes this, perhaps
a user setting a mail subdirectory and the subdirectory later getting
deleted? Anyway, the following example code uses the callable interface,
and as such, I can not guarantee it will work with future versions, although
personally I would prefer to use this method to accessing the profile database
directly.

        Cheers,
        Joe Meadows     joe@fhcrcvax.bitnet

#include ctype
#include "$maildef.h"

struct itmlst
{
  short buffer_length;
  short item_code;
  long buffer_address;
  long return_length_address;
};

main (int argc, char *argv[])
{
  char user[32];
  char forward[80];
  char maildir[252];
  int ucontext = 0, userlen, fwdlen, mlen, sts, i;
  struct itmlst
    null_list[] = {{0,0,0,0}},
    uilist1[] = {{0,MAIL$_USER_FIRST,0,0}, {0,0,0,0}},
    uilist2[] = {{0,MAIL$_USER_NEXT,0,0},
                 {0,MAIL$_NOSIGNAL,0,0},
                 {0,0,0,0}},
    uolist[] = {{sizeof(user),MAIL$_USER_RETURN_USERNAME,user,&userlen},
                {sizeof(forward),MAIL$_USER_FORWARDING,forward,&fwdlen},
                {sizeof(maildir),MAIL$_USER_FULL_DIRECTORY,maildir,&mlen},
                {0,0,0,0}};

  sts = mail$user_begin(&ucontext,null_list,null_list);
  if (!(sts & 1)) return;

  sts = mail$user_get_info(&ucontext,uilist1,uolist);
  while (sts & 1)
  {
    printf("%.*s\t%.*s\t%.*s\n",userlen,user,mlen,maildir,fwdlen,forward);
    sts = mail$user_get_info(&ucontext,uilist2,uolist);
  }

  mail$user_end(&ucontext,null_list,null_list);
}

------------------------ end ---------------------------------

