From:	MERC::"uunet!CRVAX.SRI.COM!RELAY-INFO-VAX" 18-MAY-1992 20:40:53.16
To:	info-vax@kl.sri.com
CC:	
Subj:	Fix NEWMAIL counter  (program)


   Here's one solution to an FAQ.  Whenever your new mail count deviates from
what's actually in NEWMAIL just run the following program and it will adjust
the newmail count to the number of messages actually in NEWMAIL.

            MAILCOUNT.MAR follows:

;-----------------------------------------------------------------------------
	.TITLE	RESET New Mail counter
	.IDENT	/V1.0/
;
;******************************************************************************
;*                                                                            *
;*  COPYRIGHT (c) 1992                                                        *
;*  Anthony C. McCracken                                                      *
;*  ALL RIGHTS RESERVED                                                       *
;*                                                                            *
;*  THIS PROGRAM HAS BEEN RELEASED INTO THE PUBLIC DOMAIN.  IT MAY BE FREELY  *
;*  DISTRIBUTED AND USED.  THE SOURCE MAY BE MODIFIED AS WELL TO SUIT ONE'S   *
;*  PARTICULAR NEEDS.  THIS PROGRAM MUST NOT BE SOLD.                         *
;*                                                                            *
;*  THE AUTHOR ASSUMES NO RESPONSIBILITY FOR THE USE OF THIS PROGRAM ON ANY   *
;*  OTHER COMPUTER SYSTEMS.                                                   *
;*                                                                            *
;******************************************************************************
;

;++
; FACILITY:	VMS MAIL
;
; ABSTRACT:	This program counts the number of messages in the NEWMAIL
;		folder and set the new message count accordingly.
;
; ENVIRONMENT:	USER MODE
;
; SECURITY:	NONE
;
; AUTHOR:	Anthony C. McCracken
;
; CREATION DATE:  15-May-1992
;
; USAGE:	$ RUN RSETNMCT
;
; MODIFIED BY:	None
;
;--

	$SSDEF
	$MAILDEF

;++
;   Define macros
;--

;+
; Builds ITEM_LIST_3 structures
;-
	.MACRO	.ITEM_3	BUFLEN=0,ICODE=0,BADDR=0,RLADDR=0
		.WORD		BUFLEN
		.WORD		ICODE
		.ADDRESS	BADDR
		.ADDRESS	RLADDR
	.ENDM	.ITEM_3

;+
; Makes the call to MAIL$MAILFILE_rtn easier.  All four parameters must be
; specified.  The macro then sets up the stack for the CALLS to the desired
; rotuine.
;-
	.MACRO	MAILFILE	RTN,CTXT,INIL=0,OUTIL=0
		.IF B	<RTN>
			.ERROR	;Routine must be specified
			.MEXIT
		.ENDC
		.IF B	CTXT
			.ERROR	;Context must be specified
			.MEXIT
		.ENDC
		.GLOBL	RTN
		.IF EQ OUTIL
			PUSHL	#0
		.IFF
			$PUSHADR	OUTIL,CONTEXT=L
		.ENDC
		.IF EQ	INIL
			PUSHL	#0
		.IFF
			$PUSHADR	INIL,CONTEXT=L
		.ENDC
		$PUSHADR	CTXT,CONTEXT=L
		CALLS	#3,G^MAIL$MAILFILE_'RTN
	.ENDM	MAILFILE

;+
; Makes the call to MAIL$MESSAGE_rtn easier.  All four parameters must be
; specified.  The macro then sets up the stack for the CALLS to the desired
; rotuine.
;-
	.MACRO	MAILMESSAGE	RTN,CTXT,INIL=0,OUTIL=0
		.IF B	RTN
			.ERROR	;Routine must be specified
			.MEXIT
		.ENDC
		.IF B	CTXT
			.ERROR	;Context must be specified
			.MEXIT
		.ENDC
		.GLOBL	RTN
		.IF EQ OUTIL
			PUSHL	#0
		.IFF
			$PUSHADR	OUTIL,CONTEXT=L
		.ENDC
		.IF EQ	INIL
			PUSHL	#0
		.IFF
			$PUSHADR	INIL,CONTEXT=L
		.ENDC
		$PUSHADR	CTXT,CONTEXT=L
		CALLS	#3,G^MAIL$MESSAGE_'RTN
	.ENDM	MAILMESSAGE

