XMJBN1 ;ISC-SF/GMB-Access new mail in mailbox (cont.) ;04/06/2002 08:52
;;8.0;MailMan;;Jun 28, 2002
INIT(XMDUZ,XMK,XMKN,XMNEW,XMKMULT,XMABORT) ;
N I F I="N","N0" D BOGUS(XMDUZ,I)
D CHECK^XMVVITAE
I XMDUZ'=DUZ,'$$RPRIV^XMXSEC D Q
. S XMABORT=1
. D SHOW^XMJERR
S XMK=$O(^XMB(3.7,XMDUZ,"N0",0))
I XMK>0,XMK<1 D
. D FIXIT(XMDUZ)
. S XMK=$O(^XMB(3.7,XMDUZ,"N0",0))
I XMK="" D Q
. S XMABORT=1
. S $P(^XMB(3.7,XMDUZ,0),U,6)="" ; Just to make sure we're in synch.
. N XMPARM S XMPARM(2)=XMV("NAME")
. W !,$$EZBLD^DIALOG($S(XMDUZ=DUZ:34017,1:38156.2),.XMPARM) ; You have no new messages. / |2| has no new messages.
S XMNEW=$$TNMSGCT^XMXUTIL(XMDUZ)
I $O(^XMB(3.7,XMDUZ,"N0",XMK)) D
. S XMKMULT=1
. W !!,$$EZBLD^DIALOG($S(XMDUZ=DUZ:34019,1:34019.1),XMV("NAME")) ; You have/|1| has new mail in more than one basket
E S XMKMULT=0
S XMKN=$P(^XMB(3.7,XMDUZ,2,XMK,0),U)
Q
BOGUS(XMDUZ,XMTYPE) ; Check for and kill bogus node.
; This shouldn't be needed, but something (not MailMan) is setting it.
I $D(^XMB(3.7,XMDUZ,XMTYPE,0)) K ^XMB(3.7,XMDUZ,XMTYPE,0)
Q
FIXIT(XMDUZ) ; In case mail in the waste basket is new.
N XMK,XMZ
S (XMK,XMZ)=""
F S XMK=$O(^XMB(3.7,XMDUZ,"N0",XMK)) Q:XMK'<1!'XMK D
. F S XMZ=$O(^XMB(3.7,XMDUZ,"N0",XMK,XMZ)) Q:'XMZ D
. . D:$D(^XMB(3.7,XMDUZ,2,XMK,1,XMZ,0)) NONEW^XMXUTIL(XMDUZ,XMK,XMZ,1)
. . K:$D(^XMB(3.7,XMDUZ,"N0",XMK,XMZ)) ^XMB(3.7,XMDUZ,"N0",XMK,XMZ)
. . K:$D(^XMB(3.7,XMDUZ,"N",XMK,XMZ)) ^XMB(3.7,XMDUZ,"N",XMK,XMZ)
Q
NXTBSKT(XMDUZ,XMTYPE,XMKN,XMK,XMKPRI) ;
D NXTINIT(XMDUZ,XMTYPE)
I '$D(^TMP("XM",$J,XMTYPE)) D Q
. S XMK=0,XMKN="",XMKPRI=0,XMKPRI("XMKN")=""
. K ^TMP("XM",$J,"APX")
F D Q:XMKN'=""
. I XMKN="" S XMKPRI=0,XMKPRI("XMKN")="" K ^TMP("XM",$J,"APX")
. I XMKN=XMKPRI("XMKN") D Q:XMKN'=""
. . D NXTPRI(XMDUZ,XMTYPE,.XMKPRI)
. . S XMKN=XMKPRI("XMKN")
. E S XMKPRI=0,XMKPRI("XMKN")=""
. F S XMKN=$O(^TMP("XM",$J,XMTYPE,XMKN)) Q:XMKN="" Q:'$D(^TMP("XM",$J,"APX",XMTYPE,XMKN))
S XMK=^TMP("XM",$J,XMTYPE,XMKN)
K ^TMP("XM",$J,XMTYPE)
Q
NXTINIT(XMDUZ,XMTYPE) ;
N XMK,XMKN
K ^TMP("XM",$J,XMTYPE)
D BOGUS(XMDUZ,XMTYPE)
S XMK=0
F S XMK=$O(^XMB(3.7,XMDUZ,XMTYPE,XMK)) Q:'XMK D
. S XMKN=$P(^XMB(3.7,XMDUZ,2,XMK,0),U)
. S ^TMP("XM",$J,XMTYPE,XMKN)=XMK
Q
NXTPRI(XMDUZ,XMTYPE,XMKPRI) ;
I XMKPRI=100 S XMKPRI("XMKN")="" Q
I $D(^XMB(3.7,XMDUZ,2,"AP")) D I XMKPRI S ^TMP("XM",$J,"APX",XMTYPE,XMKPRI("XMKN"))="" Q
. N XMK,XMKN
. K ^TMP("XM",$J,"AP")
. S:XMKPRI XMKPRI=XMKPRI-.1
. S XMK=0
. F S XMKPRI=$O(^XMB(3.7,XMDUZ,2,"AP",XMKPRI)) Q:'XMKPRI D Q:XMKPRI("XMKN")'=""
. . F S XMK=$O(^XMB(3.7,XMDUZ,2,"AP",XMKPRI,XMK)) Q:'XMK D
. . . S XMKN=$P(^XMB(3.7,XMDUZ,2,XMK,0),U)
. . . Q:'$D(^TMP("XM",$J,XMTYPE,XMKN))
. . . S ^TMP("XM",$J,"AP",XMKPRI,XMKN)=""
. . S XMKPRI("XMKN")=$O(^TMP("XM",$J,"AP",XMKPRI,XMKPRI("XMKN")))
. K ^TMP("XM",$J,"AP")
S XMKPRI=100
N XMIN
S XMIN=$$EZBLD^DIALOG(37005) ; IN
I $D(^TMP("XM",$J,XMTYPE,XMIN)) S XMKPRI("XMKN")=XMIN,^TMP("XM",$J,"APX",XMTYPE,XMKPRI("XMKN"))="" Q
S XMKPRI("XMKN")=""
Q
; It used to be that the list of messages to "new" was kept in ^TMP.
; But if the user got forced off for some reason, the global was lost,
; and the messages were never "new"ed. So I changed to ^XTMP. We check
; ^XTMP whenever a user logs on (in ^XMVVITAE).
; Possible problem: one user is in the middle of reading new messages
; and "new"ing ones he wants to have "new" again, and a surrogate logs
; on, and triggers an immediate "new"ing of all those messages.
; I think it's an acceptable risk. Maybe not.
; This may be a case of 'damned if you do; damned if you don't'.
; Perhaps we should also check ^XTMP in the wee hours of the morning
; (in ^XMTDT), just in case the user doesn't log on again.
NEWAGAIN(XMDUZ) ; "new" messages which the user wanted to "new".
S ^XTMP("XM",0)=$$FMADD^XLFDT(DT,7)_U_DT
N XMZ,XMK
S XMZ=""
F S XMZ=$O(^XTMP("XM","MAKENEW",XMDUZ,XMZ)) Q:XMZ="" D K ^XTMP("XM","MAKENEW",XMDUZ,XMZ)
. S XMK=$O(^XMB(3.7,"M",XMZ,XMDUZ,0)) Q:'XMK
. Q:$D(^XMB(3.7,XMDUZ,"N0",XMK,XMZ))
. D MAKENEW^XMXUTIL(XMDUZ,XMK,XMZ,1)
Q
XMJBN1 ;ISC-SF/GMB-Access new mail in mailbox (cont.) ;04/06/2002 08:52
+1 ;;8.0;MailMan;;Jun 28, 2002
INIT(XMDUZ,XMK,XMKN,XMNEW,XMKMULT,XMABORT) ;
+1 NEW I
FOR I="N","N0"
DO BOGUS(XMDUZ,I)
+2 DO CHECK^XMVVITAE
+3 IF XMDUZ'=DUZ
IF '$$RPRIV^XMXSEC
Begin DoDot:1
+4 SET XMABORT=1
+5 DO SHOW^XMJERR
End DoDot:1
QUIT
+6 SET XMK=$ORDER(^XMB(3.7,XMDUZ,"N0",0))
+7 IF XMK>0
IF XMK<1
Begin DoDot:1
+8 DO FIXIT(XMDUZ)
+9 SET XMK=$ORDER(^XMB(3.7,XMDUZ,"N0",0))
End DoDot:1
+10 IF XMK=""
Begin DoDot:1
+11 SET XMABORT=1
+12 ; Just to make sure we're in synch.
SET $PIECE(^XMB(3.7,XMDUZ,0),U,6)=""
+13 NEW XMPARM
SET XMPARM(2)=XMV("NAME")
+14 ; You have no new messages. / |2| has no new messages.
WRITE !,$$EZBLD^DIALOG($SELECT(XMDUZ=DUZ:34017,1:38156.2),.XMPARM)
End DoDot:1
QUIT
+15 SET XMNEW=$$TNMSGCT^XMXUTIL(XMDUZ)
+16 IF $ORDER(^XMB(3.7,XMDUZ,"N0",XMK))
Begin DoDot:1
+17 SET XMKMULT=1
+18 ; You have/|1| has new mail in more than one basket
WRITE !!,$$EZBLD^DIALOG($SELECT(XMDUZ=DUZ:34019,1:34019.1),XMV("NAME"))
End DoDot:1
+19 IF '$TEST
SET XMKMULT=0
+20 SET XMKN=$PIECE(^XMB(3.7,XMDUZ,2,XMK,0),U)
+21 QUIT
BOGUS(XMDUZ,XMTYPE) ; Check for and kill bogus node.
+1 ; This shouldn't be needed, but something (not MailMan) is setting it.
+2 IF $DATA(^XMB(3.7,XMDUZ,XMTYPE,0))
KILL ^XMB(3.7,XMDUZ,XMTYPE,0)
+3 QUIT
FIXIT(XMDUZ) ; In case mail in the waste basket is new.
+1 NEW XMK,XMZ
+2 SET (XMK,XMZ)=""
+3 FOR
SET XMK=$ORDER(^XMB(3.7,XMDUZ,"N0",XMK))
IF XMK'<1!'XMK
QUIT
Begin DoDot:1
+4 FOR
SET XMZ=$ORDER(^XMB(3.7,XMDUZ,"N0",XMK,XMZ))
IF 'XMZ
QUIT
Begin DoDot:2
+5 IF $DATA(^XMB(3.7,XMDUZ,2,XMK,1,XMZ,0))
DO NONEW^XMXUTIL(XMDUZ,XMK,XMZ,1)
+6 IF $DATA(^XMB(3.7,XMDUZ,"N0",XMK,XMZ))
KILL ^XMB(3.7,XMDUZ,"N0",XMK,XMZ)
+7 IF $DATA(^XMB(3.7,XMDUZ,"N",XMK,XMZ))
KILL ^XMB(3.7,XMDUZ,"N",XMK,XMZ)
End DoDot:2
End DoDot:1
+8 QUIT
NXTBSKT(XMDUZ,XMTYPE,XMKN,XMK,XMKPRI) ;
+1 DO NXTINIT(XMDUZ,XMTYPE)
+2 IF '$DATA(^TMP("XM",$JOB,XMTYPE))
Begin DoDot:1
+3 SET XMK=0
SET XMKN=""
SET XMKPRI=0
SET XMKPRI("XMKN")=""
+4 KILL ^TMP("XM",$JOB,"APX")
End DoDot:1
QUIT
+5 FOR
Begin DoDot:1
+6 IF XMKN=""
SET XMKPRI=0
SET XMKPRI("XMKN")=""
KILL ^TMP("XM",$JOB,"APX")
+7 IF XMKN=XMKPRI("XMKN")
Begin DoDot:2
+8 DO NXTPRI(XMDUZ,XMTYPE,.XMKPRI)
+9 SET XMKN=XMKPRI("XMKN")
End DoDot:2
IF XMKN'=""
QUIT
+10 IF '$TEST
SET XMKPRI=0
SET XMKPRI("XMKN")=""
+11 FOR
SET XMKN=$ORDER(^TMP("XM",$JOB,XMTYPE,XMKN))
IF XMKN=""
QUIT
IF '$DATA(^TMP("XM",$JOB,"APX",XMTYPE,XMKN))
QUIT
End DoDot:1
IF XMKN'=""
QUIT
+12 SET XMK=^TMP("XM",$JOB,XMTYPE,XMKN)
+13 KILL ^TMP("XM",$JOB,XMTYPE)
+14 QUIT
NXTINIT(XMDUZ,XMTYPE) ;
+1 NEW XMK,XMKN
+2 KILL ^TMP("XM",$JOB,XMTYPE)
+3 DO BOGUS(XMDUZ,XMTYPE)
+4 SET XMK=0
+5 FOR
SET XMK=$ORDER(^XMB(3.7,XMDUZ,XMTYPE,XMK))
IF 'XMK
QUIT
Begin DoDot:1
+6 SET XMKN=$PIECE(^XMB(3.7,XMDUZ,2,XMK,0),U)
+7 SET ^TMP("XM",$JOB,XMTYPE,XMKN)=XMK
End DoDot:1
+8 QUIT
NXTPRI(XMDUZ,XMTYPE,XMKPRI) ;
+1 IF XMKPRI=100
SET XMKPRI("XMKN")=""
QUIT
+2 IF $DATA(^XMB(3.7,XMDUZ,2,"AP"))
Begin DoDot:1
+3 NEW XMK,XMKN
+4 KILL ^TMP("XM",$JOB,"AP")
+5 IF XMKPRI
SET XMKPRI=XMKPRI-.1
+6 SET XMK=0
+7 FOR
SET XMKPRI=$ORDER(^XMB(3.7,XMDUZ,2,"AP",XMKPRI))
IF 'XMKPRI
QUIT
Begin DoDot:2
+8 FOR
SET XMK=$ORDER(^XMB(3.7,XMDUZ,2,"AP",XMKPRI,XMK))
IF 'XMK
QUIT
Begin DoDot:3
+9 SET XMKN=$PIECE(^XMB(3.7,XMDUZ,2,XMK,0),U)
+10 IF '$DATA(^TMP("XM",$JOB,XMTYPE,XMKN))
QUIT
+11 SET ^TMP("XM",$JOB,"AP",XMKPRI,XMKN)=""
End DoDot:3
+12 SET XMKPRI("XMKN")=$ORDER(^TMP("XM",$JOB,"AP",XMKPRI,XMKPRI("XMKN")))
End DoDot:2
IF XMKPRI("XMKN")'=""
QUIT
+13 KILL ^TMP("XM",$JOB,"AP")
End DoDot:1
IF XMKPRI
SET ^TMP("XM",$JOB,"APX",XMTYPE,XMKPRI("XMKN"))=""
QUIT
+14 SET XMKPRI=100
+15 NEW XMIN
+16 ; IN
SET XMIN=$$EZBLD^DIALOG(37005)
+17 IF $DATA(^TMP("XM",$JOB,XMTYPE,XMIN))
SET XMKPRI("XMKN")=XMIN
SET ^TMP("XM",$JOB,"APX",XMTYPE,XMKPRI("XMKN"))=""
QUIT
+18 SET XMKPRI("XMKN")=""
+19 QUIT
+20 ; It used to be that the list of messages to "new" was kept in ^TMP.
+21 ; But if the user got forced off for some reason, the global was lost,
+22 ; and the messages were never "new"ed. So I changed to ^XTMP. We check
+23 ; ^XTMP whenever a user logs on (in ^XMVVITAE).
+24 ; Possible problem: one user is in the middle of reading new messages
+25 ; and "new"ing ones he wants to have "new" again, and a surrogate logs
+26 ; on, and triggers an immediate "new"ing of all those messages.
+27 ; I think it's an acceptable risk. Maybe not.
+28 ; This may be a case of 'damned if you do; damned if you don't'.
+29 ; Perhaps we should also check ^XTMP in the wee hours of the morning
+30 ; (in ^XMTDT), just in case the user doesn't log on again.
NEWAGAIN(XMDUZ) ; "new" messages which the user wanted to "new".
+1 SET ^XTMP("XM",0)=$$FMADD^XLFDT(DT,7)_U_DT
+2 NEW XMZ,XMK
+3 SET XMZ=""
+4 FOR
SET XMZ=$ORDER(^XTMP("XM","MAKENEW",XMDUZ,XMZ))
IF XMZ=""
QUIT
Begin DoDot:1
+5 SET XMK=$ORDER(^XMB(3.7,"M",XMZ,XMDUZ,0))
IF 'XMK
QUIT
+6 IF $DATA(^XMB(3.7,XMDUZ,"N0",XMK,XMZ))
QUIT
+7 DO MAKENEW^XMXUTIL(XMDUZ,XMK,XMZ,1)
End DoDot:1
KILL ^XTMP("XM","MAKENEW",XMDUZ,XMZ)
+8 QUIT