Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: XMAPHOST

XMAPHOST.m

Go to the documentation of this file.
  1. XMAPHOST ;ISC-SF/GMB-Print to Message (P-MESSAGE) ;07/29/2003 14:36
  1. ;;8.0;MailMan;**2,17,21,28,33**;Jun 28, 2002;Build 1
  1. ;Was (WASH ISC)/KMB/CAP before extensive rework.
  1. ;
  1. ;This routine handles printing to P-MESSAGE.
  1. ;
  1. ;To print reports to mail messages, we actually write to host files
  1. ;(DOS,VMS...) and then suck them into mail messages. MailMan works
  1. ;closely with TaskMan and the device handler to make it happen.
  1. ;
  1. ;If a user or application wants to write something to a mail message,
  1. ;the user should choose (or the application should set ZTIO=) a device
  1. ;whose name starts with "P-MESSAGE". The user or application can
  1. ;set the subject of the message, as well as the recipients. The user
  1. ;does this by responding to MailMan queries, and the application does
  1. ;this by setting input variables (see below).
  1. ;
  1. ;EN^XMAPHOST is called as a pre-open execute for the P-MESSAGE device,
  1. ;and READ^XMAPHOST is called as a close execute for the P-MESSAGE
  1. ;terminal type.
  1. ;
  1. ;The pre-open execute is there to capture the wishes (message subject,
  1. ;recipients, and whether to queue or not) of the user working in the
  1. ;foreground. The global ^TMP("XM-MESS",$J) is created, as a result.
  1. ;TaskMan looks for this global whenever $E(ZTIO,1,9)="P-MESSAGE", and
  1. ;includes it in the task, if the user chooses to task the print. This
  1. ;is a special arrangement that MailMan has with TaskMan.
  1. ;
  1. ;If the job printing to P-MESSAGE is running in the background, then
  1. ;the pre-open execute code does not get executed during the pre-open
  1. ;execute; instead, it is run as part of the close execute.
  1. ;
  1. ;If more than 250 consecutive null lines are encountered, MailMan
  1. ;assumes EOF has somehow been missed, and stops transferring lines from
  1. ;the host file to the message.
  1. ;
  1. ;This routine has one idiosyncracy. If the report contains one single
  1. ;line or two lines separated with only a $C(13) instead of a CR/LF that
  1. ;is more than 254 characters long, there will be unexpected results.
  1. ;
  1. ;Variables:
  1. ;input:
  1. ; XMDUZ (optional) Sender DUZ or string (default=DUZ)
  1. ; If XMDUZ is a string, then user will not be asked who the
  1. ; message should be from.
  1. ; XMSUB (optional) message subject. If not supplied, then default
  1. ; subject is "Queued mail report from "<user name>
  1. ; XMY(x)="" (optional) array of additional addressees to whom the
  1. ; message should be sent. See documentation for ^XMD for more
  1. ; info on XMY.
  1. ; The message will always be sent to XMDUZ (unless XMDUZ is a
  1. ; string), so it is not necessary to set XMY(XMDUZ)="".
  1. ; XMQUIET (optional) if $G(XMQUIET), then there is no user interaction
  1. ; and no information written to the screen.
  1. ; XMZBACK (optional) if $D(XMZBACK), then XMZ is set upon exit,
  1. ; and XMZBACK is killed.
  1. ;output:
  1. ; XMZ If $D(XMZBACK), then XMZ is set with the IEN of the message,
  1. ; and XMZBACK is killed; otherwise, XMZ is not set, and
  1. ; remains whatever it was (or wasn't) before the call.
  1. ; XMMG If error, may contain error message.
  1. ; XMV("ERROR") If error, may contain error message.
  1. ;
  1. EN ; Entry from pre-open execute of P-MESSAGE entry in DEVICE file.
  1. ; If the user chooses to queue the print, we don't want this code
  1. ; (the pre-open execute of the DEVICE file entry) to execute when
  1. ; the task starts up.
  1. K ^TMP("XM-MESS",$J)
  1. N %H
  1. Q:$D(ZTQUEUED)!$G(XMQUIET)!$D(DDS)
  1. N XMAPHOST,XMABORT
  1. D SETUP(.XMAPHOST,.XMABORT) I XMABORT S (POP,DUOUT,%ZISQUIT)=1 K IO("Q") Q
  1. M ^TMP("XM-MESS",$J,"XMY")=^TMP("XMY",$J)
  1. M ^TMP("XM-MESS",$J,"XMY0")=^TMP("XMY0",$J)
  1. M ^TMP("XM-MESS",$J,"XMAPHOST")=XMAPHOST
  1. D CLEANUP^XMXADDR
  1. D KSETS
  1. Q
  1. SETUP(XMAPHOST,XMABORT) ; Entry during close-execute (called from READ^XMAPHOST)
  1. N XMINSTR
  1. S XMABORT=0
  1. D INIT(.XMDUZ,.XMAPHOST,.XMINSTR,.XMABORT)
  1. I 'XMABORT D GETSUBJ($S($D(XMAPSUBJ):XMAPSUBJ,$D(XMSUB):XMSUB,1:""),.XMAPHOST,.XMABORT)
  1. I 'XMABORT D FROMWHOM(XMDUZ,.XMINSTR,.XMABORT)
  1. I 'XMABORT D ADDRMSG(XMDUZ,.XMINSTR,.XMABORT)
  1. I 'XMABORT M XMAPHOST("XMINSTR")=XMINSTR Q
  1. D CLEANUP^XMXADDR
  1. D KSETS
  1. Q
  1. INIT(XMDUZ,XMAPHOST,XMINSTR,XMABORT) ;
  1. I '$D(XMDUZ) S XMDUZ=DUZ,XMAPHOST("SET XMDUZ")=1 K XMV
  1. S XMAPHOST("CHG XMDUZ")=XMDUZ
  1. D SETFROM^XMD(.XMDUZ,.XMINSTR) I $D(XMMG) S XMABORT=1 Q
  1. I '$D(XMINSTR("FROM")) K XMAPHOST("CHG XMDUZ")
  1. I '$D(XMV("NAME")) D Q:XMABORT
  1. . S XMAPHOST("SET XMV")=1
  1. . D INITAPI^XMVVITAE
  1. . I $D(XMV("ERROR")) S XMABORT=1 D:'$D(ZTQUEUED) ERROR^XM(.XMV,"ERROR")
  1. I $D(XMZBACK) S XMAPHOST("XMZBACK")="" K XMZBACK
  1. S XMAPHOST("XMDUZ")=XMDUZ
  1. M XMAPHOST("XMV")=XMV
  1. Q
  1. GETSUBJ(XMSUBJ,XMAPHOST,XMABORT) ;
  1. D CHKSUBJ(.XMSUBJ)
  1. I $D(ZTQUEUED)!$G(XMQUIET) D
  1. . S XMSUBJ=$G(XMSUBJ,$E($$EZBLD^DIALOG(34233,XMV("NAME")),1,65)) ; queued mail report from |1|
  1. E D SUBJ^XMJMS(.XMSUBJ,.XMABORT) Q:XMABORT
  1. S XMAPHOST("XMSUB")=XMSUBJ
  1. Q
  1. CHKSUBJ(XMSUBJ) ;
  1. I XMSUBJ="" K XMSUBJ Q
  1. K XMERR,^TMP("XMERR",$J)
  1. I $L(XMSUBJ)<3 S XMSUBJ=XMSUBJ_"..."
  1. I $L(XMSUBJ)>65 S XMSUBJ=$E(XMSUBJ,1,65)
  1. S XMSUBJ=$$XMSUBJ^XMXPARM("",XMSUBJ)
  1. I $D(XMERR) K XMSUBJ,XMERR,^TMP("XMERR",$J)
  1. Q
  1. FROMWHOM(XMDUZ,XMINSTR,XMABORT) ;
  1. I XMDUZ=.5!$D(XMINSTR("FROM")) Q
  1. N XMFROM
  1. S XMFROM=$P($G(^XMB(3.7,XMDUZ,16)),U,3)
  1. I $D(ZTQUEUED)!$G(XMQUIET) D Q
  1. . I XMFROM="P" S XMINSTR("FROM")="POSTMASTER"
  1. N DIR,X,Y,XMME,XMPOST
  1. S DIR("A")=$$EZBLD^DIALOG(34239) ; From whom
  1. S XMME=$$EZBLD^DIALOG(34240) ; M:Me
  1. S XMPOST=$$EZBLD^DIALOG(34241) ; P:Postmaster
  1. S DIR(0)="S^"_XMME_";"_XMPOST
  1. S DIR("B")=$S(XMFROM="P":$P(XMPOST,":",2,9),1:$P(XMME,":",2,9))
  1. D BLD^DIALOG(34242,"","","DIR(""?"")") ; Answer 'Me' if the message should be from...
  1. D ^DIR I $D(DIRUT) S XMABORT=1 Q
  1. I Y=$P(XMPOST,":",1) S XMINSTR("FROM")="POSTMASTER"
  1. Q
  1. ADDRMSG(XMDUZ,XMINSTR,XMABORT) ;
  1. ;I '$D(ZTQUEUED),'$G(XMQUIET) K XMY,XMY0
  1. D INIT^XMXADDR
  1. K XMERR,^TMP("XMERR",$J)
  1. I $D(ZTQUEUED)!$G(XMQUIET) D
  1. . I '$D(XMAPHOST("CHG XMDUZ")) S XMY(XMDUZ)=""
  1. . D CHKBSKT^XMD(.XMY,.XMINSTR)
  1. . D CHKADDR^XMXADDR(XMDUZ,.XMY,.XMINSTR)
  1. . K XMY
  1. E D Q:XMABORT ; ask the user for recipients.
  1. . D TOWHOM^XMJMT(XMDUZ,$$EZBLD^DIALOG(34110),.XMINSTR,"",.XMABORT) ; send
  1. Q
  1. READ ; Entry from close-execute of P-MESSAGE entry in TERMINAL TYPE file.
  1. ; Read the host file into a message, send it, erase it.
  1. ; Read record from file.
  1. ; Each time <CR> is found in record it ends a message line.
  1. N X,XMNULCNT,XMLEN,XMZZ,XMREC,XMI,XMLIMIT,XMAPHOST,XMINSTR,XMABORT
  1. I '$D(^TMP("XM-MESS",$J)) D Q:XMABORT
  1. . D SETUP(.XMAPHOST,.XMABORT)
  1. E D
  1. . M ^TMP("XMY",$J)=^TMP("XM-MESS",$J,"XMY")
  1. . M ^TMP("XMY0",$J)=^TMP("XM-MESS",$J,"XMY0")
  1. . M XMAPHOST=^TMP("XM-MESS",$J,"XMAPHOST")
  1. . K ^TMP("XM-MESS",$J)
  1. S XMDUZ=XMAPHOST("XMDUZ")
  1. M XMV=XMAPHOST("XMV")
  1. M XMINSTR=XMAPHOST("XMINSTR")
  1. S XMLIMIT=$P($G(^XMB(1,1,.16)),U) ; P-MESSAGE LINE LIMIT
  1. S:'XMLIMIT XMLIMIT=999999999999999
  1. D CRE8XMZ^XMXSEND(XMAPHOST("XMSUB"),.XMZZ)
  1. I '$D(ZTQUEUED),'$G(XMQUIET) D
  1. . U IO(0)
  1. . W !,$$EZBLD^DIALOG(34234) ; Moving to MailMan message...
  1. . W !,"."
  1. U IO
  1. S (XMNULCNT,XMI)=0,XMREC=""
  1. N $ETRAP,$ESTACK S $ETRAP="D EOFERR^XMAPHOST"
  1. F S XMREC=$$GET() Q:$G(XMAPHOST("EOF")) D Q:$G(XMAPHOST("EOF"))!(XMI>XMLIMIT)
  1. . I XMREC="" D Q:$G(XMAPHOST("EOF"))
  1. . . S XMNULCNT=XMNULCNT+1
  1. . . Q:XMNULCNT'>250 ; If more than 250 consecutive null lines,
  1. . . S XMAPHOST("EOF")=1 ; set EOF and get rid of those null lines.
  1. . . F K ^XMB(3.9,XMZZ,2,XMI,0) S XMI=XMI-1 Q:'XMI Q:$G(^XMB(3.9,XMZZ,2,XMI,0))'=""
  1. . E S XMNULCNT=0
  1. . S XMLEN=$L(XMREC)
  1. . F D Q:XMREC=""!$G(XMAPHOST("EOF"))
  1. . . D PUT(XMZZ,$P(XMREC,$C(13)),.XMI)
  1. . . S XMREC=$P(XMREC,$C(13),2,999)
  1. . . Q:XMREC=""
  1. . . S:XMLEN>254 XMREC=XMREC_$$GET(),XMLEN=0
  1. D EOF
  1. Q
  1. GET() ; Read a record from the file
  1. N Y,X
  1. N $ETRAP,$ESTACK S $ETRAP="S $EC="""" S XMAPHOST(""EOF"")=1 Q """""
  1. R Y#255:1
  1. Q Y
  1. PUT(XMZZ,XMREC,XMI) ; Put data into message.
  1. S XMI=XMI+1,^XMB(3.9,XMZZ,2,XMI,0)=$S(XMREC'?.E1C.E:XMREC,1:$$CTRL^XMXUTIL1(XMREC))
  1. I '$D(ZTQUEUED),'$G(XMQUIET),XMI#10=0 U IO(0) W "." U IO
  1. Q
  1. EOFERR ;
  1. D EOF
  1. D UNWIND^%ZTER
  1. Q
  1. EOF ;
  1. S $ETRAP=""
  1. I XMI>XMLIMIT D
  1. . S XMI=XMI+1,^XMB(3.9,XMZZ,2,XMI,0)=""
  1. . S XMI=XMI+1,^XMB(3.9,XMZZ,2,XMI,0)="*******************************************************************"
  1. . S XMI=XMI+1,^XMB(3.9,XMZZ,2,XMI,0)=$$EZBLD^DIALOG(34235,XMLIMIT) ; P-MESSAGE line limit of |1| reached.
  1. . S XMI=XMI+1,^XMB(3.9,XMZZ,2,XMI,0)="*******************************************************************"
  1. . Q:$D(ZTQUEUED)!$G(XMQUIET)
  1. . U IO(0) W !,$$EZBLD^DIALOG(34235,XMLIMIT),! ; P-MESSAGE line limit of |1| reached.
  1. I '$D(ZTQUEUED),'$G(XMQUIET) U IO(0) W !,$$EZBLD^DIALOG(34236) ; Finished moving.
  1. S ^XMB(3.9,XMZZ,2,0)="^3.92A^"_XMI_"^"_XMI
  1. D SENDMSG(XMDUZ,XMZZ,.XMINSTR)
  1. D CLEANUP
  1. Q
  1. SENDMSG(XMDUZ,XMZ,XMINSTR) ; Here, send the message to recipient.
  1. I '$D(ZTQUEUED),'$G(XMQUIET) W !,$$EZBLD^DIALOG(34217,XMZ) ; Sending [_XMZ_]...
  1. D MOVEPART^XMXSEND(XMDUZ,XMZ,.XMINSTR)
  1. I $D(XMINSTR("FROM")),XMINSTR("FROM")="POSTMASTER"!(XMINSTR("FROM")?.N) S $P(^XMB(3.9,XMZ,0),U,4)=DUZ ; Retain 'sender'
  1. I $D(XMINSTR("FROM")),$D(XMINSTR("SELF BSKT")),XMINSTR("SELF BSKT")'=1 D
  1. . D FWD^XMKP(XMDUZ,XMZ,.XMINSTR)
  1. E D
  1. . D SEND^XMKP(XMDUZ,XMZ,.XMINSTR)
  1. I '$D(ZTQUEUED),'$G(XMQUIET) W !,$$EZBLD^DIALOG(34213) ; Sent
  1. D CHECK^XMKPL
  1. Q
  1. CLEANUP ;
  1. S IONOFF=1 ; Prevent form feed during device close
  1. D CLEANUP^XMXADDR
  1. D KSETS
  1. K XMERR,^TMP("XMERR",$J)
  1. I $D(XMAPHOST("XMZBACK")) S XMZ=XMZZ
  1. Q
  1. KSETS ;
  1. K:$G(XMAPHOST("SET XMDUZ")) XMDUZ
  1. K:$G(XMAPHOST("SET XMV")) XMV,XMDUN,XMNOSEND,XMDISPI,XMPRIV
  1. I $D(XMAPHOST("CHG XMDUZ")) S XMDUZ=XMAPHOST("CHG XMDUZ")
  1. Q