;+
; Makes the call to MAIL$USER_rtn easier.  All four parameters must be
; specified.  The macro then sets up the stack for the CALLS to the desired
; rotuine.
;-
	.MACRO	MAILUSER	RTN,CTXT,INIL=0,OUTIL=0
		.IF B	RTN
			.ERROR	;Routine must be specified
			.MEXIT
		.ENDC
		.IF B	CTXT
			.ERROR	;Context must be specified
			.MEXIT
		.ENDC
		.GLOBL	RTN
		.IF EQ OUTIL
			PUSHL	#0
		.IFF
			$PUSHADR	OUTIL,CONTEXT=L
		.ENDC
		.IF EQ	INIL
			PUSHL	#0
		.IFF
			$PUSHADR	INIL,CONTEXT=L
		.ENDC
		$PUSHADR	CTXT,CONTEXT=L
		CALLS	#3,G^MAIL$USER_'RTN
	.ENDM	MAILUSER

	.PSECT	RWDATA,RD,WRT,NOEXE,LONG
;+
; Context variables used by MAIL$ routines.
;-

MFCTX:	.LONG	0		; MAIL FILE context
MMCTX:	.LONG	0		; MAIL MESSAGE context
MUCTX:	.LONG	0		; MAIL USER context

;+
; The following are used in the computation of the actual new message count.
;-

FNAME:	.ASCII	/NEWMAIL/	; MAIL Folder name
FNAME_S = .-FNAME

NMCNT:	.LONG	0		; Number of messages in NEWMAIL

;+
; The following item lists are passed to the MAIL$ routines to get information
; or set parameters within VAX MAIL.
;-

NLITM:	.ITEM_3		; A null item list

MMBITM:	.ITEM_3	4,MAIL$_MESSAGE_FILE_CTX,MFCTX,0
	.ITEM_3		; Used to initialize the mail message context

MMSITM:	.ITEM_3	0,MAIL$_NOSIGNAL,0,0
	.ITEM_3	FNAME_S,MAIL$_MESSAGE_FOLDER,FNAME,0
	.ITEM_3		; Used to select the NEWMAIL folder if it exists

NMCITM:	.ITEM_3	4,MAIL$_MESSAGE_SELECTED,NMCNT,0
	.ITEM_3		; Retrieves the actual newmail messages

SNMITM:	.ITEM_3	2,MAIL$_USER_SET_NEW_MESSAGES,NMCNT,0
	.ITEM_3		; Sets newmail count to equal the new message count

;++
; Routine to open the mail file, select the NEWMAIL folder, get the number of
; messages, access the MAIL PROFILE and set the newmail count to the actual
; number of messages present.
;--
	.PSECT	CODE,RD,NOWRT,EXE,BYTE
	.ENTRY	MAIN,^M<>
;+
; Open the mail file.
;-
	MAILFILE	RTN=BEGIN,CTXT=MFCTX,INIL=NLITM,OUTIL=NLITM
	MAILFILE	RTN=OPEN,CTXT=MFCTX,INIL=NLITM,OUTIL=NLITM
;+
; Select NEWMAIL
;-
	MAILMESSAGE	RTN=BEGIN,CTXT=MMCTX,INIL=MMBITM,OUTIL=NLITM
	MAILMESSAGE	RTN=SELECT,CTXT=MMCTX,INIL=MMSITM,OUTIL=NMCITM
;+
; Set the newmail count.
;-
	MAILUSER	RTN=BEGIN,CTXT=MUCTX,INIL=NLITM,OUTIL=NLITM
	MAILUSER	RTN=SET_INFO,CTXT=MUCTX,INIL=SNMITM,OUTIL=NLITM
;+
; Cleanup and exit mail.
;-
	MAILUSER	RTN=END,CTXT=MUCTX,INIL=NLITM,OUTIL=NLITM
	MAILMESSAGE	RTN=END,CTXT=MMCTX,INIL=NLITM,OUTIL=NLITM
	MAILFILE	RTN=CLOSE,CTXT=MFCTX,INIL=NLITM,OUTIL=NLITM
	MAILFILE	RTN=END,CTXT=MFCTX,INIL=NLITM,OUTIL=NLITM
;+
; Exit program
;-
	$EXIT_S
	.END	MAIN

;---------------------------------------------------------------------------



+----------------------------------------+-----------------------------------+
| Anthony C. McCracken                   |                                   |
| Northern Arizona University            | Boom boom boom,,, Still going !   |
| Flagstaff, Arizona                     |                                   |
|                                        | VMS just keeps going and going and|
| acm@nauvax                   BitNet    | going.  Nothing outlasts VAX/VMS. |
| acm@nauvax.ucc.nau.edu       Internet  |                                   |
| 602.523.9422.us.west         Noise net |                                   |
+----------------------------------------+-----------------------------------+

