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

XMXSEND.m

Go to the documentation of this file.
  1. XMXSEND ;ISC-SF/GMB-Send a msg ;06/19/2002 07:01
  1. ;;8.0;MailMan;;Jun 28, 2002
  1. ; Entry points:
  1. ; SENDMSG Send a message
  1. ; CRE8XMZ Setup a message. (1st part of 3-part message sending process)
  1. ; In the second part, the programmer directly sets the message
  1. ; text into the global.
  1. ; ADDRNSND Send the message created by CRE8XMZ and 'texted' by the
  1. ; programmer. (3rd part of 3-part message sending process)
  1. ; Involves checking the addressees, loading the message,
  1. ; putting the addressees in the message,
  1. ; and sending the message.
  1. ; LATER TaskMan entry point to send a 'later'd message
  1. SENDMSG(XMDUZ,XMSUBJ,XMBODY,XMTO,XMINSTR,XMZ,XMATTACH) ;
  1. ; XMDUZ DUZ of who the msg is from
  1. ; XMSUBJ Subject of the msg
  1. ; XMBODY Body of the msg
  1. ; Must be closed root, passed by value. See WP_ROOT
  1. ; definition for WP^DIE(), FM word processing filer.
  1. ; XMTO Addressees
  1. ; XMINSTR("SELF BSKT") Basket to deliver to if sender is recipient
  1. ; XMINSTR("SHARE DATE") Delete date if recipient is "SHARED,MAIL"
  1. ; XMINSTR("SHARE BSKT") Basket if recipient is "SHARED,MAIL"
  1. ; XMINSTR("RCPT BSKT") Basket name (only) to deliver to for other recipients
  1. ; XMINSTR("VAPOR") Date on which to vaporize (delete) this message
  1. ; from recipient baskets
  1. ; XMINSTR("LATER") Date on which to send this msg, if not now
  1. ; XMINSTR("FROM") String saying from whom (default is user)
  1. ; XMINSTR("FLAGS") Any or all of the following:
  1. ; P Priority
  1. ; I Information only (may not be replied to)
  1. ; X Closed msg (may not be forwarded)
  1. ; C Confidential (surrogates may not read)
  1. ; S Send to sender (make sender a recipient)
  1. ; R Confirm receipt
  1. ; XMINSTR("SCR KEY") Scramble key (implies that msg should be scrambled)
  1. ; XMINSTR("SCR HINT") Hint (to guess the scramble key)
  1. ; XMINSTR("STRIP") String containing characters to strip from the message text
  1. ; XMINSTR("TYPE") Msg type is one of the following:
  1. ; D Document (NOT IMPLEMENTED)
  1. ; S Spooled Document (NOT IMPLEMENTED)
  1. ; X DIFROM (NOT IMPLEMENTED)
  1. ; O ODIF (NOT IMPLEMENTED)
  1. ; B BLOB
  1. ; K KIDS (NOT IMPLEMENTED)
  1. ; XMINSTR("ADDR FLAGS") Any or all of the following:
  1. ; I Do not Initialize (kill) the ^TMP addressee global
  1. ; R Do not Restrict addressees
  1. ; XMZ (out) msg number in ^XMB(3.9 (BUT IF $D(XMINSTR("LATER")),
  1. ; then XMZ contains the task number)
  1. ; XMATTACH (in) Array of files to attach to message
  1. ; ("IMAGE",x) imaging (BLOB) files
  1. ; ("ROU",x) routines (NOT IMPLEMENTED)
  1. K XMERR,^TMP("XMERR",$J)
  1. Q:'$$SEND^XMXSEC(XMDUZ,.XMINSTR)
  1. I $D(XMINSTR("LATER")) D Q
  1. . N XMTASK
  1. . D PSNDLATR(XMDUZ,XMSUBJ,XMBODY,.XMTO,.XMINSTR,.XMTASK,.XMATTACH)
  1. . I $D(XMTASK) S XMZ=XMTASK
  1. D CRE8XMZ(XMSUBJ,.XMZ) Q:$D(XMERR) ; Create a place for the msg in the msg file
  1. D:$D(XMATTACH("IMAGE"))>9 ADDBLOB(XMZ,.XMATTACH) Q:$D(XMERR)
  1. D MOVEBODY(XMZ,XMBODY) ; Put the msg body in place
  1. D CHEKBODY(XMZ,$G(XMINSTR("STRIP")))
  1. D ADDRNSND(XMDUZ,XMZ,.XMTO,.XMINSTR)
  1. Q
  1. ADDRNSND(XMDUZ,XMZ,XMTO,XMINSTR) ;
  1. D CHEKADDR(XMDUZ,XMZ,.XMTO,.XMINSTR)
  1. D BLDNSND(XMDUZ,XMZ,.XMINSTR)
  1. D CLEANUP^XMXADDR
  1. Q
  1. CHEKADDR(XMDUZ,XMZ,XMTO,XMINSTR) ;
  1. N XMRESTR
  1. D:$G(XMINSTR("ADDR FLAGS"))'["I" INIT^XMXADDR
  1. D:$G(XMINSTR("ADDR FLAGS"))'["R" CHKLINES^XMXSEC1(XMDUZ,XMZ,.XMRESTR)
  1. D:$G(XMINSTR("FLAGS"))["S" CHKADDR^XMXADDR(XMDUZ,XMDUZ)
  1. D CHKADDR^XMXADDR(XMDUZ,.XMTO,.XMINSTR,.XMRESTR) ; Address the msg
  1. Q
  1. BLDNSND(XMDUZ,XMZ,XMINSTR) ;
  1. D MOVEPART(XMDUZ,XMZ,.XMINSTR) ; Put various parts of the msg in place
  1. I '$$GOTADDR^XMXADDR D ERRSET^XMXUTIL(34100) Q ; No addressees. Message not sent.
  1. D SEND^XMKP(XMDUZ,XMZ,.XMINSTR) ; Send the msg
  1. D CHECK^XMKPL
  1. Q
  1. ADDBLOB(XMZ,XMATTACH) ;
  1. N X,XMYBLOB,%X,%Y
  1. S %X="XMATTACH(""IMAGE"",",%Y="XMYBLOB(" D %XY^%RCR
  1. S X=$$MULTI^XMBBLOB(XMZ)
  1. Q:'X
  1. S XMERR=$G(XMERR)+1,^TMP("XMERR",$J,XMERR,"TEXT",1)="Error with $$MULTI^XMBBLOB"
  1. D KILLMSG^XMXUTIL(XMZ)
  1. Q
  1. CRE8XMZ(XMSUBJ,XMZ,XMIA) ; Create a place for the msg in the msg file
  1. N XMFDA,XMIEN,XMMAXDIG,XMRESET
  1. I XMSUBJ[U S XMSUBJ=$$ENCODEUP^XMXUTIL1(XMSUBJ)
  1. S XMMAXDIG=$P($G(^XMB(1,1,.17),8),U,1) I 'XMMAXDIG S XMMAXDIG=8
  1. S XMRESET=0
  1. TRYXMZ ;
  1. S XMFDA(3.9,"+1,",.01)=XMSUBJ
  1. S XMFDA(3.9,"+1,",31)=DT ; local create date
  1. D UPDATE^DIE("","XMFDA","XMIEN")
  1. I $D(DIERR) D Q
  1. . S XMZ=-1
  1. . ; Call to UPDATE^DIE failed. Can't get a message number.
  1. . ; Here's the error returned by FileMan:
  1. . D ERRSET^XMXUTIL(34107)
  1. . N I,J,K
  1. . S J=0
  1. . S I=$O(^TMP("XMERR",$J,XMERR,"TEXT",":"),-1)
  1. . F K=1:1:+DIERR D
  1. . . F S J=$O(^TMP("DIERR",$J,K,"TEXT",J)) Q:'J D
  1. . . . S I=I+1,^TMP("XMERR",$J,XMERR,"TEXT",I)=^TMP("DIERR",$J,K,"TEXT",J)
  1. . Q:'$G(XMIA)!$D(ZTQUEUED)
  1. . D SHOW^XMJERR
  1. . D WAIT^XMXUTIL
  1. S XMZ=XMIEN(1)
  1. Q:$L(XMZ)'>XMMAXDIG
  1. I XMRESET S $P(^XMB(1,1,.17),U,1)=$L(XMZ) Q
  1. ; Recycle message numbers, because this one's too big...
  1. K XMIEN
  1. S XMRESET=1
  1. I '$D(^XMB(3.9,99999,0)) D
  1. . ; We do this so that if message 100000 is created and then deleted,
  1. . ; FM will set piece 3 of ^XMB(3.9,0) to 99999. We don't want any
  1. . ; message number lower than 100000 to be created, so that message
  1. . ; numbers can't be confused with message sequence numbers in baskets
  1. . S ^XMB(3.9,99999,0)="place holder"
  1. . S ^XMB(3.9,"B","place holder",99999)=""
  1. L +^XMB(3.9,0):1
  1. I $L($P(^XMB(3.9,0),U,3))>XMMAXDIG S $P(^XMB(3.9,0),U,3)=99999
  1. N DIK,DA S DIK="^XMB(3.9,",DA=XMZ D ^DIK ; Delete the message stub.
  1. L -^XMB(3.9,0)
  1. G TRYXMZ ; Go get another
  1. MOVEBODY(XMZ,XMBODY,XMFLAG) ;
  1. D WP^DIE(3.9,XMZ_",",3,$G(XMFLAG),XMBODY)
  1. Q
  1. CHEKBODY(XMZ,XMSTRIP,XMI) ; Remove XMSTRIP, control characters from text
  1. N XMLINE,I,XMLEN,XMALTRD
  1. S XMI=+$G(XMI)
  1. F S XMI=$O(^XMB(3.9,XMZ,2,XMI)) Q:'XMI S XMLINE=^(XMI,0) D
  1. . S XMALTRD=0
  1. . I $G(XMSTRIP)'="" S XMLEN=$L(XMLINE),XMLINE=$TR(XMLINE,XMSTRIP) I XMLEN>$L(XMLINE) S XMALTRD=1
  1. . I XMLINE?.E1C.E D
  1. . . S (I,XMALTRD)=1
  1. . . F D Q:XMLINE'?.E1C.E
  1. . . . I $E(XMLINE,I)?1C S XMLINE=$E(XMLINE,1,I-1)_$E(XMLINE,I+1,999) Q
  1. . . . S I=I+1
  1. . S:XMALTRD ^XMB(3.9,XMZ,2,XMI,0)=XMLINE
  1. Q
  1. MOVEPART(XMDUZ,XMZ,XMINSTR) ; Put various parts of the msg in place
  1. N XMFDA,XMIENS
  1. S XMIENS=XMZ_","
  1. I $D(XMINSTR("FROM")) S XMFDA(3.9,XMIENS,1)=XMINSTR("FROM")
  1. E D
  1. . S XMFDA(3.9,XMIENS,1)=XMDUZ
  1. . S:XMDUZ'=DUZ XMFDA(3.9,XMIENS,1.1)=DUZ
  1. S XMFDA(3.9,XMIENS,1.4)=$$NOW^XLFDT()
  1. I $D(XMINSTR) D
  1. . S:$G(XMINSTR("FLAGS"))["R" XMFDA(3.9,XMIENS,1.3)="y"
  1. . S:$D(XMINSTR("VAPOR")) XMFDA(3.9,XMIENS,1.6)=XMINSTR("VAPOR")
  1. . S:$D(XMINSTR("TYPE")) XMFDA(3.9,XMIENS,1.7)=XMINSTR("TYPE")
  1. . I $D(XMINSTR("SCR KEY")) D
  1. . . N XMKEY,XMSECURE ; XMSECURE is new'd for scramble
  1. . . S XMFDA(3.9,XMIENS,1.8)=$S($G(XMINSTR("SCR HINT"))="":" ",1:XMINSTR("SCR HINT"))
  1. . . D LOADCODE^XMJMCODE
  1. . . S XMKEY=XMINSTR("SCR KEY")
  1. . . D ADJUST^XMJMCODE(.XMKEY)
  1. . . S XMFDA(3.9,XMIENS,1.85)="1"_$$ENCSTR^XMJMCODE(XMKEY)
  1. . . D ENCMSG^XMJMCODE(XMZ)
  1. . S:$G(XMINSTR("FLAGS"))["X" XMFDA(3.9,XMIENS,1.95)="y"
  1. . S:$G(XMINSTR("FLAGS"))["C" XMFDA(3.9,XMIENS,1.96)="y"
  1. . S:$G(XMINSTR("FLAGS"))["I" XMFDA(3.9,XMIENS,1.97)="y"
  1. . S:$G(XMINSTR("FLAGS"))["P" XMFDA(3.9,XMIENS,1.7)=$G(XMFDA(3.9,XMIENS,1.7))_"P"
  1. . S:$D(XMINSTR("RCPT BSKT")) XMFDA(3.9,XMIENS,21)=XMINSTR("RCPT BSKT")
  1. S:$$BRODCAST^XMKP XMFDA(3.9,XMIENS,1.97)="y"
  1. D FILE^DIE("","XMFDA")
  1. Q
  1. LATER ; TaskMan entry point to send a user's latered message
  1. N XMI,XMLATER,XMPREFIX,XMTO,XMV,XMPRIVAT,XMBCAST
  1. S XMPRIVAT=$$EZBLD^DIALOG(39135) ; " [Private Mail Group]"
  1. S XMBCAST=$$EZBLD^DIALOG(39006) ; "* (Broadcast to all local users)"
  1. D INIT^XMVVITAE
  1. S XMI=""
  1. F S XMI=$O(^TMP("XMY0",$J,XMI)) Q:XMI="" D
  1. . S XMPREFIX=$G(^TMP("XMY0",$J,XMI,1)) ; prefix (I:,C:)
  1. . S XMLATER=$G(^TMP("XMY0",$J,XMI,"L"))
  1. . S:XMLATER'="" XMPREFIX=XMPREFIX_"L@"_XMLATER
  1. . S:XMPREFIX'="" XMPREFIX=XMPREFIX_":"
  1. . S XMTO(XMPREFIX_$S(XMI[XMPRIVAT:$P(XMI,XMPRIVAT,1),XMI=XMBCAST:"*",1:XMI))="" ; (set in ^XMXADDRG)
  1. D SENDMSG(XMDUZ,XMSUBJ,"^TMP(""XM"",$J,""BODY"")",.XMTO,.XMINSTR)
  1. S ZTREQ="@"
  1. Q
  1. PSNDLATR(XMDUZ,XMSUBJ,XMBODY,XMTO,XMINSTR,ZTSK,XMATTACH) ; Set up a task for a program to send a message later
  1. N ZTRTN,ZTDTH,ZTDESC,ZTIO,ZTSAVE
  1. S ZTIO=""
  1. S ZTRTN="PTSKLATR^XMXSEND"
  1. S ZTDTH=$$FMTH^XLFDT(XMINSTR("LATER"))
  1. S ZTDESC=$$EZBLD^DIALOG(39310) ; MailMan: Send Message Later
  1. S ZTSAVE($$OREF^DILF(XMBODY))=""
  1. F I="DUZ","XMDUZ","XMSUBJ","XMBODY","XMTO","XMTO(","XMINSTR(","XMATTACH(" S ZTSAVE(I)=""
  1. D ^%ZTLOAD
  1. ;D HOME^%ZIS call this only if preceded by call to ^%ZIS
  1. I '$D(ZTSK) D ERRSET^XMXUTIL(39311) ; Task creation not successful
  1. Q
  1. PTSKLATR ; TaskMan entry point to send a program's latered message
  1. K XMINSTR("LATER")
  1. D SENDMSG(XMDUZ,XMSUBJ,XMBODY,.XMTO,.XMINSTR,"",.XMATTACH)
  1. S ZTREQ="@"
  1. Q
  1. STARTMSG(XMSUBJ,XMZ) ;
  1. K XMERR,^TMP("XMERR",$J)
  1. D CRE8XMZ(XMSUBJ,.XMZ) Q:$D(XMERR)
  1. S XMLCNT=0
  1. Q
  1. BODYLINE(XMZ,XMLINE) ; Put the msg body in place, line by line
  1. S XMLCNT=XMLCNT+1
  1. S ^XMB(3.9,XMZ,2,XMLCNT,0)=XMLINE
  1. Q
  1. ENDMSG(XMDUZ,XMZ,XMTO,XMINSTR) ;
  1. S ^XMB(3.9,XMZ,2,0)="^^"_XMLCNT_U_XMLCNT_U_DT
  1. K XMLCNT
  1. D ADDRNSND(XMDUZ,XMZ,.XMTO,.XMINSTR)
  1. Q
  1. POSTMAST(XMDUZ,XMINSTR) ;
  1. S:'$D(XMDUZ) XMDUZ=DUZ
  1. D:'$G(XMV("PRIV")) INIT^XMVVITAE
  1. S XMINSTR("FROM")=.5
  1. Q