From:	SMTP%"RELAY-INFO-VAX@CRVAX.SRI.COM" 18-MAY-1993 15:01:14.96
To:	EVERHART
CC:	
Subj:	Re: NEW-MAIL COUNT with VMS-Mail in batch mode not displayed ?

From: mikel@anorad.com (Mikel Beck)
X-Newsgroups: comp.os.vms
Subject: Re: NEW-MAIL COUNT with VMS-Mail in batch mode not displayed ?
Message-Id: <1993May17.171511.140@anorad.com>
Date: 17 May 93 17:15:11 EST
Distribution: world
Organization: Anorad Corporation
Lines: 82
To: Info-VAX@kl.sri.com
X-Gateway-Source-Info: USENET

>> You could use DCL to read VMSMAIL_PROFILE.DATA directly, based on the file
>> format that's been published here and elsewhere.  However, reading the file
>> directly is prone to breaking since only callable mail is supported by DEC
>> for accessing the file.  The better way would be a program in the language
>> of your choice using callable mail to return the new-mail count in a symbol.

	As a matter of fact, I had a need to do this some time ago.
	All the following routine does is get the current user's 
	name, and return how many new unread messages are waiting.

#include <stdio.h>
#include <ssdef.h>
#include <jpidef.h>
#include <maildef.h>
#include <ctype.h>
#include <nam.h>

struct ItemList
{
   short BufferLength;
   short ItemCode;
   long BufferAddress;
   long ReturnLengthAddress;
};

struct ItemList NullList[] = { { 0, 0, 0, 0 } };

int UserContext = 0;

int MainCheck ( void );

int MailCheck ( void )
{
   int UserLength = 0;
   char User[13];
   short NewMessages = 0;
   int Status = SS$_NORMAL;
   
   struct ItemList JpiList[] = 
   {
      { sizeof ( User ) - 1 , JPI$_USERNAME, &User, &UserLength },
      { 0, 0, 0, 0, } 
   };

   struct ItemList UserItemList[] =
   {
      { 0, MAIL$_USER_USERNAME, 0, 0 },
      { 0, 0, 0, 0 }
   };
  
   struct ItemList OutItemList[] =
   {
      { sizeof ( NewMessages ), MAIL$_USER_NEW_MESSAGES, &NewMessages, 0 },
      { 0, 0, 0, 0 }
   };

   Status = MAIL$USER_BEGIN ( &UserContext, &NullList, &NullList );
   if ( Status != SS$_NORMAL ) return ( 0 );
  
   sys$getjpiw ( 0, 0, 0, JpiList, 0, 0, 0 );
   User[UserLength] = '\0';

   while ( isspace ( User[--UserLength] ) )
      User[UserLength] = '\0';

   UserItemList[0].BufferLength = strlen ( User );
   UserItemList[0].BufferAddress = User;
   
   Status = MAIL$USER_GET_INFO ( &UserContext, UserItemList, OutItemList );
   if ( Status != SS$_NORMAL ) return ( 0 );

   Status = MAIL$USER_END ( &UserContext, &NullList, &NullList );
   if ( Status != SS$_NORMAL ) return ( 0 );

   return ( NewMessages );
}

+-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+
|      Mikel Beck - Senior Business Programmer, Anorad Corporation        |
|                        E-Mail: mikel@anorad.com                         |
|                         "Excellence In Motion"                          |
+-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+

