home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Spezial / SPEZIAL2_97.zip / SPEZIAL2_97.iso / ANWEND / ONLINE / SREFPRC1 / MULTSEND.SRF < prev    next >
Text File  |  1997-06-30  |  4KB  |  113 lines

  1. /* ----------------------------------------------------------------------- */
  2. /* multi-part send routine                                    
  3.  
  4.  thevalue: the stuff to send. Possibly text, possibly whatever -- 
  5.             OR; if isfile=1, a fully qualified file name.
  6.    thetype: the mime type to use. If not speicfied, text/html is used
  7.    status: S,M,E, MS,MM,ME
  8.            'S'   : Start-- This is the first send
  9.            'SS'  : Start, but do not close,
  10.            'SE'  : Start, do not open
  11.  
  12.            'M'  :  Middle -- An interior send
  13.            'MS' : Middle, but do NOT "close" this part
  14.            'ME'  : Middle, do NOT open part
  15.  
  16.            'E'     : End -- The last send
  17.            'ES'     : End -- do not CLOSE this part
  18.            'EE'     : End -- do not OPEN this part
  19.  
  20.            'A'  : Send, do not OPEN or CLOSE this part
  21.  
  22.           The S,M,E and send a complete message.
  23.           To build a message in pieces (retaining older parts of the message)
  24.          you can use a sequence of: xS,A,xE (where X is S,M, or E).
  25.           Note: MS and ES are the same (but ME and EE are NOT the same)
  26.  
  27.           The default value is A
  28.  
  29.    isfile: If 1, then thevalue is treated as a fully qualified file name,
  30.            and the contents are read using charin. If the file can not
  31.            be found, an empty string is used.
  32.            Default is NOT to interpret thevalue as a file name.
  33.  
  34. Returns RC code from the send -- check for negative values to indicate
  35. broken connection.  
  36.  
  37. example: foo=multsend('d:\i1.gif','image/gif','S',1)
  38.         foo=multsend('d:\i2.gif','image/gif','M',1)
  39.         foo=multsend('d:\i3.gif','image/gif','E',1)
  40.  
  41. example2:foo=multsend('Hello 1','text/plain','S')
  42.         foo=multsend('what's up1','text/plain','MS')
  43.         foo=multsend('what's up2','text/plain','A')
  44.         foo=multsend('what's up3','text/plain','ME')
  45.         foo=multsend('good bye','text/plain','E')
  46.  
  47. */
  48. /* ----------------------------------------------------------------------- */
  49. sref_multi_send:
  50. parse arg thevalue,thetype,status,isfile,verbose
  51.  
  52.   crlf='0d0a'x                /* useful */
  53.   bound='asfa235sdfF#234asg#%^6q32472341as'
  54.   bound2='asfA235sdfF#234asg#%^6q32472341p'
  55.  
  56. /* if isfile, then thevalue is a fully qualified file name. Read it */
  57.   if isfile=1 then do
  58.       afil=stream(thevalue,'c','query exists')
  59.       if afil="" then do
  60.             thevalue=""
  61.       end  /* Do */
  62.       else do
  63.          thevalue=charin(afil,1,chars(afil))
  64.       end
  65.   end  /* Do */
  66.  
  67. /* if by odd chance a bound string is found in thevalue, it will
  68.   be replaced by bound2 */
  69.   foo=pos(bound,thevalue)
  70.   if foo>0 then thevalue=sref_replacestrg(thevalue,bound,bound2,'ALL')
  71.  
  72.  
  73. /* mime tyhpes */
  74.   if thetype=0 | thetype="" then thetype="text/html"
  75.  
  76. if verbose>3 then call pmprintf_sref(' Multipart send: ' status ' = ' thetype)
  77.  
  78. /* status */
  79.  if status=0 | status="" then status="A"
  80.  status=strip(upper(status)); 
  81.  
  82.   mimestart='--'bound''crlf   /* starts a MIME multipart section */
  83.   mimeend  ='--'bound'--'crlf /* ends a MIME multipart section */
  84.  
  85.   /* Send the header and first boundary */
  86.  
  87.   if status='S' | status='SS' then do
  88.      'set netbuffer off'         /* turn off buffering */
  89.      'send type multipart/x-mixed-replace;boundary="'bound'" as MultiSend'
  90.      'string' mimestart          /* Or could be: 'var name mimestart' */
  91.   end
  92.   out=""
  93.   if wordpos(status,'ME SE EE A')=0 then do
  94.      out=out||'Content-type: '||thetype||crlf
  95.      out=out||crlf
  96.   end
  97.   out=out||thevalue||crlf
  98.   if status="E" | status="EE" then do
  99.       out=out||mimeend           /* Mime 'last data' indicator */
  100.   end
  101.   if wordpos(status,'M ME S SE')>0 then do
  102.        out=out||mimestart         /* Mime 'start data' indicator */
  103.  end
  104.   'VAR NAME out'                           /* send it */
  105.   res1=rc
  106.   if status="E" | status="EE" then   'SEND Complete'          /* and complete the send */
  107.  
  108.   return res1                                  
  109.  
  110.  
  111.  
  112.  
  113.