From:	SMTP%"chris@csvax1.ucc.ie" 24-MAY-1993 09:17:38.64
To:	EVERHART
CC:	
Subj:	Re: changing read/new in mail.  A much different way.

X-Newsgroups: comp.os.vms
From: chris@csvax1.ucc.ie (Chris Higgins - System Administrator)
Subject: Re: changing read/new in mail.  A much different way.
Message-Id: <C7DC6M.D4o@curia.ucc.ie>
Sender: usenet@curia.ucc.ie
Reply-To: chris@csvax1.ucc.ie
Organization: Computer Science Dept. University College Cork, Ireland.
Date: Fri, 21 May 1993 08:42:22 GMT
Lines: 175
To: Info-VAX@kl.sri.com
X-Gateway-Source-Info: USENET

In article <01GYEJCZOZGCCTZ8KU@PUMA.DIR.TEXAS.GOV>, "Stewart Nichols (512) 463.7601" <NICHOLS_SA@PUMA.DIR.TEXAS.GOV> writes:
>Deborah Kaplan writes:
> 
>>hi.  i'm responsible for deleting all the users' mail off of haverford's
>>system over the summer.  the mail deletion itself is not a problem, but
>>i was wondering if there is a way to reset the newmail counter without
>>going into each individual account and typing "read/new".  i looked in the 
>>manuals, but didn't see anything.  could someone either help me out with
>>this or point to me to a manual i might have missed?  thanks very much.
>>
See the end of this for a piece of code that will do this.

>>deborah
>
>Are you going to go ahead and delete the account after deleting the mail?
>If so, there are easier ways to do what you ask than what has been 
>suggested so far.  Even if you aren't going to delete the account, this
>method works well if a different person is going to use the same account
>next semester, because it deletes the previous person's mail setups,
>such as favorite editor, default printer...
>
>If you are going to end up deleteing the whole account anyway, or if
>it is OK to trash the users's mail profile, then you can simply delete

What about 
$ mail
MAIL> remove username 

 ?????

.signature


/*
 * This code has been sitting on my system, for several generations of
 * System Administrators, so I cannot guarantee that any of them
 * didn't modify this code.  I make *NO* guarantees that the code will
 * work. (It does for me, and it should.... but I don't guarantee it)
 *
 * Usual disclaimers apply... Run at your own peril...
 * I just hope, that Joe Meadows doesn't mind me sending this out !
 *
 * J.C. Higgins,   +                         + If you love something, set it +
 * VMS Sys. Admin, + Chris@csvax1.ucc.ie     + free. If it doesn't come back +
 * Comp.Sc.Dept.   + Chris@odyssey.ucc.ie    + to you, hunt it down and      +
 * UCC, Ireland    + C.Higgins@bureau.ucc.ie + KILL it.      -- Me.          +
 */

/*	This software has been released in the public domain for
no consideration. Joe Meadows nor Timeline make any representation,
warranty, or claim as to its intended use or functionality, and no
liability shall attach through its use.

	Joe Meadows
	Timeline Inc.
	(206) 822-3140

	With that out of the way, this program is meant to serve as an
example of using the callable mail interface. The program is meant to
be run to fix all users new mail counts. It stemmed from a rash of people
having problems with their mail counts being off, and the difficulty of
describing the simple two step operation of reading all their new mail
and then executing READ/NEW one extra time (which fixes the count).

*/
#include ctype
#include maildef

typedef struct _ItemList
{
  short buffer_length;
  short item_code;
  void *buffer_address;
  long *return_length_address;
} ItemList;

main (int argc, char *argv[])
{
  char user[33];
  char maildir[253];
  short new, cnt;
  int ucontext = 0, userlen, mlen, sts, i;
  ItemList
    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}},
    uilist3[] = {{0,MAIL$_USER_USERNAME,user,0},
                 {sizeof(cnt),MAIL$_USER_SET_NEW_MESSAGES,&cnt,0},
                 {0,0,0,0}},
    uolist[] = {{sizeof(user) - 1,MAIL$_USER_RETURN_USERNAME,user,&userlen},
                {sizeof(maildir) - 1,MAIL$_USER_FULL_DIRECTORY,maildir,&mlen},
                {sizeof(new),MAIL$_USER_NEW_MESSAGES,&new,0},
                {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)
  {                    
    user[userlen] = '\0';
    maildir[mlen] = '\0';
    if (new > 0)
    {
      cnt = fix_user(user,maildir);
      if ((cnt != -1) && (cnt != new))
      {
        printf("Adjusting %s new mail count, from %d to %d\n",user,new,cnt);
        uilist3[0].buffer_length = userlen;
        mail$user_set_info(&ucontext,uilist3,null_list);
      }
    }

    sts = mail$user_get_info(&ucontext,uilist2,uolist);
  } 

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




fix_user(char *user, char *maildir)
{
  long sts, new = -1, mcontext = 0, fcontext = 0;
  short flags = MAIL$M_NEWMSG;
  ItemList
    null_list[] = {{0,0,0,0}},
    ns_list[] = {{0,MAIL$_NOSIGNAL,0,0},{0,0,0,0}},
    filist[] = {{strlen(maildir),MAIL$_MAILFILE_NAME,maildir,0},
                {0,MAIL$_NOSIGNAL,0,0},
                {0,0,0,0}},
    mblist[] = {{4,MAIL$_MESSAGE_FILE_CTX,&fcontext,0},
                {0,MAIL$_NOSIGNAL,0,0},
                {0,0,0,0}},
    mslist[] = {{sizeof(flags),MAIL$_MESSAGE_FLAGS,&flags,0},
                {sizeof("NEWMAIL"),MAIL$_MESSAGE_FOLDER,"NEWMAIL",0},
                {0,MAIL$_NOSIGNAL,0,0},
                {0,0,0,0}},
    milist[] = {{0,MAIL$_MESSAGE_NEXT,0,0},
                {0,MAIL$_NOSIGNAL,0,0},
                {0,0,0,0}};

  if (strlen(maildir) == 0)
    return 0; /* no maildirectory? They can't have no new mail... */

  if (mail$mailfile_begin(&fcontext,ns_list,null_list) & 1)
  {
    if (mail$mailfile_open(&fcontext,filist,null_list) & 1)
    {
      if (mail$message_begin(&mcontext,mblist,null_list) & 1)
      {
        new = 0;
        sts = mail$message_select(&mcontext,mslist,null_list);
        while (sts & 1)
        {
          sts = mail$message_info(&mcontext,milist,null_list);
          if (sts & 1) ++new;
        }
        mail$message_end(&mcontext,ns_list,null_list);
      }
      mail$mailfile_close(&fcontext,ns_list,null_list);
    }
    mail$mailfile_end(&fcontext,ns_list,null_list);
  }
  return(new);
}
                                                  Chris.

+ J.C. Higgins,    +                          + If you love something, set it +
+ VMS Sys. Admin,  + Chris@csvax1.ucc.ie      + free. If it doesn't come back +
+ Comp.Sc.Dept.    + Chris@odyssey.ucc.ie     + to you, hunt it down and      +
+ UCC, Ireland     + C.Higgins@bureau.ucc.ie  + KILL it.      -- Me.          +

